Raw -> Smart Pointers in PNeXus.

This commit is contained in:
2023-10-25 17:52:24 +02:00
parent 1cb0cfd3e7
commit 8f4a7c6b68
2 changed files with 15 additions and 32 deletions

View File

@@ -1951,15 +1951,6 @@ PNeXus::PNeXus(const char* fileName)
*/
PNeXus::~PNeXus()
{
if (fNxEntry1) {
delete fNxEntry1;
fNxEntry1 = 0;
}
if (fNxEntry2) {
delete fNxEntry2;
fNxEntry2 = 0;
}
for (unsigned int i=0; i<fGroupedHisto.size(); i++) {
fGroupedHisto[i].clear();
}
@@ -1984,24 +1975,18 @@ void PNeXus::SetIdfVersion(unsigned int idf)
fIdfVersion = idf;
if (idf == 1) { // IDF 1
if (fNxEntry2) {
delete fNxEntry2;
fNxEntry2 = 0;
}
fNxEntry2.reset();
fNxEntry1 = new PNeXusEntry1();
if (fNxEntry1 == 0) {
fNxEntry1 = std::make_unique<PNeXusEntry1>();
if (fNxEntry1 == nullptr) {
std::cerr << std::endl << ">> **ERROR** couldn't invoke IDF 1 object PNeXusEntry1." << std::endl;
return;
}
} else { // IDF 2
if (fNxEntry1) {
delete fNxEntry1;
fNxEntry1 = 0;
}
fNxEntry1.reset();
fNxEntry2 = new PNeXusEntry2();
if (fNxEntry2 == 0) {
fNxEntry2 = std::make_unique<PNeXusEntry2>();
if (fNxEntry2 == nullptr) {
std::cerr << std::endl << ">> **ERROR** couldn't invoke IDF 2 object PNeXusEntry1." << std::endl;
return;
}
@@ -2510,9 +2495,6 @@ void PNeXus::Init()
fFileName = "n/a";
fFileTime = "n/a";
fCreator = "n/a";
fNxEntry1 = 0;
fNxEntry2 = 0;
}
//-----------------------------------------------------------------------------------------------------
@@ -2804,8 +2786,8 @@ int PNeXus::ReadFileIdf1()
std::cout << std::endl << ">> reading NeXus IDF Version 1 file ..." << std::endl;
// create first the necessary NXentry object for IDF Version 1
fNxEntry1 = new PNeXusEntry1();
if (fNxEntry1 == 0) {
fNxEntry1 = std::make_unique<PNeXusEntry1>();
if (fNxEntry1 == nullptr) {
fErrorCode = PNEXUS_OBJECT_INVOK_ERROR;
fErrorMsg = ">> **ERROR** couldn't invoke PNeXusEntry1 object.";
return NX_ERROR;
@@ -3384,8 +3366,8 @@ int PNeXus::ReadFileIdf2()
std::cout << std::endl << ">> reading NeXus IDF Version 2 file ..." << std::endl;
// create first the necessary NXentry object for IDF Version 2
fNxEntry2 = new PNeXusEntry2();
if (fNxEntry2 == 0) {
fNxEntry2 = std::make_unique<PNeXusEntry2>();
if (fNxEntry2 == nullptr) {
fErrorCode = PNEXUS_OBJECT_INVOK_ERROR;
fErrorMsg = ">> **ERROR** couldn't invoke PNeXusEntry2 object.";
return NX_ERROR;