replaced raw pointers by smart pointers for any2many.cpp.
This commit is contained in:
parent
31761e1eca
commit
bad6812b2b
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <TString.h>
|
#include <TString.h>
|
||||||
#include <TSAXParser.h>
|
#include <TSAXParser.h>
|
||||||
@ -493,49 +494,31 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// read startup file
|
// read startup file
|
||||||
char startup_path_name[128];
|
char startup_path_name[128];
|
||||||
TSAXParser *saxParser = new TSAXParser();
|
std::unique_ptr<TSAXParser> saxParser = std::unique_ptr<TSAXParser>(new TSAXParser());
|
||||||
PStartupHandler *startupHandler = new PStartupHandler();
|
std::unique_ptr<PStartupHandler> startupHandler = std::unique_ptr<PStartupHandler>(new PStartupHandler());
|
||||||
if (!startupHandler->StartupFileFound()) {
|
if (!startupHandler->StartupFileFound()) {
|
||||||
std::cerr << std::endl << ">> any2many **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
|
std::cerr << std::endl << ">> any2many **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
// clean up
|
|
||||||
if (saxParser) {
|
|
||||||
delete saxParser;
|
|
||||||
saxParser = nullptr;
|
|
||||||
}
|
|
||||||
if (startupHandler) {
|
|
||||||
delete startupHandler;
|
|
||||||
startupHandler = nullptr;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
|
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
|
||||||
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
|
saxParser->ConnectToHandler("PStartupHandler", startupHandler.get());
|
||||||
//status = saxParser->ParseFile(startup_path_name);
|
//status = saxParser->ParseFile(startup_path_name);
|
||||||
// parsing the file as above seems to lead to problems in certain environments;
|
// parsing the file as above seems to lead to problems in certain environments;
|
||||||
// use the parseXmlFile function instead (see PStartupHandler.cpp for the definition)
|
// use the parseXmlFile function instead (see PStartupHandler.cpp for the definition)
|
||||||
status = parseXmlFile(saxParser, startup_path_name);
|
status = parseXmlFile(saxParser.get(), startup_path_name);
|
||||||
// check for parse errors
|
// check for parse errors
|
||||||
if (status) { // error
|
if (status) { // error
|
||||||
std::cerr << std::endl << ">> any2many **WARNING** Reading/parsing musrfit_startup.xml failed.";
|
std::cerr << std::endl << ">> any2many **WARNING** Reading/parsing musrfit_startup.xml failed.";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
// clean up
|
|
||||||
if (saxParser) {
|
|
||||||
delete saxParser;
|
|
||||||
saxParser = nullptr;
|
|
||||||
}
|
|
||||||
if (startupHandler) {
|
|
||||||
delete startupHandler;
|
|
||||||
startupHandler = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// read all the necessary runs (raw data)
|
// read all the necessary runs (raw data)
|
||||||
PRunDataHandler *dataHandler;
|
std::unique_ptr<PRunDataHandler> dataHandler;
|
||||||
if (startupHandler)
|
if (startupHandler)
|
||||||
dataHandler = new PRunDataHandler(&info, startupHandler->GetDataPathList());
|
dataHandler = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(&info, startupHandler->GetDataPathList()));
|
||||||
else
|
else
|
||||||
dataHandler = new PRunDataHandler(&info);
|
dataHandler = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(&info));
|
||||||
|
|
||||||
// read and convert all data
|
// read and convert all data
|
||||||
dataHandler->ConvertData();
|
dataHandler->ConvertData();
|
||||||
@ -546,21 +529,6 @@ int main(int argc, char *argv[])
|
|||||||
std::cerr << std::endl << ">> any2many **ERROR** Couldn't read all data files, will quit ..." << std::endl;
|
std::cerr << std::endl << ">> any2many **ERROR** Couldn't read all data files, will quit ..." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up
|
|
||||||
info.runList.clear();
|
|
||||||
if (saxParser) {
|
|
||||||
delete saxParser;
|
|
||||||
saxParser = nullptr;
|
|
||||||
}
|
|
||||||
if (startupHandler) {
|
|
||||||
delete startupHandler;
|
|
||||||
startupHandler = nullptr;
|
|
||||||
}
|
|
||||||
if (dataHandler) {
|
|
||||||
delete dataHandler;
|
|
||||||
dataHandler = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PMUSR_SUCCESS;
|
return PMUSR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user