Skip to content

Commit

Permalink
Merge pull request #2044 from e-kwsm/nullptr
Browse files Browse the repository at this point in the history
Replace NULL with nullptr (C++11)
  • Loading branch information
ghutchis committed May 8, 2020
2 parents 742f393 + 38af315 commit 66042e0
Show file tree
Hide file tree
Showing 285 changed files with 2,071 additions and 2,088 deletions.
12 changes: 2 additions & 10 deletions CMakeLists.txt
Expand Up @@ -6,6 +6,8 @@ endif()
project(openbabel)
set(CMAKE_MODULE_PATH ${openbabel_SOURCE_DIR}/cmake/modules)

set (CMAKE_CXX_STANDARD 11)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
if(POLICY CMP0042)
Expand All @@ -15,16 +17,6 @@ endif()

include (CheckCXXCompilerFlag)

CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Multi-threaded applications may experience race conditions.")
endif()

#include (MacroEnsureVersion)

# Version numbering - should be bumped for each release
Expand Down
10 changes: 5 additions & 5 deletions include/openbabel/atom.h
Expand Up @@ -165,7 +165,7 @@ namespace OpenBabel
//! Mark an atom as belonging to at least one ring
void SetInRing(bool value=true) { SET_OR_UNSET_FLAG(OB_RING_ATOM); }
//! Clear the internal coordinate pointer
void ClearCoordPtr() { _c = NULL; _cidx=0; }
void ClearCoordPtr() { _c = nullptr; _cidx=0; }
//@}

