replaced raw pointers by smart pointers for any2many.cpp.

This commit is contained in:
suter_a 2023-10-13 12:23:32 +02:00
parent 31761e1eca
commit bad6812b2b

View File

@ -37,6 +37,7 @@
#include <iostream>
#include <fstream>
#include <memory>
#include <TString.h>
#include <TSAXParser.h>
@ -493,49 +494,31 @@ int main(int argc, char *argv[])
// read startup file
char startup_path_name[128];
TSAXParser *saxParser = new TSAXParser();
PStartupHandler *startupHandler = new PStartupHandler();
std::unique_ptr<TSAXParser> saxParser = std::unique_ptr<TSAXParser>(new TSAXParser());
std::unique_ptr<PStartupHandler> startupHandler = std::unique_ptr<PStartupHandler>(new PStartupHandler());
if (!startupHandler->StartupFileFound()) {
std::cerr << std::endl << ">> any2many **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
std::cerr << std::endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = nullptr;
}
if (startupHandler) {
delete startupHandler;
startupHandler = nullptr;
}
} else {
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
saxParser->ConnectToHandler("PStartupHandler", startupHandler.get());
//status = saxParser->ParseFile(startup_path_name);
// parsing the file as above seems to lead to problems in certain environments;
// 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
if (status) { // error
std::cerr << std::endl << ">> any2many **WARNING** Reading/parsing musrfit_startup.xml failed.";
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)
PRunDataHandler *dataHandler;
std::unique_ptr<PRunDataHandler> dataHandler;
if (startupHandler)
dataHandler = new PRunDataHandler(&info, startupHandler->GetDataPathList());
dataHandler = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(&info, startupHandler->GetDataPathList()));
else
dataHandler = new PRunDataHandler(&info);
dataHandler = std::unique_ptr<PRunDataHandler>(new PRunDataHandler(&info));
// read and convert all data
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;
}
// 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;
}