* Define a function for the XML-reading workaround in order to clean up a bit.
For the moment we keep to copies of it -- one for the use within the various musrfit programs, one that can be used in user functions. * musrt0 is now again activated in musrgui/musredit by default.
This commit is contained in:
@ -30,6 +30,7 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
|
||||
#include "PUserFcnBase.h"
|
||||
@ -56,5 +57,47 @@ PUserFcnBase::~PUserFcnBase()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// This function is a replacement for the ParseFile method of TSAXParser.
|
||||
// It is needed because in certain environments ParseFile does not work but ParseBuffer does.
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p> Replacement for the ParseFile method of TSAXParser
|
||||
* that can be used in user functions.
|
||||
*
|
||||
* <p><b>return:</b>
|
||||
* - 1 if file cannot be read
|
||||
* - 0 if the file has been parsed successfully
|
||||
* - parse error code otherwise
|
||||
*
|
||||
* \param saxParser pointer to a TSAXParser object
|
||||
* \param startup_path_name full path to the XML file to be read
|
||||
*/
|
||||
Int_t parseXmlFile(TSAXParser *saxParser, const char *startup_path_name)
|
||||
{
|
||||
Int_t status;
|
||||
fstream xmlFile;
|
||||
UInt_t xmlSize = 0;
|
||||
Char_t *xmlBuffer = 0;
|
||||
|
||||
xmlFile.open(startup_path_name, ios::in | ios::ate); // open file for reading and go to the end of the file
|
||||
if (xmlFile.is_open()) { // check if file has been opened successfully
|
||||
xmlSize = xmlFile.tellg(); // get the position within the stream == size of the file (since we are at the end)
|
||||
xmlFile.seekg(0, ios::beg); // go back to the beginning of the stream
|
||||
xmlBuffer = new Char_t[xmlSize]; // allocate buffer memory for the whole XML file
|
||||
xmlFile.read(xmlBuffer, xmlSize); // read in the whole XML file into the buffer
|
||||
xmlFile.close(); // close the XML file
|
||||
}
|
||||
if (!xmlBuffer) { // file has not been read into the buffer
|
||||
status = 1;
|
||||
} else {
|
||||
status = saxParser->ParseBuffer(xmlBuffer, xmlSize); // parse buffer
|
||||
delete[] xmlBuffer; // free the buffer memory
|
||||
xmlBuffer = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// place a void pointer vector for global user function objects which might be needed
|
||||
vector<void *> gGlobalUserFcn;
|
||||
|
Reference in New Issue
Block a user