//! \name Methods to retrieve atomic information
Expand Down Expand Up @@ -241,7 +241,7 @@ namespace OpenBabel
//! (e.g., only vector3), NULL will be returned.
double *GetCoordinate(){
if (_c) return(&(*_c)[_cidx]);
else return NULL;
else return nullptr;
}
//! \return the coordinates as a vector3 object
vector3 &GetVector();
Expand Down Expand Up @@ -310,7 +310,7 @@ namespace OpenBabel
void DeleteResidue(){
if (_residue) {
delete _residue;
_residue = NULL; // Make sure to clear that a residue existed
_residue = nullptr; // Make sure to clear that a residue existed
}
}
//! Add a bond to the internal list. Does not update the bond.
Expand Down Expand Up @@ -363,11 +363,11 @@ namespace OpenBabel
*/
std::pair<int, int> LewisAcidBaseCounts() const;
//! \return Is there any residue information?
bool HasResidue() { return(_residue != NULL); }
bool HasResidue() { return(_residue != nullptr); }
//! \return Is this a HETATM in a residue (returns false if not in a residue)
//! \since version 2.4
bool IsHetAtom() {
if (_residue == NULL)
if (_residue == nullptr)
return false;
else
return _residue->IsHetAtom(this);
Expand Down
2 changes: 1 addition & 1 deletion include/openbabel/base.h
Expand Up @@ -207,7 +207,7 @@ class OBConversion; //used only as pointer
A derived class may return NULL if copying is inappropriate */
virtual OBGenericData* Clone(OBBase* /*parent*/) const
{ return NULL; }
{ return nullptr; }
virtual ~OBGenericData() {}
//Use default copy constructor and assignment operators
//OBGenericData& operator=(const OBGenericData &src);
Expand Down
2 changes: 1 addition & 1 deletion include/openbabel/data.h
Expand Up @@ -57,7 +57,7 @@ namespace OpenBabel

public:
//! Constructor
OBGlobalDataBase(): _init(false), _dataptr(NULL) { }
OBGlobalDataBase(): _init(false), _dataptr(nullptr) { }
//! Destructor
virtual ~OBGlobalDataBase() {}
//! Read in the data file, falling back as needed
Expand Down
10 changes: 5 additions & 5 deletions include/openbabel/descriptor.h
Expand Up @@ -39,22 +39,22 @@ class OBAPI OBDescriptor : public OBPlugin
const char* TypeID(){return "descriptors";};

/// \return the value of a numeric descriptor
virtual double Predict(OBBase* /* pOb */, std::string* /* param */ =NULL)
virtual double Predict(OBBase* /* pOb */, std::string* /* param */ =nullptr)
{return std::numeric_limits<double>::quiet_NaN();}

/// \return the value of the descriptor and adds it to the object's OBPairData
double PredictAndSave(OBBase* pOb, std::string* param=NULL);
double PredictAndSave(OBBase* pOb, std::string* param=nullptr);

///Provides a string value for non-numeric descriptors and returns NaN, or a string representation and returns a numeric value
virtual double GetStringValue(OBBase* pOb, std::string& svalue, std::string* param=NULL);
virtual double GetStringValue(OBBase* pOb, std::string& svalue, std::string* param=nullptr);

///Parses the filter stream for a relational expression and returns its result when applied to the chemical object
virtual bool Compare(OBBase* pOb, std::istream& ss, bool noEval, std::string* param=NULL);
virtual bool Compare(OBBase* pOb, std::istream& ss, bool noEval, std::string* param=nullptr);

///Write information on a plugin class to the string txt.
///If the parameter is a descriptor ID, displays the verbose description for that descriptor only
/// e.g. babel -L descriptors HBA1
virtual bool Display(std::string& txt, const char* param, const char* ID=NULL);
virtual bool Display(std::string& txt, const char* param, const char* ID=nullptr);

/// Comparison of the values of the descriptor. Used in sorting.
/// Descriptors may use more complicated ordering than this default (e.g.InChIFilter)
Expand Down
10 changes: 5 additions & 5 deletions include/openbabel/forcefield.h
Expand Up @@ -246,7 +246,7 @@ const double GAS_CONSTANT = 8.31446261815324e-3 / KCAL_TO_KJ; //!< kcal mol^-1
//! Constructor
OBFFConstraint()
{
a = b = c = d = NULL;
a = b = c = d = nullptr;
ia = ib = ic = id = 0;
constraint_value = 0.0;
factor = 0.0;
Expand Down Expand Up @@ -573,13 +573,13 @@ const double GAS_CONSTANT = 8.31446261815324e-3 / KCAL_TO_KJ; //!< kcal mol^-1
//! Destructor
virtual ~OBForceField()
{
if (_grad1 != NULL) {
if (_grad1 != nullptr) {
delete [] _grad1;
_grad1 = NULL;
_grad1 = nullptr;
}
if (_gradientPtr != NULL) {
if (_gradientPtr != nullptr) {
delete [] _gradientPtr;
_gradientPtr = NULL;
_gradientPtr = nullptr;
}
}

Expand Down
6 changes: 3 additions & 3 deletions include/openbabel/format.h
Expand Up @@ -133,18 +133,18 @@ std::cerr << "Not a valid input format"; return false;}
/// in the program.
virtual OBFormat* MakeNewInstance()
{
return NULL; //shows not implemented in the format class
return nullptr; //shows not implemented in the format class
}

//New functions since OBFormat is derived from OBPlugin
//\brief Called from, and an alternative to, OBConversion::RegisterFormat();
int RegisterFormat(const char* ID, const char* MIME = NULL);
int RegisterFormat(const char* ID, const char* MIME = nullptr);

///\brief Provides a description in txt of the format specified by itr.
///If param starts with "in", "read", "out" or "write" only the
///appropriate formats are output. The others return false.
///If param contains "verbose", the whole description is output.
virtual bool Display(std::string& txt, const char* param, const char* ID=NULL);
virtual bool Display(std::string& txt, const char* param, const char* ID=nullptr);

static OBFormat* FormatFromMIME(const char* MIME);

Expand Down
18 changes: 9 additions & 9 deletions include/openbabel/generic.h
Expand Up @@ -72,7 +72,7 @@ namespace OpenBabel
OBAtom *_atom;
OBBond *_bond;
public:
OBExternalBond(): _idx(0), _atom(NULL), _bond(NULL) {}
OBExternalBond(): _idx(0), _atom(nullptr), _bond(nullptr) {}
OBExternalBond(OBAtom *,OBBond *,int);
OBExternalBond(const OBExternalBond &);
~OBExternalBond() {}
Expand All @@ -95,7 +95,7 @@ namespace OpenBabel
OBExternalBondData();

//Copying is not used and too much work to set up
virtual OBGenericData* Clone(OBBase* /*parent*/) const{return NULL;}
virtual OBGenericData* Clone(OBBase* /*parent*/) const{return nullptr;}

void SetData(OBAtom*,OBBond*,int);
std::vector<OBExternalBond> *GetData()
Expand Down Expand Up @@ -182,7 +182,7 @@ namespace OpenBabel
if ((*i)->GetAttribute() == s)
return(*i);

return(NULL);
return(nullptr);
}

//! \return the OBGenericData associate with the attribute name parameter.
Expand All @@ -194,7 +194,7 @@ namespace OpenBabel
if ((*i)->GetAttribute() == s)
return(*i);

return(NULL);
return(nullptr);
}

//! Gets the entire set.
Expand Down Expand Up @@ -264,7 +264,7 @@ namespace OpenBabel
// exist due to Kekulize() in EndModify() in operator= in OBMol. Having
// more than one RingData causes problems as one of them can become invalid
// and cause segfaults.
virtual OBGenericData* Clone(OBBase* /*parent*/) const{return NULL;}
virtual OBGenericData* Clone(OBBase* /*parent*/) const{return nullptr;}
~OBRingData();

OBRingData &operator=(const OBRingData &);
Expand Down Expand Up @@ -607,7 +607,7 @@ namespace OpenBabel
//! double is angle in radians
std::vector<triple<OBAtom*,OBAtom*,double> > _ads;

OBTorsion(): _bc((OBAtom *)NULL, (OBAtom *)NULL) { }
OBTorsion(): _bc((OBAtom *)nullptr, (OBAtom *)nullptr) { }
//protected for use only by friend classes
OBTorsion(OBAtom *, OBAtom *, OBAtom *, OBAtom *);

Expand Down Expand Up @@ -720,7 +720,7 @@ namespace OpenBabel
OBAngle(const OBAngle &);
~OBAngle()
{
_vertex = NULL;
_vertex = nullptr;
}

OBAngle &operator = (const OBAngle &);
Expand Down Expand Up @@ -1140,13 +1140,13 @@ namespace OpenBabel
OBFreeGridPoint *BeginPoint(OBFreeGridPointIterator &i)
{
i = _points.begin();
return((i == _points.end()) ? (OBFreeGridPoint*)NULL : (OBFreeGridPoint*)*i);
return((i == _points.end()) ? (OBFreeGridPoint*)nullptr : (OBFreeGridPoint*)*i);
}

OBFreeGridPoint *NextPoint(OBFreeGridPointIterator &i)
{
++i;
return((i == _points.end()) ? (OBFreeGridPoint*)NULL : (OBFreeGridPoint*)*i);
return((i == _points.end()) ? (OBFreeGridPoint*)nullptr : (OBFreeGridPoint*)*i);
}

void Clear();
Expand Down
2 changes: 1 addition & 1 deletion include/openbabel/graphsym.h
Expand Up @@ -47,7 +47,7 @@ namespace OpenBabel {

public:
//! Constructor
OBGraphSym(OBMol* pmol, const OBBitVec* frag_atoms = NULL);
OBGraphSym(OBMol* pmol, const OBBitVec* frag_atoms = nullptr);
//! Destructor
virtual ~OBGraphSym();

Expand Down
2 changes: 1 addition & 1 deletion include/openbabel/grid.h
Expand Up @@ -112,7 +112,7 @@ namespace OpenBabel

public:

OBFloatGrid() : _ival(NULL), _halfSpace(0.0) {}
OBFloatGrid() : _ival(nullptr), _halfSpace(0.0) {}
~OBFloatGrid()
{
if (_ival) delete [] _ival;
Expand Down
2 changes: 1 addition & 1 deletion include/openbabel/groupcontrib.h
Expand Up @@ -62,7 +62,7 @@ class OBDESC OBGroupContrib : public OBDescriptor
}


virtual double Predict(OBBase* pOb, std::string* param=NULL);
virtual double Predict(OBBase* pOb, std::string* param=nullptr);

private:
bool ParseFile();
Expand Down
2 changes: 1 addition & 1 deletion include/openbabel/internalcoord.h
Expand Up @@ -70,7 +70,7 @@ namespace OpenBabel
double _tor; //!< Torsional/dihedral angle between this, _a, _b, and _c

//! Constructor
OBInternalCoord(OBAtom *a= NULL, OBAtom *b= NULL, OBAtom *c= NULL,
OBInternalCoord(OBAtom *a= nullptr, OBAtom *b= nullptr, OBAtom *c= nullptr,
double dst = 0.0, double ang = 0.0, double tor = 0.0) :
_a(a), _b(b), _c(c), _dst(dst), _ang(ang), _tor(tor)
{}
Expand Down
6 changes: 3 additions & 3 deletions include/openbabel/lineend.h
Expand Up @@ -60,7 +60,7 @@ namespace OpenBabel
{
public:
FilteringInputStreambuf(
std::istream* source = NULL) ;
std::istream* source = nullptr) ;
virtual ~FilteringInputStreambuf()
{
//sync(); comment out so can be deleted in OBConversion destructor
Expand Down Expand Up @@ -131,7 +131,7 @@ namespace OpenBabel
int result( EOF ) ;
if( gptr() < egptr() )
result = *gptr() ;
else if ( mySource != NULL )
else if ( mySource != nullptr )
{
result = myExtractor( *mySource ) ;
if ( result != EOF )
Expand All @@ -151,7 +151,7 @@ namespace OpenBabel
FilteringInputStreambuf< Extractor >::sync()
{
int result( 0 ) ;
if ( mySource != NULL )
if ( mySource != nullptr )
{
if ( gptr() < egptr() )
{ //have read something but not provided it
Expand Down
18 changes: 9 additions & 9 deletions include/openbabel/mol.h
Expand Up @@ -480,10 +480,10 @@ enum HydrogenType { AllHydrogen, PolarHydrogen, NonPolarHydrogen };
//! Iterative component of Separate to copy one fragment at a time
bool GetNextFragment( OpenBabel::OBMolAtomDFSIter& iter, OBMol& newMol );
// docs in mol.cpp
bool CopySubstructure(OBMol& newmol, OBBitVec *includeatoms, OBBitVec *excludebonds = (OBBitVec*)0,
bool CopySubstructure(OBMol& newmol, OBBitVec *includeatoms, OBBitVec *excludebonds = (OBBitVec*)nullptr,
unsigned int correctvalence=1,
std::vector<unsigned int> *atomorder=(std::vector<unsigned int>*)0,
std::vector<unsigned int> *bondorder=(std::vector<unsigned int>*)0);
std::vector<unsigned int> *atomorder=(std::vector<unsigned int>*)nullptr,
std::vector<unsigned int> *bondorder=(std::vector<unsigned int>*)nullptr);
//! Converts the charged form of coordinate bonds, e.g.[N+]([O-])=O to N(=O)=O
bool ConvertDativeBonds();
//! Converts 5-valent N and P only. Return true if conversion occurred.
Expand Down Expand Up @@ -630,12 +630,12 @@ enum HydrogenType { AllHydrogen, PolarHydrogen, NonPolarHydrogen };
//! \return the array of coordinates for the first conformer
double *BeginConformer(std::vector<double*>::iterator&i)
{ i = _vconf.begin();
return((i == _vconf.end()) ? NULL:*i); }
return((i == _vconf.end()) ? nullptr:*i); }
//! Advance the iterator to the next confomer, if possible
//! \return The array of coordinates for the next conformer, or NULL if none exist
double *NextConformer(std::vector<double*>::iterator&i)
{ ++i;
return((i == _vconf.end()) ? NULL:*i); }
return((i == _vconf.end()) ? nullptr:*i); }
//! \return the entire set of conformers for this molecule as a vector of floating point arrays
std::vector<double*> &GetConformers() { return(_vconf); }
//@}
Expand Down Expand Up @@ -672,30 +672,30 @@ enum HydrogenType { AllHydrogen, PolarHydrogen, NonPolarHydrogen };
OBResidue *BeginResidue(OBResidueIterator &i)
{
i = _residue.begin();
return((i == _residue.end()) ? NULL:*i);
return((i == _residue.end()) ? nullptr:*i);
}
//! Advance the iterator @p i to the next residue in the molecule
//! \return the next residue (if any, or NULL if not possible)
OBResidue *NextResidue(OBResidueIterator &i)
{
++i;
return((i == _residue.end()) ? NULL:*i);
return((i == _residue.end()) ? nullptr:*i);
}
//! Set the iterator to the beginning of the internal coordinate list
//! \return the first internal coordinate record, or NULL if none exist
//! \see SetInternalCoord
OBInternalCoord *BeginInternalCoord(std::vector<OBInternalCoord*>::iterator &i)
{
i = _internals.begin();
return((i == _internals.end()) ? NULL:*i);
return((i == _internals.end()) ? nullptr:*i);
}
//! Advance the iterator to the next internal coordinate record
//! \return the next first internal coordinate record, or NULL if none exist
//! \see SetInternalCoord
OBInternalCoord *NextInternalCoord(std::vector<OBInternalCoord*>::iterator &i)
{
++i;
return((i == _internals.end()) ? NULL:*i);
return((i == _internals.end()) ? nullptr:*i);
}
//@}

Expand Down

0 comments on commit 66042e0

Please sign in to comment.