Raw -> Smart Pointers in PNeXus.

This commit is contained in:
suter_a 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;

View File

@ -32,6 +32,7 @@
#include <string>
#include <vector>
#include <memory>
#include "napi.h"
@ -574,8 +575,8 @@ class PNeXus {
virtual void SetFileName(std::string name) { fFileName = name; }
virtual void SetFileTime(std::string time) { fFileTime = time; }
virtual PNeXusEntry1* GetEntryIdf1() { return fNxEntry1; }
virtual PNeXusEntry2* GetEntryIdf2() { return fNxEntry2; }
virtual PNeXusEntry1* GetEntryIdf1() { return fNxEntry1.get(); }
virtual PNeXusEntry2* GetEntryIdf2() { return fNxEntry2.get(); }
virtual bool IsValid(bool strict=false);
virtual int GetErrorCode() { return fErrorCode; }
@ -605,8 +606,8 @@ class PNeXus {
std::string fCreator; ///< facility of program where the file originated
PNeXusEntry1 *fNxEntry1; ///< NXentry for IDF 1
PNeXusEntry2 *fNxEntry2; ///< NXentry for IDF 2
std::unique_ptr<PNeXusEntry1> fNxEntry1; ///< NXentry for IDF 1
std::unique_ptr<PNeXusEntry2> fNxEntry2; ///< NXentry for IDF 2
std::vector< std::vector<unsigned int> > fGroupedHisto;