From 27f711a6585e17c0c2882f6d7ea054a1f7a860eb Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Thu, 10 Mar 2022 16:00:10 +0900 Subject: [PATCH] Run clang-tidy (readability-braces-around-statements) (#4977) https://github.com/rdkit/rdkit/pull/3024#discussion_r526549843 --- .clang-tidy | 2 +- Code/DataStructs/BitOps.h | 8 +- Code/DataStructs/FPBReader.h | 8 +- Code/DataStructs/MultiFPBReader.h | 4 +- Code/DataStructs/SparseIntVect.h | 13 ++- Code/Geometry/point.h | 22 +++-- Code/GraphMol/Bond.h | 8 +- Code/GraphMol/CIPLabeler/CIPMol.cpp | 3 +- Code/GraphMol/CIPLabeler/Sort.cpp | 3 +- .../Enumerate/CartesianProduct.h | 7 +- .../Enumerate/EnumerationStrategyBase.h | 8 +- Code/GraphMol/ChemTransforms/catch_tests.cpp | 6 +- Code/GraphMol/Chirality.cpp | 4 +- Code/GraphMol/Conformer.h | 4 +- Code/GraphMol/Deprotect/Deprotect.cpp | 3 +- .../DistGeomHelpers/BoundsMatrixBuilder.cpp | 4 +- Code/GraphMol/FMCS/Composition2N.h | 10 ++- Code/GraphMol/FMCS/DuplicatedSeedCache.h | 35 ++++++-- Code/GraphMol/FMCS/RingMatchTableSet.h | 64 ++++++++++---- Code/GraphMol/FMCS/SeedSet.h | 7 +- Code/GraphMol/FMCS/SubstructureCache.h | 21 +++-- Code/GraphMol/FMCS/TargetMatch.h | 6 +- Code/GraphMol/FileParsers/MolFileWriter.cpp | 4 +- Code/GraphMol/FileParsers/MolWriters.h | 16 +++- Code/GraphMol/FilterCatalog/FilterMatchers.h | 11 ++- .../ForceFieldHelpers/FFConvenience.h | 8 +- .../MMFF/testMultiThread.cpp | 3 +- Code/GraphMol/FragCatalog/FragCatalogEntry.h | 4 +- Code/GraphMol/MolAlign/O3AAlignMolecules.h | 4 +- Code/GraphMol/MolBundle.h | 10 ++- Code/GraphMol/MolCatalog/MolCatalogEntry.h | 4 +- Code/GraphMol/MolDraw2D/MolDraw2DDetails.h | 8 +- Code/GraphMol/MolDraw2D/MolDraw2DSVG.cpp | 4 +- Code/GraphMol/MolDraw2D/test1.cpp | 4 +- Code/GraphMol/MolEnumerator/MolEnumerator.cpp | 4 +- Code/GraphMol/MolPickler.cpp | 4 +- Code/GraphMol/MolStandardize/Tautomer.h | 4 +- Code/GraphMol/PeriodicTable.h | 12 +-- Code/GraphMol/QueryAtom.h | 8 +- Code/GraphMol/QueryBond.h | 4 +- Code/GraphMol/QueryOps.h | 8 +- .../RGroupDecomposition/GaExample.cpp | 8 +- .../RGroupDecomposition/RGroupDecomp.h | 4 +- .../RGroupFingerprintScore.cpp | 8 +- .../GraphMol/RGroupDecomposition/RGroupGa.cpp | 12 ++- .../RGroupDecomposition/RGroupUtils.cpp | 4 +- .../RGroupDecomposition/testRGroupDecomp.cpp | 4 +- Code/GraphMol/SLNParse/SLNParseOps.h | 4 +- Code/GraphMol/SubstanceGroup.cpp | 4 +- Code/GraphMol/Substruct/vf2.hpp | 88 ++++++++++++++----- .../SubstructLibrary/SubstructLibrary.h | 44 +++++++--- .../SubstructLibrarySerialization.h | 4 +- Code/GraphMol/TautomerQuery/TautomerQuery.cpp | 4 +- Code/GraphMol/TautomerQuery/catch_tests.cpp | 4 +- Code/GraphMol/Wrap/props.hpp | 36 ++++++-- Code/GraphMol/Wrap/substructmethods.h | 4 +- Code/GraphMol/new_canon.h | 52 +++++++---- Code/ML/InfoTheory/InfoBitRanker.h | 8 +- Code/Numerics/Conrec.h | 23 +++-- Code/Numerics/Optimizer/BFGSOpt.h | 16 +++- Code/Numerics/Vector.h | 8 +- Code/PgSQL/rdkit/adapter.cpp | 24 +++-- Code/Query/AndQuery.h | 4 +- Code/Query/EqualityQuery.h | 5 +- Code/Query/GreaterEqualQuery.h | 15 ++-- Code/Query/GreaterQuery.h | 15 ++-- Code/Query/LessEqualQuery.h | 15 ++-- Code/Query/LessQuery.h | 15 ++-- Code/Query/OrQuery.h | 4 +- Code/Query/Query.h | 15 ++-- Code/Query/RangeQuery.h | 19 ++-- Code/Query/SetQuery.h | 9 +- Code/Query/XOrQuery.h | 4 +- Code/RDBoost/list_indexing_suite.hpp | 4 +- Code/RDBoost/python_streambuf.h | 56 ++++++++---- Code/RDGeneral/Dict.h | 8 +- Code/RDGeneral/RDValue-taggedunion.h | 87 +++++++++++++----- Code/RDGeneral/RDValue.h | 40 ++++++--- Code/RDGeneral/Ranking.h | 4 +- Code/RDGeneral/StreamOps.h | 24 +++-- Code/RDGeneral/hanoiSort.h | 17 ++-- Code/RDGeneral/utils.h | 5 +- Code/SimDivPickers/LeaderPicker.h | 68 ++++++++++---- Code/SimDivPickers/MaxMinPicker.h | 25 ++++-- External/GA/ga/LinkedPopLinearSel.h | 8 +- External/GA/ga/StringChromosome.cpp | 28 +++--- External/GA/ga/StringChromosomeBase.h | 20 +++-- External/GA/util/Util.cpp | 16 ++-- External/GA/util/Util.h | 35 +++++--- 89 files changed, 918 insertions(+), 384 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index bda718d42..747b59c06 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '-*,boost-use-to-string,modernize-use-auto,modernize-use-nullptr,modernize-loop-convert,modernize-use-override,modernize-pass-by-value,modernize-shrink-to-fit' +Checks: '-*,boost-use-to-string,modernize-use-auto,modernize-use-nullptr,modernize-loop-convert,modernize-use-override,modernize-pass-by-value,modernize-shrink-to-fit,readability-braces-around-statements' HeaderFilterRegex: 'Code/' AnalyzeTemporaryDtors: false User: glandrum diff --git a/Code/DataStructs/BitOps.h b/Code/DataStructs/BitOps.h index 7244a0942..99a5bd85b 100644 --- a/Code/DataStructs/BitOps.h +++ b/Code/DataStructs/BitOps.h @@ -43,7 +43,9 @@ double SimilarityWrapper(const T& bv1, const T& bv2, } else { res = metric(bv1, bv2); } - if (returnDistance) res = 1.0 - res; + if (returnDistance) { + res = 1.0 - res; + } return res; } //! \overload @@ -63,7 +65,9 @@ double SimilarityWrapper(const T& bv1, const T& bv2, double a, double b, } else { res = metric(bv1, bv2, a, b); } - if (returnDistance) res = 1.0 - res; + if (returnDistance) { + res = 1.0 - res; + } return res; } diff --git a/Code/DataStructs/FPBReader.h b/Code/DataStructs/FPBReader.h index 5d557c9d2..0a21fcdda 100644 --- a/Code/DataStructs/FPBReader.h +++ b/Code/DataStructs/FPBReader.h @@ -93,7 +93,9 @@ class RDKIT_DATASTRUCTS_EXPORT FPBReader { df_lazyRead(lazyRead) {} ~FPBReader() { destroy(); - if (df_owner) delete dp_istrm; + if (df_owner) { + delete dp_istrm; + } dp_istrm = nullptr; df_init = false; } @@ -115,7 +117,9 @@ class RDKIT_DATASTRUCTS_EXPORT FPBReader { Cleans up whatever memory was allocated during init() */ void cleanup() { - if (!df_init) return; + if (!df_init) { + return; + } destroy(); df_init = false; } diff --git a/Code/DataStructs/MultiFPBReader.h b/Code/DataStructs/MultiFPBReader.h index c4955f246..9e43c5787 100644 --- a/Code/DataStructs/MultiFPBReader.h +++ b/Code/DataStructs/MultiFPBReader.h @@ -121,7 +121,9 @@ class RDKIT_DATASTRUCTS_EXPORT MultiFPBReader { unsigned int addReader(FPBReader *rdr) { PRECONDITION(rdr, "no reader provided"); d_readers.push_back(rdr); - if (df_init) rdr->init(); + if (df_init) { + rdr->init(); + } return d_readers.size(); } diff --git a/Code/DataStructs/SparseIntVect.h b/Code/DataStructs/SparseIntVect.h index e33098dd6..a75ebb7da 100644 --- a/Code/DataStructs/SparseIntVect.h +++ b/Code/DataStructs/SparseIntVect.h @@ -115,10 +115,11 @@ class SparseIntVect { int res = 0; typename StorageType::const_iterator iter; for (iter = d_data.begin(); iter != d_data.end(); ++iter) { - if (!doAbs) + if (!doAbs) { res += iter->second; - else + } else { res += abs(iter->second); + } } return res; } @@ -523,7 +524,9 @@ double DiceSimilarity(const SparseIntVect &v1, } else { sim = 2. * numer / denom; } - if (returnDistance) sim = 1. - sim; + if (returnDistance) { + sim = 1. - sim; + } // std::cerr<<" "< &v1, } else { sim = andSum / denom; } - if (returnDistance) sim = 1. - sim; + if (returnDistance) { + sim = 1. - sim; + } // std::cerr<<" "<angleTo(other); // check the sign of the z component of the cross product: - if ((this->x * other.y - this->y * other.x) < -1e-6) res = 2.0 * M_PI - res; + if ((this->x * other.y - this->y * other.x) < -1e-6) { + res = 2.0 * M_PI - res; + } return res; } @@ -377,16 +379,19 @@ class RDKIT_RDGEOMETRYLIB_EXPORT Point2D : public Point { t2.normalize(); double dotProd = t1.dotProduct(t2); // watch for roundoff error: - if (dotProd < -1.0) + if (dotProd < -1.0) { dotProd = -1.0; - else if (dotProd > 1.0) + } else if (dotProd > 1.0) { dotProd = 1.0; + } return acos(dotProd); } double signedAngleTo(const Point2D &other) const { double res = this->angleTo(other); - if ((this->x * other.y - this->y * other.x) < -1e-6) res = 2.0 * M_PI - res; + if ((this->x * other.y - this->y * other.x) < -1e-6) { + res = 2.0 * M_PI - res; + } return res; } @@ -453,7 +458,9 @@ class RDKIT_RDGEOMETRYLIB_EXPORT PointND : public Point { unsigned int dimension() const override { return dp_storage.get()->size(); } PointND &operator=(const PointND &other) { - if (this == &other) return *this; + if (this == &other) { + return *this; + } RDNumeric::Vector *nvec = new RDNumeric::Vector(*other.getStorage()); @@ -501,10 +508,11 @@ class RDKIT_RDGEOMETRYLIB_EXPORT PointND : public Point { if ((n1 > 1.e-8) && (n2 > 1.e-8)) { dp /= (n1 * n2); } - if (dp < -1.0) + if (dp < -1.0) { dp = -1.0; - else if (dp > 1.0) + } else if (dp > 1.0) { dp = 1.0; + } return acos(dp); } diff --git a/Code/GraphMol/Bond.h b/Code/GraphMol/Bond.h index 97de162a8..f2174af80 100644 --- a/Code/GraphMol/Bond.h +++ b/Code/GraphMol/Bond.h @@ -124,7 +124,9 @@ class RDKIT_GRAPHMOL_EXPORT Bond : public RDProps { dp_stereoAtoms = std::exchange(o.dp_stereoAtoms, nullptr); } Bond &operator=(Bond &&o) noexcept { - if (this == &o) return *this; + if (this == &o) { + return *this; + } RDProps::operator=(std::move(o)); df_isAromatic = o.df_isAromatic; df_isConjugated = o.df_isConjugated; @@ -346,7 +348,9 @@ class RDKIT_GRAPHMOL_EXPORT Bond : public RDProps { } //! \overload INT_VECT &getStereoAtoms() { - if (!dp_stereoAtoms) dp_stereoAtoms = new INT_VECT(); + if (!dp_stereoAtoms) { + dp_stereoAtoms = new INT_VECT(); + } return *dp_stereoAtoms; } diff --git a/Code/GraphMol/CIPLabeler/CIPMol.cpp b/Code/GraphMol/CIPLabeler/CIPMol.cpp index e9eb1fd32..d798845c6 100644 --- a/Code/GraphMol/CIPLabeler/CIPMol.cpp +++ b/Code/GraphMol/CIPLabeler/CIPMol.cpp @@ -20,8 +20,9 @@ CIPMol::CIPMol(ROMol &mol) : d_mol{mol} {} boost::rational CIPMol::getFractionalAtomicNum(Atom *atom) const { PRECONDITION(atom, "bad atom") - if (d_atomnums.empty()) + if (d_atomnums.empty()) { const_cast(this)->d_atomnums = calcFracAtomNums(*this); + } return d_atomnums[atom->getIdx()]; } diff --git a/Code/GraphMol/CIPLabeler/Sort.cpp b/Code/GraphMol/CIPLabeler/Sort.cpp index 79ad0fcda..9aecb1072 100644 --- a/Code/GraphMol/CIPLabeler/Sort.cpp +++ b/Code/GraphMol/CIPLabeler/Sort.cpp @@ -29,7 +29,7 @@ Priority Sort::prioritize(const Node *node, std::vector &edges, bool unique = true; int numPseudoAsym = 0; - for (auto i = 0u; i < edges.size(); ++i) + for (auto i = 0u; i < edges.size(); ++i) { for (auto j = i; j > 0; --j) { int cmp = compareSubstituents(node, edges[j - 1], edges[j], deep); @@ -46,6 +46,7 @@ Priority Sort::prioritize(const Node *node, std::vector &edges, break; } } + } return {unique, numPseudoAsym == 1}; } diff --git a/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h b/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h index ba82d97e9..bbe18eed7 100644 --- a/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h +++ b/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h @@ -87,8 +87,9 @@ class RDKIT_CHEMREACTIONS_EXPORT CartesianProductStrategy const EnumerationTypes::RGROUPS &next() override { if (m_numPermutationsProcessed) { increment(); - } else + } else { ++m_numPermutationsProcessed; + } return m_permutation; } @@ -120,7 +121,9 @@ class RDKIT_CHEMREACTIONS_EXPORT CartesianProductStrategy } void next(size_t rowToIncrement) { - if (!hasNext()) return; + if (!hasNext()) { + return; + } m_permutation[rowToIncrement] += 1; size_t max_index_of_row = m_permutationSizes[rowToIncrement] - 1; if (m_permutation[rowToIncrement] > max_index_of_row) { diff --git a/Code/GraphMol/ChemReactions/Enumerate/EnumerationStrategyBase.h b/Code/GraphMol/ChemReactions/Enumerate/EnumerationStrategyBase.h index 659ccf395..40da5f411 100644 --- a/Code/GraphMol/ChemReactions/Enumerate/EnumerationStrategyBase.h +++ b/Code/GraphMol/ChemReactions/Enumerate/EnumerationStrategyBase.h @@ -75,7 +75,9 @@ template EnumerationTypes::RGROUPS getSizesFromBBs( const std::vector> &bbs) { EnumerationTypes::RGROUPS sizes; - for (size_t i = 0; i < bbs.size(); ++i) sizes.push_back(bbs[i].size()); + for (size_t i = 0; i < bbs.size(); ++i) { + sizes.push_back(bbs[i].size()); + } return sizes; } @@ -188,7 +190,9 @@ class RDKIT_CHEMREACTIONS_EXPORT EnumerationStrategyBase { //! Skip the specified number of permutations (useful for //! resetting state to a known position) bool skip(boost::uint64_t skipCount) { - for (boost::uint64_t i = 0; i < skipCount; ++i) next(); + for (boost::uint64_t i = 0; i < skipCount; ++i) { + next(); + } return true; } diff --git a/Code/GraphMol/ChemTransforms/catch_tests.cpp b/Code/GraphMol/ChemTransforms/catch_tests.cpp index 56e72e992..99581a9cd 100644 --- a/Code/GraphMol/ChemTransforms/catch_tests.cpp +++ b/Code/GraphMol/ChemTransforms/catch_tests.cpp @@ -322,8 +322,9 @@ TEST_CASE("molzip", "[]") { RDKit::MolFragmenter::fragmentOnBonds(*m, bonds)}; auto smiles = MolToSmiles(*resa); - if (std::count(smiles.begin(), smiles.end(), '/') != 2) + if (std::count(smiles.begin(), smiles.end(), '/') != 2) { continue; // we removed bond stereo in fragment to bonds! + } MolzipParams p; p.label = MolzipLabel::FragmentOnBonds; CHECK(MolToSmiles(*molzip(*resa, p)) == MolToSmiles(*m)); @@ -334,8 +335,9 @@ TEST_CASE("molzip", "[]") { *m, bonds, true, &dummyLabels)}; auto smiles = MolToSmiles(*res); - if (std::count(smiles.begin(), smiles.end(), '/') != 2) + if (std::count(smiles.begin(), smiles.end(), '/') != 2) { continue; // we removed bond stereo in fragment to bonds! + } for (auto *atom : res->atoms()) { if (atom->getIsotope()) { atom->setAtomMapNum(atom->getIsotope()); diff --git a/Code/GraphMol/Chirality.cpp b/Code/GraphMol/Chirality.cpp index 323866d32..dee1d2ed5 100644 --- a/Code/GraphMol/Chirality.cpp +++ b/Code/GraphMol/Chirality.cpp @@ -408,7 +408,9 @@ bool isLinearArrangement(const RDGeom::Point3D &v1, const RDGeom::Point3D &v2) { double lsq = v1.lengthSq() * v2.lengthSq(); // treat zero length vectors as linear - if (lsq < 1.0e-6) return true; + if (lsq < 1.0e-6) { + return true; + } double dotProd = v1.dotProduct(v2); diff --git a/Code/GraphMol/Conformer.h b/Code/GraphMol/Conformer.h index 18ed53b14..77eee6661 100644 --- a/Code/GraphMol/Conformer.h +++ b/Code/GraphMol/Conformer.h @@ -171,7 +171,9 @@ typedef boost::shared_ptr CONFORMER_SPTR; */ inline bool hasNonZeroZCoords(const Conformer &conf) { for (auto p : conf.getPositions()) { - if (p.z != 0.0) return true; + if (p.z != 0.0) { + return true; + } } return false; } diff --git a/Code/GraphMol/Deprotect/Deprotect.cpp b/Code/GraphMol/Deprotect/Deprotect.cpp index 733cf6c77..cbf319937 100644 --- a/Code/GraphMol/Deprotect/Deprotect.cpp +++ b/Code/GraphMol/Deprotect/Deprotect.cpp @@ -135,8 +135,9 @@ std::unique_ptr deprotect( if (deprotections_used.size() >= MAX_DEPROTECTIONS) { BOOST_LOG(rdErrorLog) << "Too many deprotections, halting..." << std::endl; - } else + } else { something_happened = true; + } break; } } diff --git a/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp b/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp index 49cb17a23..cab96d6b6 100644 --- a/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp +++ b/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp @@ -866,7 +866,9 @@ bool _checkMacrocycleAllInSameRingAmideEster14(const ROMol &mol, const Bond *, unsigned int a2Num = atm2->getAtomicNum(); unsigned int a3Num = atm3->getAtomicNum(); - if (a3Num != 6) return false; + if (a3Num != 6) { + return false; + } if (a2Num == 7 || a2Num == 8) { if (mol.getAtomDegree(atm2) == 3 && mol.getAtomDegree(atm3) == 3) { diff --git a/Code/GraphMol/FMCS/Composition2N.h b/Code/GraphMol/FMCS/Composition2N.h index ecb754fdc..409a2432a 100644 --- a/Code/GraphMol/FMCS/Composition2N.h +++ b/Code/GraphMol/FMCS/Composition2N.h @@ -32,16 +32,20 @@ class Composition2N { // generator of 2^N-1 possible bit combinations if ((++Bits) <= MaxValue) { InverseBits = (~Bits + 1) & ValueMask; return true; - } else + } else { return false; + } } bool is2Power() const { // one bit is set only BitSet bits = getBitSet(); unsigned n = 0; while (0 == (bits & 1uLL) && - ++n < sizeof(bits) * 8) // find lowest bitwise 1 + ++n < sizeof(bits) * 8) { // find lowest bitwise 1 bits >>= 1u; // shift all zero lower bits - if (0 != (bits & 1uLL)) bits >>= 1u; // shift first set bit too + } + if (0 != (bits & 1uLL)) { + bits >>= 1u; // shift first set bit too + } return 0 == bits; // remained bits except lowest 1 } // unused: bool nonZero() {return 0!=getBitSet();} diff --git a/Code/GraphMol/FMCS/DuplicatedSeedCache.h b/Code/GraphMol/FMCS/DuplicatedSeedCache.h index a336e8ce0..ae88b2d2a 100644 --- a/Code/GraphMol/FMCS/DuplicatedSeedCache.h +++ b/Code/GraphMol/FMCS/DuplicatedSeedCache.h @@ -47,18 +47,30 @@ class DuplicatedSeedCache { } bool operator<(const TKey& right) const { - if (AtomIdx.size() < right.AtomIdx.size()) return true; - if (AtomIdx.size() > right.AtomIdx.size()) return false; + if (AtomIdx.size() < right.AtomIdx.size()) { + return true; + } + if (AtomIdx.size() > right.AtomIdx.size()) { + return false; + } - if (BondIdx.size() < right.BondIdx.size()) return true; - if (BondIdx.size() > right.BondIdx.size()) return false; + if (BondIdx.size() < right.BondIdx.size()) { + return true; + } + if (BondIdx.size() > right.BondIdx.size()) { + return false; + } // everything is equal -> perform straight comparison int diff; diff = memcmp(&AtomIdx[0], &right.AtomIdx[0], AtomIdx.size() * sizeof(unsigned)); - if (diff < 0) return true; - if (diff > 0) return false; + if (diff < 0) { + return true; + } + if (diff > 0) { + return false; + } return memcmp(&BondIdx[0], &right.BondIdx[0], BondIdx.size() * sizeof(unsigned)) < 0; } @@ -76,16 +88,21 @@ class DuplicatedSeedCache { bool find(const TKey& key, TValue& value) const { value = false; - if (key.getNumAtoms() > MaxAtoms) + if (key.getNumAtoms() > MaxAtoms) { return false; // fast check if key greater then max key in the cache + } std::map::const_iterator entryit = Index.find(key); - if (Index.end() != entryit) value = entryit->second; + if (Index.end() != entryit) { + value = entryit->second; + } return Index.end() != entryit; } void add(const TKey& key, TValue found = true) { - if (key.getNumAtoms() > MaxAtoms) MaxAtoms = key.getNumAtoms(); + if (key.getNumAtoms() > MaxAtoms) { + MaxAtoms = key.getNumAtoms(); + } Index.insert(std::pair(key, found)); } diff --git a/Code/GraphMol/FMCS/RingMatchTableSet.h b/Code/GraphMol/FMCS/RingMatchTableSet.h index 1ce01d29d..9cb169695 100644 --- a/Code/GraphMol/FMCS/RingMatchTableSet.h +++ b/Code/GraphMol/FMCS/RingMatchTableSet.h @@ -27,16 +27,20 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { } inline void resize(unsigned s1, unsigned s2) { MatchMatrix.resize(s1, s2); - for (size_t i = 0; i < s1; i++) - for (size_t j = 0; j < s2; j++) MatchMatrix.set(i, j, false); + for (size_t i = 0; i < s1; i++) { + for (size_t j = 0; j < s2; j++) { + MatchMatrix.set(i, j, false); + } + } } inline void makeRingIndex(const ROMol* mol2) { unsigned i = 0; // for each TARGET ring const RingInfo::VECT_INT_VECT& rings2 = mol2->getRingInfo()->bondRings(); for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin(); - r2 != rings2.end(); r2++) + r2 != rings2.end(); r2++) { RingIndex[&*r2] = i++; + } } inline bool isEqual(unsigned i, const INT_VECT* r2) const { return MatchMatrix.at(i, getRingIndex(r2)); @@ -49,7 +53,9 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { inline unsigned getRingIndex(const INT_VECT* r2) const { std::map::const_iterator j = RingIndex.find(r2); - if (RingIndex.end() == j) throw -1; + if (RingIndex.end() == j) { + throw -1; + } return j->second; } }; @@ -66,7 +72,9 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { RingMatchTableSet() {} inline void clear() { - if (QueryBondRingsIndeces) QueryBondRingsIndeces->clear(); + if (QueryBondRingsIndeces) { + QueryBondRingsIndeces->clear(); + } TargetBondRingsIndecesSet.clear(); MatchMatrixSet.clear(); QueryRingIndex.clear(); @@ -82,14 +90,18 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { inline bool isTargetBondInRing(const ROMol* target, unsigned bi) const { std::map>>::const_iterator i = TargetBondRingsIndecesSet.find(target); - if (TargetBondRingsIndecesSet.end() == i) throw -1; // never + if (TargetBondRingsIndecesSet.end() == i) { + throw -1; // never + } return i->second[bi].empty(); } inline const std::vector& getTargetBondRings(const ROMol* target, unsigned bi) const { std::map>>::const_iterator i = TargetBondRingsIndecesSet.find(target); - if (TargetBondRingsIndecesSet.end() == i) throw -1; // never + if (TargetBondRingsIndecesSet.end() == i) { + throw -1; // never + } return i->second[bi]; } @@ -106,17 +118,20 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { unsigned i = 0; const RingInfo::VECT_INT_VECT& rings = query->getRingInfo()->bondRings(); for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin(); - r != rings.end(); r++) + r != rings.end(); r++) { QueryRingIndex[&*r] = i++; + } TargetBondRingsIndecesSet.clear(); QueryBondRingsIndeces = &TargetBondRingsIndecesSet[query]; QueryBondRingsIndeces->resize(query->getNumBonds()); size_t ri = 0; for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin(); - r != rings.end(); r++, ri++) + r != rings.end(); r++, ri++) { for (INT_VECT::const_iterator bi = r->begin(); bi != r->end(); - bi++) // all bonds in the ring + bi++) { // all bonds in the ring (*QueryBondRingsIndeces)[*bi].push_back(ri); + } + } } inline void addTargetBondRingsIndeces(const ROMol* mol2) { std::vector>& m = TargetBondRingsIndecesSet[mol2]; @@ -125,10 +140,12 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { size_t ri = 0; const RingInfo::VECT_INT_VECT& rings = mol2->getRingInfo()->bondRings(); for (RingInfo::VECT_INT_VECT::const_iterator r = rings.begin(); - r != rings.end(); r++, ri++) + r != rings.end(); r++, ri++) { for (INT_VECT::const_iterator bi = r->begin(); bi != r->end(); - bi++) // all bonds in the ring + bi++) { // all bonds in the ring m[*bi].push_back(ri); + } + } } void computeRingMatchTable( @@ -150,8 +167,9 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { // for each TARGET ring for (RingInfo::VECT_INT_VECT::const_iterator r2 = rings2.begin(); r2 != rings2.end(); r2++) { - if (r1->size() != r2->size()) // rings are different + if (r1->size() != r2->size()) { // rings are different continue; + } FMCS::Graph graph2; makeRingGraph( graph2, *r2, @@ -173,7 +191,9 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { parameters.BondTyper, nullptr, parameters.AtomCompareParameters, bp, parameters.CompareFunctionsUserData); #endif - if (match) m.setMatch(i, &*r2); + if (match) { + m.setMatch(i, &*r2); + } } } } @@ -191,9 +211,13 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { unsigned j2 = NotSet; std::map::const_iterator ai; ai = atomMap.find(atom1); - if (atomMap.end() != ai) j1 = ai->second; + if (atomMap.end() != ai) { + j1 = ai->second; + } ai = atomMap.find(atom2); - if (atomMap.end() != ai) j2 = ai->second; + if (atomMap.end() != ai) { + j2 = ai->second; + } if (NotSet == j1) { j1 = g.m_vertices.size(); atomMap[atom1] = j1; @@ -211,13 +235,17 @@ class RDKIT_FMCS_EXPORT RingMatchTableSet { inline unsigned getQueryRingIndex(const INT_VECT* r1) const { std::map::const_iterator i = QueryRingIndex.find(r1); - if (QueryRingIndex.end() == i) throw -1; // never + if (QueryRingIndex.end() == i) { + throw -1; // never + } return i->second; } inline const RingMatchTable& getTargetMatchMatrix(const ROMol* mol2) const { std::map::const_iterator mi = MatchMatrixSet.find(mol2); - if (MatchMatrixSet.end() == mi) throw -1; // never + if (MatchMatrixSet.end() == mi) { + throw -1; // never + } return mi->second; } diff --git a/Code/GraphMol/FMCS/SeedSet.h b/Code/GraphMol/FMCS/SeedSet.h index 6bf04b541..950c12a58 100644 --- a/Code/GraphMol/FMCS/SeedSet.h +++ b/Code/GraphMol/FMCS/SeedSet.h @@ -47,8 +47,11 @@ class RDKIT_FMCS_EXPORT SeedSet { // sorted by amount of bonds Value& add(const Value& seed) { iterator where; for (where = Seeds.begin(); where != Seeds.end(); - where++) // find position in sorted list - if (where->getNumBonds() < seed.getNumBonds()) break; + where++) { // find position in sorted list + if (where->getNumBonds() < seed.getNumBonds()) { + break; + } + } iterator it = Seeds.insert(where, EmptySeed); Value& val = *it; val.setMoleculeFragment(seed); diff --git a/Code/GraphMol/FMCS/SubstructureCache.h b/Code/GraphMol/FMCS/SubstructureCache.h index 3793f386a..c694dd914 100644 --- a/Code/GraphMol/FMCS/SubstructureCache.h +++ b/Code/GraphMol/FMCS/SubstructureCache.h @@ -52,15 +52,20 @@ class RDKIT_FMCS_EXPORT SubstructureCache { std::vector currCodes(nv); std::vector prevCodes(nv); size_t nIterations = seed.getNumBonds(); - if (nIterations > 5) nIterations = 5; + if (nIterations > 5) { + nIterations = 5; + } for (unsigned seedAtomIdx = 0; seedAtomIdx < seed.getNumAtoms(); - seedAtomIdx++) + seedAtomIdx++) { currCodes[seedAtomIdx] = queryAtomLabels[seed.MoleculeFragment.AtomsIdx[seedAtomIdx]]; + } for (size_t iter = 0; iter < nIterations; iter++) { - for (size_t i = 0; i < nv; i++) prevCodes[i] = currCodes[i]; + for (size_t i = 0; i < nv; i++) { + prevCodes[i] = currCodes[i]; + } for (size_t seedBondIdx = 0; seedBondIdx < ne; seedBondIdx++) { const Bond* bond = seed.MoleculeFragment.Bonds[seedBondIdx]; @@ -124,7 +129,9 @@ class RDKIT_FMCS_EXPORT SubstructureCache { key.computeKey(seed, queryAtomLabels, queryBondLabels); std::map::const_iterator entryit = NumericIndex.find(key.NumericMetrics.Value); - if (NumericIndex.end() != entryit) return &ValueStorage[entryit->second]; + if (NumericIndex.end() != entryit) { + return &ValueStorage[entryit->second]; + } return nullptr; // not found } @@ -147,8 +154,9 @@ class RDKIT_FMCS_EXPORT SubstructureCache { if (!NumericIndex .insert(std::pair( key.NumericMetrics.Value, ValueStorage.size() - 1)) - .second) + .second) { return; // not enough memory room to add the item, but it is just cache + } } size_t keyssize() const { // for statistics only @@ -158,8 +166,9 @@ class RDKIT_FMCS_EXPORT SubstructureCache { size_t fullsize() const { // for statistics only size_t n = 0; for (std::vector::const_iterator e = ValueStorage.begin(); - e != ValueStorage.end(); e++) + e != ValueStorage.end(); e++) { n += e->size(); + } return n; } }; diff --git a/Code/GraphMol/FMCS/TargetMatch.h b/Code/GraphMol/FMCS/TargetMatch.h index af956e992..d1df039b2 100644 --- a/Code/GraphMol/FMCS/TargetMatch.h +++ b/Code/GraphMol/FMCS/TargetMatch.h @@ -66,10 +66,12 @@ struct TargetMatch { for(size_t i = 0; i < TargetBondIdx.size(); i++) TargetBondIdx[i] = -1; */ - for (size_t i = 0; i < VisitedTargetBonds.size(); i++) + for (size_t i = 0; i < VisitedTargetBonds.size(); i++) { VisitedTargetBonds[i] = false; - for (size_t i = 0; i < VisitedTargetAtoms.size(); i++) + } + for (size_t i = 0; i < VisitedTargetAtoms.size(); i++) { VisitedTargetAtoms[i] = false; + } MatchedAtomSize = match.size(); for (match_V_t::const_iterator mit = match.begin(); mit != match.end(); diff --git a/Code/GraphMol/FileParsers/MolFileWriter.cpp b/Code/GraphMol/FileParsers/MolFileWriter.cpp index fae3853b1..07e2c6fb6 100644 --- a/Code/GraphMol/FileParsers/MolFileWriter.cpp +++ b/Code/GraphMol/FileParsers/MolFileWriter.cpp @@ -975,7 +975,9 @@ const std::string GetV3000MolFileAtomLine( } if (atom->getPropIfPresent(common_properties::molInversionFlag, iprop) && iprop) { - if (iprop == 1 || iprop == 2) ss << " INVRET=" << iprop; + if (iprop == 1 || iprop == 2) { + ss << " INVRET=" << iprop; + } } if (atom->getPropIfPresent(common_properties::molStereoCare, iprop) && iprop) { diff --git a/Code/GraphMol/FileParsers/MolWriters.h b/Code/GraphMol/FileParsers/MolWriters.h index e415fd00d..cb42d3e18 100644 --- a/Code/GraphMol/FileParsers/MolWriters.h +++ b/Code/GraphMol/FileParsers/MolWriters.h @@ -81,7 +81,9 @@ class RDKIT_FILEPARSERS_EXPORT SmilesWriter : public MolWriter { dp_ostream->flush(); } catch (...) { try { - if (dp_ostream->good()) dp_ostream->setstate(std::ios::badbit); + if (dp_ostream->good()) { + dp_ostream->setstate(std::ios::badbit); + } } catch (const std::runtime_error &) { } } @@ -159,7 +161,9 @@ class RDKIT_FILEPARSERS_EXPORT SDWriter : public MolWriter { dp_ostream->flush(); } catch (...) { try { - if (dp_ostream->good()) dp_ostream->setstate(std::ios::badbit); + if (dp_ostream->good()) { + dp_ostream->setstate(std::ios::badbit); + } } catch (const std::runtime_error &) { } } @@ -230,7 +234,9 @@ class RDKIT_FILEPARSERS_EXPORT TDTWriter : public MolWriter { dp_ostream->flush(); } catch (...) { try { - if (dp_ostream->good()) dp_ostream->setstate(std::ios::badbit); + if (dp_ostream->good()) { + dp_ostream->setstate(std::ios::badbit); + } } catch (const std::runtime_error &) { } } @@ -298,7 +304,9 @@ class RDKIT_FILEPARSERS_EXPORT PDBWriter : public MolWriter { dp_ostream->flush(); } catch (...) { try { - if (dp_ostream->good()) dp_ostream->setstate(std::ios::badbit); + if (dp_ostream->good()) { + dp_ostream->setstate(std::ios::badbit); + } } catch (const std::runtime_error &) { } } diff --git a/Code/GraphMol/FilterCatalog/FilterMatchers.h b/Code/GraphMol/FilterCatalog/FilterMatchers.h index 7ea67a08a..c9854d3bf 100644 --- a/Code/GraphMol/FilterCatalog/FilterMatchers.h +++ b/Code/GraphMol/FilterCatalog/FilterMatchers.h @@ -43,7 +43,9 @@ namespace RDKit { namespace { std::string getArgName(const boost::shared_ptr &arg) { - if (arg.get()) return arg->getName(); + if (arg.get()) { + return arg->getName(); + } return ""; } } // namespace @@ -403,8 +405,11 @@ class RDKIT_FILTERCATALOG_EXPORT ExclusionList : public FilterMatcherBase { } bool isValid() const override { - for (size_t i = 0; i < d_offPatterns.size(); ++i) - if (!d_offPatterns[i]->isValid()) return false; + for (size_t i = 0; i < d_offPatterns.size(); ++i) { + if (!d_offPatterns[i]->isValid()) { + return false; + } + } return true; } diff --git a/Code/GraphMol/ForceFieldHelpers/FFConvenience.h b/Code/GraphMol/ForceFieldHelpers/FFConvenience.h index 6d5d37436..1b65826b1 100644 --- a/Code/GraphMol/ForceFieldHelpers/FFConvenience.h +++ b/Code/GraphMol/ForceFieldHelpers/FFConvenience.h @@ -30,7 +30,9 @@ void OptimizeMoleculeConfsHelper_(ForceFields::ForceField ff, ROMol *mol, ff.positions().resize(mol->getNumAtoms()); for (ROMol::ConformerIterator cit = mol->beginConformers(); cit != mol->endConformers(); ++cit, ++i) { - if (i % numThreads != threadIdx) continue; + if (i % numThreads != threadIdx) { + continue; + } for (unsigned int aidx = 0; aidx < mol->getNumAtoms(); ++aidx) { ff.positions()[aidx] = &(*cit)->getAtomPos(aidx); } @@ -50,7 +52,9 @@ void OptimizeMoleculeConfsMT(ROMol &mol, const ForceFields::ForceField &ff, &res, ti, numThreads, maxIters)); } for (auto &thread : tg) { - if (thread.joinable()) thread.join(); + if (thread.joinable()) { + thread.join(); + } } } #endif diff --git a/Code/GraphMol/ForceFieldHelpers/MMFF/testMultiThread.cpp b/Code/GraphMol/ForceFieldHelpers/MMFF/testMultiThread.cpp index 984f93adf..0418fd016 100644 --- a/Code/GraphMol/ForceFieldHelpers/MMFF/testMultiThread.cpp +++ b/Code/GraphMol/ForceFieldHelpers/MMFF/testMultiThread.cpp @@ -86,10 +86,11 @@ void testMMFFMultiThread() { fut.get(); } std::cerr << "done" << std::endl; - for (unsigned int i = 0; i < count; ++i) + for (unsigned int i = 0; i < count; ++i) { for (auto *mol : mols[i]) { delete mol; } + } BOOST_LOG(rdErrorLog) << " done" << std::endl; } diff --git a/Code/GraphMol/FragCatalog/FragCatalogEntry.h b/Code/GraphMol/FragCatalog/FragCatalogEntry.h index 415b3a96f..42b5b8aa9 100644 --- a/Code/GraphMol/FragCatalog/FragCatalogEntry.h +++ b/Code/GraphMol/FragCatalog/FragCatalogEntry.h @@ -102,7 +102,9 @@ class RDKIT_FRAGCATALOG_EXPORT FragCatalogEntry } bool hasProp(const char *key) const { - if (!dp_props) return false; + if (!dp_props) { + return false; + } return dp_props->hasVal(key); } bool hasProp(const std::string &key) const { return hasProp(key.c_str()); } diff --git a/Code/GraphMol/MolAlign/O3AAlignMolecules.h b/Code/GraphMol/MolAlign/O3AAlignMolecules.h index 79862d62d..13112f8f0 100644 --- a/Code/GraphMol/MolAlign/O3AAlignMolecules.h +++ b/Code/GraphMol/MolAlign/O3AAlignMolecules.h @@ -206,7 +206,9 @@ class RDKIT_MOLALIGN_EXPORT SDM { } // assignment operator SDM &operator=(const SDM &other) { - if (this == &other) return *this; + if (this == &other) { + return *this; + } d_prbConf = other.d_prbConf; d_refConf = other.d_refConf; d_o3aConstraintVect = other.d_o3aConstraintVect; diff --git a/Code/GraphMol/MolBundle.h b/Code/GraphMol/MolBundle.h index c95bfefbf..fc9b3bae2 100644 --- a/Code/GraphMol/MolBundle.h +++ b/Code/GraphMol/MolBundle.h @@ -61,7 +61,9 @@ class MolBundle : public RDProps { virtual size_t size() const { return d_mols.size(); } //! returns a particular molecule in the bundle virtual const boost::shared_ptr getMol(size_t idx) const { - if (idx >= d_mols.size()) throw IndexErrorException(static_cast(idx)); + if (idx >= d_mols.size()) { + throw IndexErrorException(static_cast(idx)); + } return d_mols[idx]; } //! returns a particular molecule from the bundle @@ -100,13 +102,15 @@ class FixedMolSizeMolBundle : public MolBundle { size_t addMol(boost::shared_ptr nmol) override { PRECONDITION(nmol.get(), "bad mol pointer"); if (d_mols.size()) { - if (nmol->getNumAtoms() != d_mols[0]->getNumAtoms()) + if (nmol->getNumAtoms() != d_mols[0]->getNumAtoms()) { throw ValueErrorException( "all molecules in a bundle must have the same number of atoms"); + } // REVIEW: should we allow different numbers of bonds? - if (nmol->getNumBonds() != d_mols[0]->getNumBonds()) + if (nmol->getNumBonds() != d_mols[0]->getNumBonds()) { throw ValueErrorException( "all molecules in a bundle must have the same number of bonds"); + } } d_mols.push_back(nmol); return (d_mols.size()); diff --git a/Code/GraphMol/MolCatalog/MolCatalogEntry.h b/Code/GraphMol/MolCatalog/MolCatalogEntry.h index 183738007..d07ffdb98 100644 --- a/Code/GraphMol/MolCatalog/MolCatalogEntry.h +++ b/Code/GraphMol/MolCatalog/MolCatalogEntry.h @@ -75,7 +75,9 @@ class RDKIT_MOLCATALOG_EXPORT MolCatalogEntry : public RDCatalog::CatalogEntry { //! returns true if such a property exists bool hasProp(const char *key) const { - if (!dp_props) return false; + if (!dp_props) { + return false; + } return dp_props->hasVal(key); } //! \overload diff --git a/Code/GraphMol/MolDraw2D/MolDraw2DDetails.h b/Code/GraphMol/MolDraw2D/MolDraw2DDetails.h index 5f6b74925..eaf2c88a4 100644 --- a/Code/GraphMol/MolDraw2D/MolDraw2DDetails.h +++ b/Code/GraphMol/MolDraw2D/MolDraw2DDetails.h @@ -64,7 +64,9 @@ RDKIT_MOLDRAW2D_EXPORT void addStereoAnnotation( RDKIT_MOLDRAW2D_EXPORT inline void addAtomIndices(const ROMol &mol) { // we don't need this in the global set of tags since it will only be used // here - if (mol.hasProp("_atomIndicesAdded")) return; + if (mol.hasProp("_atomIndicesAdded")) { + return; + } bool computed = true; mol.setProp("_atomIndicesAdded", 1, computed); for (auto atom : mol.atoms()) { @@ -80,7 +82,9 @@ RDKIT_MOLDRAW2D_EXPORT inline void addAtomIndices(const ROMol &mol) { RDKIT_MOLDRAW2D_EXPORT inline void addBondIndices(const ROMol &mol) { // we don't need this in the global set of tags since it will only be used // here - if (mol.hasProp("_bondIndicesAdded")) return; + if (mol.hasProp("_bondIndicesAdded")) { + return; + } bool computed = true; mol.setProp("_bondIndicesAdded", 1, computed); for (auto bond : mol.bonds()) { diff --git a/Code/GraphMol/MolDraw2D/MolDraw2DSVG.cpp b/Code/GraphMol/MolDraw2D/MolDraw2DSVG.cpp index 0c792cc70..9a9cbf024 100644 --- a/Code/GraphMol/MolDraw2D/MolDraw2DSVG.cpp +++ b/Code/GraphMol/MolDraw2D/MolDraw2DSVG.cpp @@ -474,7 +474,9 @@ void MolDraw2DSVG::tagAtoms(const ROMol &mol, double radius, // **************************************************************************** void MolDraw2DSVG::outputClasses() { - if (d_activeClass.empty() && !hasActiveAtmIdx()) return; + if (d_activeClass.empty() && !hasActiveAtmIdx()) { + return; + } d_os << "class='"; if (!d_activeClass.empty()) { diff --git a/Code/GraphMol/MolDraw2D/test1.cpp b/Code/GraphMol/MolDraw2D/test1.cpp index c77a9b525..6754755b9 100644 --- a/Code/GraphMol/MolDraw2D/test1.cpp +++ b/Code/GraphMol/MolDraw2D/test1.cpp @@ -537,7 +537,9 @@ void test1() { // https://stackoverflow.com/questions/22489073/counting-the-number-of-occurrences-of-a-string-within-a-string auto countSubstring = [](const std::string &str, const std::string &sub) -> int { - if (sub.length() == 0) return 0; + if (sub.length() == 0) { + return 0; + } int count = 0; for (size_t offset = str.find(sub); offset != std::string::npos; offset = str.find(sub, offset + sub.length())) { diff --git a/Code/GraphMol/MolEnumerator/MolEnumerator.cpp b/Code/GraphMol/MolEnumerator/MolEnumerator.cpp index ec3ec018a..371bee68e 100644 --- a/Code/GraphMol/MolEnumerator/MolEnumerator.cpp +++ b/Code/GraphMol/MolEnumerator/MolEnumerator.cpp @@ -29,7 +29,9 @@ void getVariations(size_t level, std::vector base, getVariations(level + 1, base, variations, variationCounts, maxToEnumerate, doRandom); } - if (variations.size() >= maxToEnumerate) return; + if (variations.size() >= maxToEnumerate) { + return; + } } } void enumerateVariations(std::vector> &variations, diff --git a/Code/GraphMol/MolPickler.cpp b/Code/GraphMol/MolPickler.cpp index bb901962c..da258ec49 100644 --- a/Code/GraphMol/MolPickler.cpp +++ b/Code/GraphMol/MolPickler.cpp @@ -487,7 +487,9 @@ Query *unpickleQuery(std::istream &ss, res->setNegation(isNegated); res->setDescription(descr); - if (!typeLabel.empty()) res->setTypeLabel(typeLabel); + if (!typeLabel.empty()) { + res->setTypeLabel(typeLabel); + } QueryOps::finalizeQueryFromDescription(res, owner); diff --git a/Code/GraphMol/MolStandardize/Tautomer.h b/Code/GraphMol/MolStandardize/Tautomer.h index ae1df032f..cdb5f643f 100644 --- a/Code/GraphMol/MolStandardize/Tautomer.h +++ b/Code/GraphMol/MolStandardize/Tautomer.h @@ -212,7 +212,9 @@ class RDKIT_MOLSTANDARDIZE_EXPORT TautomerEnumerator { d_removeIsotopicHs(other.d_removeIsotopicHs), d_reassignStereo(other.d_reassignStereo) {} TautomerEnumerator &operator=(const TautomerEnumerator &other) { - if (this == &other) return *this; + if (this == &other) { + return *this; + } dp_catalog = other.dp_catalog; d_callback = other.d_callback; d_maxTautomers = other.d_maxTautomers; diff --git a/Code/GraphMol/PeriodicTable.h b/Code/GraphMol/PeriodicTable.h index 36d9c85e9..b960f4737 100644 --- a/Code/GraphMol/PeriodicTable.h +++ b/Code/GraphMol/PeriodicTable.h @@ -78,15 +78,17 @@ class RDKIT_GRAPHMOL_EXPORT PeriodicTable { // this little optimization actually makes a measurable difference // in molecule-construction time int anum = -1; - if (elementSymbol == "C") + if (elementSymbol == "C") { anum = 6; - else if (elementSymbol == "N") + } else if (elementSymbol == "N") { anum = 7; - else if (elementSymbol == "O") + } else if (elementSymbol == "O") { anum = 8; - else { + } else { STR_UINT_MAP::const_iterator iter = byname.find(elementSymbol); - if (iter != byname.end()) anum = iter->second; + if (iter != byname.end()) { + anum = iter->second; + } } POSTCONDITION(anum > -1, "Element '" + elementSymbol + "' not found"); return anum; diff --git a/Code/GraphMol/QueryAtom.h b/Code/GraphMol/QueryAtom.h index b7d240a07..f8f6ff0ed 100644 --- a/Code/GraphMol/QueryAtom.h +++ b/Code/GraphMol/QueryAtom.h @@ -54,7 +54,9 @@ class RDKIT_GRAPHMOL_EXPORT QueryAtom : public Atom { } } QueryAtom &operator=(const QueryAtom &other) { - if (this == &other) return *this; + if (this == &other) { + return *this; + } Atom::operator=(other); delete dp_query; if (other.dp_query) { @@ -134,7 +136,9 @@ namespace detail { inline std::string qhelper(Atom::QUERYATOM_QUERY *q, unsigned int depth) { std::string res = ""; if (q) { - for (unsigned int i = 0; i < depth; ++i) res += " "; + for (unsigned int i = 0; i < depth; ++i) { + res += " "; + } res += q->getFullDescription() + "\n"; for (Atom::QUERYATOM_QUERY::CHILD_VECT_CI ci = q->beginChildren(); ci != q->endChildren(); ++ci) { diff --git a/Code/GraphMol/QueryBond.h b/Code/GraphMol/QueryBond.h index 1bfc52b7a..03a39721a 100644 --- a/Code/GraphMol/QueryBond.h +++ b/Code/GraphMol/QueryBond.h @@ -121,7 +121,9 @@ namespace detail { inline std::string qhelper(Bond::QUERYBOND_QUERY *q, unsigned int depth) { std::string res; if (q) { - for (unsigned int i = 0; i < depth; ++i) res += " "; + for (unsigned int i = 0; i < depth; ++i) { + res += " "; + } res += q->getFullDescription() + "\n"; for (Bond::QUERYBOND_QUERY::CHILD_VECT_CI ci = q->beginChildren(); ci != q->endChildren(); ++ci) { diff --git a/Code/GraphMol/QueryOps.h b/Code/GraphMol/QueryOps.h index d9bac7107..452ac75a8 100644 --- a/Code/GraphMol/QueryOps.h +++ b/Code/GraphMol/QueryOps.h @@ -142,11 +142,15 @@ static inline void parseAtomType(int val, int &atomic_num, bool &aromatic) { } } static inline bool getAtomTypeIsAromatic(int val) { - if (val > 1000) return true; + if (val > 1000) { + return true; + } return false; } static inline int getAtomTypeAtomicNum(int val) { - if (val > 1000) return val - 1000; + if (val > 1000) { + return val - 1000; + } return val; } diff --git a/Code/GraphMol/RGroupDecomposition/GaExample.cpp b/Code/GraphMol/RGroupDecomposition/GaExample.cpp index 42cc68f7d..b0e3cdf7c 100644 --- a/Code/GraphMol/RGroupDecomposition/GaExample.cpp +++ b/Code/GraphMol/RGroupDecomposition/GaExample.cpp @@ -110,8 +110,12 @@ int main(int argc, char* argv[]) { int batch = vm["batch"].as(); while (getline(fh, line)) { count++; - if (count < start) continue; - if (count > start + batch) break; + if (count < start) { + continue; + } + if (count > start + batch) { + break; + } int pos = line.find_last_of("\t"); auto smiles = line.substr(pos + 1); shared_ptr mol(SmilesToMol(smiles)); diff --git a/Code/GraphMol/RGroupDecomposition/RGroupDecomp.h b/Code/GraphMol/RGroupDecomposition/RGroupDecomp.h index c0a1206bb..0ad92c0e6 100644 --- a/Code/GraphMol/RGroupDecomposition/RGroupDecomp.h +++ b/Code/GraphMol/RGroupDecomposition/RGroupDecomp.h @@ -206,7 +206,9 @@ RDKIT_RGROUPDECOMPOSITION_EXPORT unsigned int RGroupDecompose( inline bool checkForTimeout(const std::chrono::steady_clock::time_point &t0, double timeout, bool throwOnTimeout = true) { - if (timeout <= 0) return false; + if (timeout <= 0) { + return false; + } auto t1 = std::chrono::steady_clock::now(); std::chrono::duration elapsed = t1 - t0; if (elapsed.count() >= timeout) { diff --git a/Code/GraphMol/RGroupDecomposition/RGroupFingerprintScore.cpp b/Code/GraphMol/RGroupDecomposition/RGroupFingerprintScore.cpp index 0ab50ef80..a4ab49696 100644 --- a/Code/GraphMol/RGroupDecomposition/RGroupFingerprintScore.cpp +++ b/Code/GraphMol/RGroupDecomposition/RGroupFingerprintScore.cpp @@ -39,7 +39,9 @@ void addFingerprintToRGroupData(RGroupData *rgroupData) { // TODO- Handle multiple attachments differently? if (atom->getAtomicNum() == 0) { atom->setAtomicNum(5); - if (atom->getIsotope() > 0) atom->setIsotope(0); + if (atom->getIsotope() > 0) { + atom->setIsotope(0); + } } } try { @@ -266,7 +268,9 @@ void VarianceDataForLabel::removeRgroupData(RGroupData *rgroupData) { // calculate the mean variance for a bit counts array double VarianceDataForLabel::variance() const { auto lambda = [this](double sum, int bitCount) { - if (bitCount == 0) return sum; + if (bitCount == 0) { + return sum; + } // variance calculation because fingerprint is binary: // sum == squared sum == bit count // ss = sqrSum - (sum * sum) / cnt; diff --git a/Code/GraphMol/RGroupDecomposition/RGroupGa.cpp b/Code/GraphMol/RGroupDecomposition/RGroupGa.cpp index 1682ac76f..48e344d1b 100644 --- a/Code/GraphMol/RGroupDecomposition/RGroupGa.cpp +++ b/Code/GraphMol/RGroupDecomposition/RGroupGa.cpp @@ -105,7 +105,9 @@ RGroupGa::RGroupGa(const RGroupDecompData& rGroupData, numPermutations = 1L; auto pos = 0; for (auto m : matches) { - if (m.size() == 1) continue; + if (m.size() == 1) { + continue; + } chromosomePolicy.setMax(pos, m.size()); unsigned long count = numPermutations * m.size(); numPermutations = count / m.size() == numPermutations @@ -118,7 +120,9 @@ RGroupGa::RGroupGa(const RGroupDecompData& rGroupData, // TODO refine these settings auto popsize = 100 + chromLength / 10; - if (popsize > 200) popsize = 200; + if (popsize > 200) { + popsize = 200; + } const auto& params = rGroupData.params; if (params.gaPopulationSize > 0) { popsize = params.gaPopulationSize; @@ -167,7 +171,9 @@ void RGroupGa::rGroupMutateOperation( child->decode(); auto& fingerprintVarianceScoreData = child->getFingerprintVarianceScoreData(); - if (fingerprintVarianceScoreData.labelsToVarianceData.size() == 0) return; + if (fingerprintVarianceScoreData.labelsToVarianceData.size() == 0) { + return; + } #ifdef DEBUG std::cerr << "RGroup mutate start" << std::endl; #endif diff --git a/Code/GraphMol/RGroupDecomposition/RGroupUtils.cpp b/Code/GraphMol/RGroupDecomposition/RGroupUtils.cpp index d469bd392..e7a23035b 100644 --- a/Code/GraphMol/RGroupDecomposition/RGroupUtils.cpp +++ b/Code/GraphMol/RGroupDecomposition/RGroupUtils.cpp @@ -104,7 +104,9 @@ bool isUserRLabel(const Atom &atom) { } bool isAtomWithMultipleNeighborsOrNotUserRLabel(const Atom &atom) { - if (atom.getDegree() > 1) return true; + if (atom.getDegree() > 1) { + return true; + } return !isUserRLabel(atom); } diff --git a/Code/GraphMol/RGroupDecomposition/testRGroupDecomp.cpp b/Code/GraphMol/RGroupDecomposition/testRGroupDecomp.cpp index cc4820ccb..e4bc19bd7 100644 --- a/Code/GraphMol/RGroupDecomposition/testRGroupDecomp.cpp +++ b/Code/GraphMol/RGroupDecomposition/testRGroupDecomp.cpp @@ -1852,7 +1852,9 @@ void testMultipleCoreRelabellingIssues() { auto smiles = line.substr(pos + 1); std::shared_ptr mol(SmilesToMol(smiles)); molecules.push_back(mol); - if (molecules.size() == 30) break; + if (molecules.size() == 30) { + break; + } } } diff --git a/Code/GraphMol/SLNParse/SLNParseOps.h b/Code/GraphMol/SLNParse/SLNParseOps.h index 46ee5c217..c89d9feb2 100644 --- a/Code/GraphMol/SLNParse/SLNParseOps.h +++ b/Code/GraphMol/SLNParse/SLNParseOps.h @@ -222,7 +222,9 @@ int addBranchToMol(std::vector &molList, unsigned int molIdx, for (ROMol::ATOM_BOOKMARK_MAP::const_iterator bmIt = branch->getAtomBookmarks()->begin(); bmIt != branch->getAtomBookmarks()->end(); ++bmIt) { - if (bmIt->first < 0) continue; + if (bmIt->first < 0) { + continue; + } if (mp->hasAtomBookmark(bmIt->first)) { std::stringstream err; err << "SLN Parser error: Atom ID " << bmIt->first diff --git a/Code/GraphMol/SubstanceGroup.cpp b/Code/GraphMol/SubstanceGroup.cpp index 7b0ab62f6..4e4807c4b 100644 --- a/Code/GraphMol/SubstanceGroup.cpp +++ b/Code/GraphMol/SubstanceGroup.cpp @@ -316,7 +316,9 @@ bool removedParentInHierarchy( const boost::dynamic_bitset<> &toRemove, const std::map &indexLookup) { PRECONDITION(idx < sgs.size(), "cannot find SubstanceGroup"); - if (toRemove[idx]) return true; + if (toRemove[idx]) { + return true; + } unsigned int parent; if (sgs[idx].getPropIfPresent("PARENT", parent)) { diff --git a/Code/GraphMol/Substruct/vf2.hpp b/Code/GraphMol/Substruct/vf2.hpp index ac3962b4d..8048f0892 100644 --- a/Code/GraphMol/Substruct/vf2.hpp +++ b/Code/GraphMol/Substruct/vf2.hpp @@ -43,10 +43,18 @@ struct Pair { * The ordering by in/out degree */ static bool nodeInfoComp1(const NodeInfo &a, const NodeInfo &b) { - if (a.out < b.out) return true; - if (a.out > b.out) return false; - if (a.in < b.in) return true; - if (a.in > b.in) return false; + if (a.out < b.out) { + return true; + } + if (a.out > b.out) { + return false; + } + if (a.in < b.in) { + return true; + } + if (a.in > b.in) { + return false; + } return false; } @@ -55,12 +63,24 @@ static bool nodeInfoComp1(const NodeInfo &a, const NodeInfo &b) { * The frequency is in the out field, the valence in `in'. */ static int nodeInfoComp2(const NodeInfo &a, const NodeInfo &b) { - if (!a.in && b.in) return 1; - if (a.in && !b.in) return -1; - if (a.out < b.out) return -1; - if (a.out > b.out) return 1; - if (a.in < b.in) return -1; - if (a.in > b.in) return 1; + if (!a.in && b.in) { + return 1; + } + if (a.in && !b.in) { + return -1; + } + if (a.out < b.out) { + return -1; + } + if (a.out > b.out) { + return 1; + } + if (a.in < b.in) { + return -1; + } + if (a.in > b.in) { + return 1; + } return 0; } @@ -106,8 +126,9 @@ node_id *SortNodesByFrequency(const Graph *g) { for (unsigned int i = 0; i < vect.size(); i += run) { for (run = 1; i + run < vect.size() && vect[i + run].in == vect[i].in && vect[i + run].out == vect[i].out; - ++run) + ++run) { ; + } for (unsigned int j = 0; j < run; ++j) { vect[i + j].in += vect[i + j].out; vect[i + j].out = run; @@ -240,11 +261,14 @@ class VF2SubState { Graph *GetGraph2() { return g2; } bool NextPair(Pair &pair) { - if (pair.n1 == NULL_NODE) pair.n1 = 0; - if (pair.n2 == NULL_NODE) + if (pair.n1 == NULL_NODE) { + pair.n1 = 0; + } + if (pair.n2 == NULL_NODE) { pair.n2 = 0; - else + } else { pair.n2++; + } #if 0 std::cerr<<" **** np: "<< prev_n1<<","< boost::out_degree(node2, *g2)) + if (boost::out_degree(node1, *g1) > boost::out_degree(node2, *g2)) { return false; - if (!vc(node1, node2)) return false; + } + if (!vc(node1, node2)) { + return false; + } unsigned int other1, other2; #ifdef RDK_VF2_PRUNING @@ -494,17 +526,22 @@ class VF2SubState { bool Match(node_id c1[], node_id c2[]) { if (IsGoal()) { GetCoreSet(c1, c2); - if (MatchChecks(c1, c2)) return true; + if (MatchChecks(c1, c2)) { + return true; + } } - if (IsDead()) return false; + if (IsDead()) { + return false; + } Pair pair; while (NextPair(pair)) { if (IsFeasiblePair(pair.n1, pair.n2)) { AddPair(pair.n1, pair.n2); - if (Match(c1, c2)) // recurse + if (Match(c1, c2)) { // recurse return true; + } BackTrack(pair.n1, pair.n2); } } @@ -526,14 +563,17 @@ class VF2SubState { } } - if (IsDead()) return false; + if (IsDead()) { + return false; + } Pair pair; while (NextPair(pair)) { if (IsFeasiblePair(pair.n1, pair.n2)) { AddPair(pair.n1, pair.n2); - if (MatchAll(c1, c2, res, lim)) // recurse + if (MatchAll(c1, c2, res, lim)) { // recurse return true; + } BackTrack(pair.n1, pair.n2); } } diff --git a/Code/GraphMol/SubstructLibrary/SubstructLibrary.h b/Code/GraphMol/SubstructLibrary/SubstructLibrary.h index de27094f2..db95cd961 100644 --- a/Code/GraphMol/SubstructLibrary/SubstructLibrary.h +++ b/Code/GraphMol/SubstructLibrary/SubstructLibrary.h @@ -93,7 +93,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT MolHolder : public MolHolderBase { } boost::shared_ptr getMol(unsigned int idx) const override { - if (idx >= mols.size()) throw IndexErrorException(idx); + if (idx >= mols.size()) { + throw IndexErrorException(idx); + } return mols[idx]; } @@ -133,7 +135,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT CachedMolHolder : public MolHolderBase { } boost::shared_ptr getMol(unsigned int idx) const override { - if (idx >= mols.size()) throw IndexErrorException(idx); + if (idx >= mols.size()) { + throw IndexErrorException(idx); + } boost::shared_ptr mol(new ROMol); MolPickler::molFromPickle(mols[idx], mol.get()); return mol; @@ -177,7 +181,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT CachedSmilesMolHolder } boost::shared_ptr getMol(unsigned int idx) const override { - if (idx >= mols.size()) throw IndexErrorException(idx); + if (idx >= mols.size()) { + throw IndexErrorException(idx); + } boost::shared_ptr mol(SmilesToMol(mols[idx])); return mol; @@ -226,7 +232,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT CachedTrustedSmilesMolHolder } boost::shared_ptr getMol(unsigned int idx) const override { - if (idx >= mols.size()) throw IndexErrorException(idx); + if (idx >= mols.size()) { + throw IndexErrorException(idx); + } RWMol *m = SmilesToMol(mols[idx], 0, false); if (m) { @@ -249,7 +257,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT FPHolderBase { public: virtual ~FPHolderBase() { - for (size_t i = 0; i < fps.size(); ++i) delete fps[i]; + for (size_t i = 0; i < fps.size(); ++i) { + delete fps[i]; + } } virtual unsigned int size() const { return rdcast(fps.size()); } @@ -277,7 +287,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT FPHolderBase { //! Return false if a substructure search can never match the molecule bool passesFilter(unsigned int idx, const ExplicitBitVect &query) const { - if (idx >= fps.size()) throw IndexErrorException(idx); + if (idx >= fps.size()) { + throw IndexErrorException(idx); + } return AllProbeBitsMatch(query, *fps[idx]); } @@ -285,7 +297,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT FPHolderBase { //! Get the bit vector at the specified index (throws IndexError if out of //! range) const ExplicitBitVect &getFingerprint(unsigned int idx) const { - if (idx >= fps.size()) throw IndexErrorException(idx); + if (idx >= fps.size()) { + throw IndexErrorException(idx); + } return *fps[idx]; } @@ -388,7 +402,9 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT KeyFromPropHolder : public KeyHolderBase { } const std::string &getKey(unsigned int idx) const override { - if (idx >= keys.size()) throw IndexErrorException(idx); + if (idx >= keys.size()) { + throw IndexErrorException(idx); + } return keys[idx]; } @@ -604,30 +620,34 @@ class RDKIT_SUBSTRUCTLIBRARY_EXPORT SubstructLibrary { //! Get the underlying fingerprint implementation. /*! Throws a value error if no fingerprints have been set */ FPHolderBase &getFingerprints() { - if (!fps) + if (!fps) { throw ValueErrorException("Substruct Library does not have fingerprints"); + } return *fps; } const FPHolderBase &getFingerprints() const { - if (!fps) + if (!fps) { throw ValueErrorException("Substruct Library does not have fingerprints"); + } return *fps; } //! Get the underlying key holder implementation. /*! Throws a value error if no keyholder have been set */ KeyHolderBase &getKeys() { - if (!keyholder.get()) + if (!keyholder.get()) { throw ValueErrorException("Substruct Library does not have fingerprints"); + } return *keyholder.get(); } //! Get the underlying key holder implementation. /*! Throws a value error if no keyholder have been set */ const KeyHolderBase &getKeys() const { - if (!keyholder.get()) + if (!keyholder.get()) { throw ValueErrorException("Substruct Library does not have fingerprints"); + } return *keyholder.get(); } diff --git a/Code/GraphMol/SubstructLibrary/SubstructLibrarySerialization.h b/Code/GraphMol/SubstructLibrary/SubstructLibrarySerialization.h index 01b8c2857..8ade8f438 100644 --- a/Code/GraphMol/SubstructLibrary/SubstructLibrarySerialization.h +++ b/Code/GraphMol/SubstructLibrary/SubstructLibrarySerialization.h @@ -130,7 +130,9 @@ void load(Archive &ar, RDKit::FPHolderBase &fpholder, std::vector &fps = fpholder.getFingerprints(); ar &pickles; - for (size_t i = 0; i < fps.size(); ++i) delete fps[i]; + for (size_t i = 0; i < fps.size(); ++i) { + delete fps[i]; + } fps.clear(); for (auto &pkl : pickles) { diff --git a/Code/GraphMol/TautomerQuery/TautomerQuery.cpp b/Code/GraphMol/TautomerQuery/TautomerQuery.cpp index 06cb4dcfc..14adf6d85 100644 --- a/Code/GraphMol/TautomerQuery/TautomerQuery.cpp +++ b/Code/GraphMol/TautomerQuery/TautomerQuery.cpp @@ -102,7 +102,9 @@ class TautomerQueryMatcher { #ifdef VERBOSE std::cout << "Got Match " << std::endl; #endif - if (d_matchingTautomers) d_matchingTautomers->push_back(tautomer); + if (d_matchingTautomers) { + d_matchingTautomers->push_back(tautomer); + } } return matchingTautomer; } diff --git a/Code/GraphMol/TautomerQuery/catch_tests.cpp b/Code/GraphMol/TautomerQuery/catch_tests.cpp index 5da7815d3..132fc7917 100644 --- a/Code/GraphMol/TautomerQuery/catch_tests.cpp +++ b/Code/GraphMol/TautomerQuery/catch_tests.cpp @@ -36,7 +36,9 @@ TEST_CASE("TEMPLATE_ERROR") { std::cout << "Tautomer " << MolToSmiles(*taut) << " match " << test << std::endl; #endif - if (test) match = true; + if (test) { + match = true; + } } CHECK(match); diff --git a/Code/GraphMol/Wrap/props.hpp b/Code/GraphMol/Wrap/props.hpp index eb8ac5f74..d5fffae5b 100644 --- a/Code/GraphMol/Wrap/props.hpp +++ b/Code/GraphMol/Wrap/props.hpp @@ -82,15 +82,33 @@ boost::python::dict GetPropsAsDict(const T &obj, bool includePrivate, // std::vector, std::vector, string STR_VECT keys = obj.getPropList(includePrivate, includeComputed); for (size_t i = 0; i < keys.size(); ++i) { - if (AddToDict(obj, dict, keys[i])) continue; - if (AddToDict(obj, dict, keys[i])) continue; - if (AddToDict(obj, dict, keys[i])) continue; - if (AddToDict(obj, dict, keys[i])) continue; - if (AddToDict>(obj, dict, keys[i])) continue; - if (AddToDict>(obj, dict, keys[i])) continue; - if (AddToDict>(obj, dict, keys[i])) continue; - if (AddToDict>(obj, dict, keys[i])) continue; - if (AddToDict(obj, dict, keys[i])) continue; + if (AddToDict(obj, dict, keys[i])) { + continue; + } + if (AddToDict(obj, dict, keys[i])) { + continue; + } + if (AddToDict(obj, dict, keys[i])) { + continue; + } + if (AddToDict(obj, dict, keys[i])) { + continue; + } + if (AddToDict>(obj, dict, keys[i])) { + continue; + } + if (AddToDict>(obj, dict, keys[i])) { + continue; + } + if (AddToDict>(obj, dict, keys[i])) { + continue; + } + if (AddToDict>(obj, dict, keys[i])) { + continue; + } + if (AddToDict(obj, dict, keys[i])) { + continue; + } } return dict; } diff --git a/Code/GraphMol/Wrap/substructmethods.h b/Code/GraphMol/Wrap/substructmethods.h index e7a21c102..f8a6d494d 100644 --- a/Code/GraphMol/Wrap/substructmethods.h +++ b/Code/GraphMol/Wrap/substructmethods.h @@ -98,7 +98,9 @@ PyObject *helpGetSubstructMatch(T1 &mol, T2 &query, std::vector matches; pySubstructHelper(mol, query, params, matches); MatchVectType match; - if (matches.size()) match = matches[0]; + if (matches.size()) { + match = matches[0]; + } return convertMatches(match); } diff --git a/Code/GraphMol/new_canon.h b/Code/GraphMol/new_canon.h index c2df4ce3b..c431885f0 100644 --- a/Code/GraphMol/new_canon.h +++ b/Code/GraphMol/new_canon.h @@ -164,7 +164,9 @@ class RDKIT_GRAPHMOL_EXPORT SpecialChiralityAtomCompareFunctor { ii < dp_atoms[i].bonds.size() && ii < dp_atoms[j].bonds.size(); ++ii) { int cmp = bondholder::compare(dp_atoms[i].bonds[ii], dp_atoms[j].bonds[ii]); - if (cmp) return cmp; + if (cmp) { + return cmp; + } } std::vector> swapsi; @@ -177,7 +179,9 @@ class RDKIT_GRAPHMOL_EXPORT SpecialChiralityAtomCompareFunctor { } for (unsigned int ii = 0; ii < swapsi.size() && ii < swapsj.size(); ++ii) { int cmp = swapsi[ii].second - swapsj[ii].second; - if (cmp) return cmp; + if (cmp) { + return cmp; + } } return 0; } @@ -229,7 +233,9 @@ class RDKIT_GRAPHMOL_EXPORT SpecialSymmetryAtomCompareFunctor { ii < dp_atoms[i].bonds.size() && ii < dp_atoms[j].bonds.size(); ++ii) { int cmp = bondholder::compare(dp_atoms[i].bonds[ii], dp_atoms[j].bonds[ii]); - if (cmp) return cmp; + if (cmp) { + return cmp; + } } if (dp_atoms[i].bonds.size() < dp_atoms[j].bonds.size()) { @@ -243,7 +249,9 @@ class RDKIT_GRAPHMOL_EXPORT SpecialSymmetryAtomCompareFunctor { class RDKIT_GRAPHMOL_EXPORT AtomCompareFunctor { unsigned int getAtomRingNbrCode(unsigned int i) const { - if (!dp_atoms[i].hasRingNbr) return 0; + if (!dp_atoms[i].hasRingNbr) { + return 0; + } int *nbrs = dp_atoms[i].nbrIds; unsigned int code = 0; @@ -469,26 +477,29 @@ class RDKIT_GRAPHMOL_EXPORT ChiralAtomCompareFunctor { // always start with the current class: ivi = dp_atoms[i].index; ivj = dp_atoms[j].index; - if (ivi < ivj) + if (ivi < ivj) { return -1; - else if (ivi > ivj) + } else if (ivi > ivj) { return 1; + } // move onto atomic number ivi = dp_atoms[i].atom->getAtomicNum(); ivj = dp_atoms[j].atom->getAtomicNum(); - if (ivi < ivj) + if (ivi < ivj) { return -1; - else if (ivi > ivj) + } else if (ivi > ivj) { return 1; + } // isotopes: ivi = dp_atoms[i].atom->getIsotope(); ivj = dp_atoms[j].atom->getIsotope(); - if (ivi < ivj) + if (ivi < ivj) { return -1; - else if (ivi > ivj) + } else if (ivi > ivj) { return 1; + } // atom stereochem: ivi = 0; @@ -502,10 +513,11 @@ class RDKIT_GRAPHMOL_EXPORT ChiralAtomCompareFunctor { cipCode)) { ivj = cipCode == "R" ? 2 : 1; } - if (ivi < ivj) + if (ivi < ivj) { return -1; - else if (ivi > ivj) + } else if (ivi > ivj) { return 1; + } // bond stereo is taken care of in the neighborhood comparison return 0; @@ -523,7 +535,9 @@ class RDKIT_GRAPHMOL_EXPORT ChiralAtomCompareFunctor { PRECONDITION(dp_mol, "no molecule"); PRECONDITION(i != j, "bad call"); int v = basecomp(i, j); - if (v) return v; + if (v) { + return v; + } if (df_useNbrs) { getAtomNeighborhood(dp_atoms[i].bonds); @@ -537,14 +551,18 @@ class RDKIT_GRAPHMOL_EXPORT ChiralAtomCompareFunctor { ++ii) { int cmp = bondholder::compare( dp_atoms[i].bonds[ii], dp_atoms[j].bonds[ii], ATNUM_CLASS_OFFSET); - if (cmp) return cmp; + if (cmp) { + return cmp; + } } for (unsigned int ii = 0; ii < dp_atoms[i].bonds.size() && ii < dp_atoms[j].bonds.size(); ++ii) { int cmp = bondholder::compare(dp_atoms[i].bonds[ii], dp_atoms[j].bonds[ii]); - if (cmp) return cmp; + if (cmp) { + return cmp; + } } if (dp_atoms[i].bonds.size() < dp_atoms[j].bonds.size()) { return -1; @@ -621,7 +639,9 @@ void RefinePartitions(const ROMol &mol, canon_atom *atoms, CompareFunc compar, // count:"<count[activeset]) ){ diff --git a/Code/ML/InfoTheory/InfoBitRanker.h b/Code/ML/InfoTheory/InfoBitRanker.h index 29b53cc63..18dec031f 100644 --- a/Code/ML/InfoTheory/InfoBitRanker.h +++ b/Code/ML/InfoTheory/InfoBitRanker.h @@ -126,8 +126,12 @@ class RDKIT_INFOTHEORY_EXPORT InfoBitRanker { } ~InfoBitRanker() { - if (dp_topBits) delete[] dp_topBits; - if (dp_maskBits) delete dp_maskBits; + if (dp_topBits) { + delete[] dp_topBits; + } + if (dp_maskBits) { + delete dp_maskBits; + } } /*! \brief Accumulate the votes for all the bits turned on in a bit vector diff --git a/Code/Numerics/Conrec.h b/Code/Numerics/Conrec.h index ef10ca014..cb3caa71e 100644 --- a/Code/Numerics/Conrec.h +++ b/Code/Numerics/Conrec.h @@ -72,9 +72,13 @@ inline void Contour(const double *d, size_t ilb, size_t iub, size_t jlb, temp1 = std::max(d[i * ny + j], d[i * ny + j + 1]); temp2 = std::max(d[(i + 1) * ny + j], d[(i + 1) * ny + j + 1]); dmax = std::max(temp1, temp2); - if (dmax < z[0] || dmin > z[nc - 1]) continue; + if (dmax < z[0] || dmin > z[nc - 1]) { + continue; + } for (k = 0; k < nc; k++) { - if (z[k] < dmin || z[k] > dmax) continue; + if (z[k] < dmin || z[k] > dmax) { + continue; + } for (m = 4; m >= 0; m--) { if (m > 0) { h[m] = d[(i + im[m - 1]) * ny + j + jm[m - 1]] - z[k]; @@ -85,12 +89,13 @@ inline void Contour(const double *d, size_t ilb, size_t iub, size_t jlb, xh[0] = 0.50 * (x[i] + x[i + 1]); yh[0] = 0.50 * (y[j] + y[j + 1]); } - if (h[m] > 0.0) + if (h[m] > 0.0) { sh[m] = 1; - else if (h[m] < 0.0) + } else if (h[m] < 0.0) { sh[m] = -1; - else + } else { sh[m] = 0; + } } /* @@ -120,12 +125,14 @@ inline void Contour(const double *d, size_t ilb, size_t iub, size_t jlb, for (m = 1; m <= 4; m++) { m1 = m; m2 = 0; - if (m != 4) + if (m != 4) { m3 = m + 1; - else + } else { m3 = 1; - if ((case_value = castab[sh[m1] + 1][sh[m2] + 1][sh[m3] + 1]) == 0) + } + if ((case_value = castab[sh[m1] + 1][sh[m2] + 1][sh[m3] + 1]) == 0) { continue; + } switch (case_value) { case 1: /* Line between vertices 1 and 2 */ x1 = xh[m1]; diff --git a/Code/Numerics/Optimizer/BFGSOpt.h b/Code/Numerics/Optimizer/BFGSOpt.h index f682b9d3f..97f671340 100644 --- a/Code/Numerics/Optimizer/BFGSOpt.h +++ b/Code/Numerics/Optimizer/BFGSOpt.h @@ -65,12 +65,16 @@ void linearSearch(unsigned int dim, double *oldPt, double oldVal, double *grad, // get the length of the direction vector: sum = 0.0; - for (unsigned int i = 0; i < dim; i++) sum += dir[i] * dir[i]; + for (unsigned int i = 0; i < dim; i++) { + sum += dir[i] * dir[i]; + } sum = sqrt(sum); // rescale if we're trying to move too far: if (sum > maxStep) { - for (unsigned int i = 0; i < dim; i++) dir[i] *= maxStep / sum; + for (unsigned int i = 0; i < dim; i++) { + dir[i] *= maxStep / sum; + } } // make sure our direction has at least some component along @@ -86,7 +90,9 @@ void linearSearch(unsigned int dim, double *oldPt, double oldVal, double *grad, test = 0.0; for (unsigned int i = 0; i < dim; i++) { double temp = fabs(dir[i]) / std::max(fabs(oldPt[i]), 1.0); - if (temp > test) test = temp; + if (temp > test) { + test = temp; + } } lambdaMin = MOVETOL / test; @@ -242,7 +248,9 @@ int minimize(unsigned int dim, double *pos, double gradTol, xi[i] = newPos[i] - pos[i]; pos[i] = newPos[i]; double temp = fabs(xi[i]) / std::max(fabs(pos[i]), 1.0); - if (temp > test) test = temp; + if (temp > test) { + test = temp; + } dGrad[i] = grad[i]; } // std::cerr<<" iter: "< DoubleVector; template double TanimotoSimilarity(const Vector &v1, const Vector &v2) { double numer = v1.dotProduct(v2); - if (numer == 0.0) return 0.0; + if (numer == 0.0) { + return 0.0; + } double denom = v1.normL2Sq() + v2.normL2Sq() - numer; - if (denom == 0.0) return 0.0; + if (denom == 0.0) { + return 0.0; + } return numer / denom; } } // end of namespace RDNumeric diff --git a/Code/PgSQL/rdkit/adapter.cpp b/Code/PgSQL/rdkit/adapter.cpp index 36e062b08..51d9ba52c 100644 --- a/Code/PgSQL/rdkit/adapter.cpp +++ b/Code/PgSQL/rdkit/adapter.cpp @@ -985,8 +985,12 @@ extern "C" bytea *makeLowSparseFingerPrint(CSfp data, int numInts) { #endif } - if (s[n].low == 0 || s[n].low > iterV) s[n].low = iterV; - if (s[n].high < iterV) s[n].high = iterV; + if (s[n].low == 0 || s[n].low > iterV) { + s[n].low = iterV; + } + if (s[n].high < iterV) { + s[n].high = iterV; + } } return res; @@ -1015,8 +1019,9 @@ extern "C" void countOverlapValues(bytea *sign, CSfp data, int numBits, } else { /* Assume, sign has only true bits */ for (iter = v->getNonzeroElements().begin(); - iter != v->getNonzeroElements().end(); iter++) + iter != v->getNonzeroElements().end(); iter++) { *sum += iter->second; + } *overlapSum = *sum; *overlapN = v->getNonzeroElements().size(); @@ -1050,9 +1055,10 @@ extern "C" void countLowOverlapValues(bytea *sign, CSfp data, int numInts, for (n = 0; n < numInts; n++) { *keySum += s[n].low; - if (s[n].low != s[n].high) - *keySum += s[n].high; /* there is at least two key mapped into current - backet */ + if (s[n].low != s[n].high) { + *keySum += s[n].high; + } /* there is at least two key mapped into current + backet */ } Assert(*overlapUp <= *keySum); @@ -2151,9 +2157,10 @@ extern "C" char *findMCSsmiles(char *smiles, char *params) { try { MCSResult res = RDKit::findMCS(molecules, &p); mcs = res.SmartsString; - if (!res.isCompleted()) + if (!res.isCompleted()) { ereport(WARNING, (errcode(ERRCODE_WARNING), errmsg("findMCS timed out, result is not maximal"))); + } } catch (...) { ereport(WARNING, (errcode(ERRCODE_WARNING), errmsg("findMCS: failed"))); mcs.clear(); @@ -2206,9 +2213,10 @@ extern "C" char *findMCS(void *vmols, char *params) { try { MCSResult res = RDKit::findMCS(*molecules, &p); - if (!res.isCompleted()) + if (!res.isCompleted()) { ereport(WARNING, (errcode(ERRCODE_WARNING), errmsg("findMCS timed out, result is not maximal"))); + } mcs = res.SmartsString; } catch (...) { ereport(WARNING, (errcode(ERRCODE_WARNING), errmsg("findMCS: failed"))); diff --git a/Code/Query/AndQuery.h b/Code/Query/AndQuery.h index 3f07a1d70..89efc438b 100644 --- a/Code/Query/AndQuery.h +++ b/Code/Query/AndQuery.h @@ -34,7 +34,9 @@ class RDKIT_QUERY_EXPORT AndQuery break; } } - if (this->getNegation()) res = !res; + if (this->getNegation()) { + res = !res; + } return res; } Query *copy() diff --git a/Code/Query/EqualityQuery.h b/Code/Query/EqualityQuery.h index f31aae65a..084eb5454 100644 --- a/Code/Query/EqualityQuery.h +++ b/Code/Query/EqualityQuery.h @@ -83,10 +83,11 @@ class RDKIT_QUERY_EXPORT EqualityQuery std::ostringstream res; res << this->getDescription(); res << " " << this->d_val; - if (this->getNegation()) + if (this->getNegation()) { res << " != "; - else + } else { res << " = "; + } res << "val"; return res.str(); } diff --git a/Code/Query/GreaterEqualQuery.h b/Code/Query/GreaterEqualQuery.h index e15a4e59e..de7f154aa 100644 --- a/Code/Query/GreaterEqualQuery.h +++ b/Code/Query/GreaterEqualQuery.h @@ -39,15 +39,17 @@ class RDKIT_QUERY_EXPORT GreaterEqualQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) >= 0) { - if (this->getNegation()) + if (this->getNegation()) { return false; - else + } else { return true; + } } else { - if (this->getNegation()) + if (this->getNegation()) { return true; - else + } else { return false; + } } } Query *copy() @@ -68,10 +70,11 @@ class RDKIT_QUERY_EXPORT GreaterEqualQuery std::ostringstream res; res << this->getDescription(); res << " " << this->d_val; - if (this->getNegation()) + if (this->getNegation()) { res << " ! >= "; - else + } else { res << " >= "; + } return res.str(); } }; diff --git a/Code/Query/GreaterQuery.h b/Code/Query/GreaterQuery.h index d2410579d..cbf6df2b0 100644 --- a/Code/Query/GreaterQuery.h +++ b/Code/Query/GreaterQuery.h @@ -39,15 +39,17 @@ class RDKIT_QUERY_EXPORT GreaterQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) > 0) { - if (this->getNegation()) + if (this->getNegation()) { return false; - else + } else { return true; + } } else { - if (this->getNegation()) + if (this->getNegation()) { return true; - else + } else { return false; + } } } @@ -68,10 +70,11 @@ class RDKIT_QUERY_EXPORT GreaterQuery std::ostringstream res; res << this->getDescription(); res << " " << this->d_val; - if (this->getNegation()) + if (this->getNegation()) { res << " ! > "; - else + } else { res << " > "; + } return res.str(); } }; diff --git a/Code/Query/LessEqualQuery.h b/Code/Query/LessEqualQuery.h index 4f47f79c6..f27e737c1 100644 --- a/Code/Query/LessEqualQuery.h +++ b/Code/Query/LessEqualQuery.h @@ -39,15 +39,17 @@ class RDKIT_QUERY_EXPORT LessEqualQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) <= 0) { - if (this->getNegation()) + if (this->getNegation()) { return false; - else + } else { return true; + } } else { - if (this->getNegation()) + if (this->getNegation()) { return true; - else + } else { return false; + } } } @@ -69,10 +71,11 @@ class RDKIT_QUERY_EXPORT LessEqualQuery std::ostringstream res; res << this->getDescription(); res << " " << this->d_val; - if (this->getNegation()) + if (this->getNegation()) { res << " ! <= "; - else + } else { res << " <= "; + } return res.str(); } }; diff --git a/Code/Query/LessQuery.h b/Code/Query/LessQuery.h index 066f491f7..581633953 100644 --- a/Code/Query/LessQuery.h +++ b/Code/Query/LessQuery.h @@ -39,15 +39,17 @@ class RDKIT_QUERY_EXPORT LessQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) < 0) { - if (this->getNegation()) + if (this->getNegation()) { return false; - else + } else { return true; + } } else { - if (this->getNegation()) + if (this->getNegation()) { return true; - else + } else { return false; + } } } @@ -68,10 +70,11 @@ class RDKIT_QUERY_EXPORT LessQuery std::ostringstream res; res << this->getDescription(); res << " " << this->d_val; - if (this->getNegation()) + if (this->getNegation()) { res << " ! < "; - else + } else { res << " < "; + } return res.str(); } }; diff --git a/Code/Query/OrQuery.h b/Code/Query/OrQuery.h index 0fce7e667..c35d649c0 100644 --- a/Code/Query/OrQuery.h +++ b/Code/Query/OrQuery.h @@ -33,7 +33,9 @@ class RDKIT_QUERY_EXPORT OrQuery break; } } - if (this->getNegation()) res = !res; + if (this->getNegation()) { + res = !res; + } return res; } diff --git a/Code/Query/Query.h b/Code/Query/Query.h index 12fdf5fb6..0c6ce1721 100644 --- a/Code/Query/Query.h +++ b/Code/Query/Query.h @@ -70,10 +70,11 @@ class RDKIT_QUERY_EXPORT Query { const std::string &getDescription() const { return this->d_description; } //! returns a fuller text description virtual std::string getFullDescription() const { - if (!getNegation()) + if (!getNegation()) { return getDescription(); - else + } else { return "not " + getDescription(); + } } //! sets our type label @@ -109,15 +110,17 @@ class RDKIT_QUERY_EXPORT Query { virtual bool Match(const DataFuncArgType arg) const { MatchFuncArgType mfArg = TypeConvert(arg, Int2Type()); bool tRes; - if (this->d_matchFunc) + if (this->d_matchFunc) { tRes = this->d_matchFunc(mfArg); - else + } else { tRes = static_cast(mfArg); + } - if (this->getNegation()) + if (this->getNegation()) { return !tRes; - else + } else { return tRes; + } } //! returns a copy of this Query diff --git a/Code/Query/RangeQuery.h b/Code/Query/RangeQuery.h index 933d50040..69c9ec0aa 100644 --- a/Code/Query/RangeQuery.h +++ b/Code/Query/RangeQuery.h @@ -64,20 +64,23 @@ class RDKIT_QUERY_EXPORT RangeQuery int lCmp = queryCmp(this->d_lower, mfArg, this->d_tol); int uCmp = queryCmp(this->d_upper, mfArg, this->d_tol); bool lowerRes, upperRes; - if (this->df_lowerOpen) + if (this->df_lowerOpen) { lowerRes = lCmp < 0; - else + } else { lowerRes = lCmp <= 0; - if (this->df_upperOpen) + } + if (this->df_upperOpen) { upperRes = uCmp > 0; - else + } else { upperRes = uCmp >= 0; + } bool tempR = !(lowerRes && upperRes); - if (this->getNegation()) + if (this->getNegation()) { return tempR; - else + } else { return !tempR; + } } Query *copy() @@ -98,7 +101,9 @@ class RDKIT_QUERY_EXPORT RangeQuery std::string getFullDescription() const override { std::ostringstream res; res << this->getDescription(); - if (this->getNegation()) res << " ! "; + if (this->getNegation()) { + res << " ! "; + } res << " " << this->d_lower << " val " << this->d_upper; return res.str(); } diff --git a/Code/Query/SetQuery.h b/Code/Query/SetQuery.h index c434ec0a6..5a2b00464 100644 --- a/Code/Query/SetQuery.h +++ b/Code/Query/SetQuery.h @@ -31,7 +31,9 @@ class RDKIT_QUERY_EXPORT SetQuery //! insert an entry into our \c set void insert(const MatchFuncArgType what) { - if (d_set.find(what) == this->d_set.end()) this->d_set.insert(what); + if (d_set.find(what) == this->d_set.end()) { + this->d_set.insert(what); + } } //! clears our \c set @@ -67,10 +69,11 @@ class RDKIT_QUERY_EXPORT SetQuery std::string getFullDescription() const override { std::ostringstream res; res << this->getDescription() << " val"; - if (this->getNegation()) + if (this->getNegation()) { res << " not in "; - else + } else { res << " in ("; + } std::copy(d_set.begin(), d_set.end(), std::ostream_iterator(res, ", ")); res << ")"; diff --git a/Code/Query/XOrQuery.h b/Code/Query/XOrQuery.h index 52759eac9..41c8ed289 100644 --- a/Code/Query/XOrQuery.h +++ b/Code/Query/XOrQuery.h @@ -38,7 +38,9 @@ class RDKIT_QUERY_EXPORT XOrQuery } } } - if (this->getNegation()) res = !res; + if (this->getNegation()) { + res = !res; + } return res; } diff --git a/Code/RDBoost/list_indexing_suite.hpp b/Code/RDBoost/list_indexing_suite.hpp index 7d038ae50..b20963e80 100644 --- a/Code/RDBoost/list_indexing_suite.hpp +++ b/Code/RDBoost/list_indexing_suite.hpp @@ -140,7 +140,9 @@ class list_indexing_suite extract i(i_); if (i.check()) { long index = i(); - if (index < 0) index += DerivedPolicies::size(container); + if (index < 0) { + index += DerivedPolicies::size(container); + } if (index >= long(container.size()) || index < 0) { PyErr_SetString(PyExc_IndexError, "Index out of range"); throw_error_already_set(); diff --git a/Code/RDBoost/python_streambuf.h b/Code/RDBoost/python_streambuf.h index 2eba9654f..763c1dfc2 100644 --- a/Code/RDBoost/python_streambuf.h +++ b/Code/RDBoost/python_streambuf.h @@ -215,16 +215,18 @@ class streambuf : public std::basic_streambuf { switch (mode) { case 's': /// yeah, is redundant, but it is somehow natural to do "s" case 't': - if (!df_isTextMode) + if (!df_isTextMode) { throw ValueErrorException( "Need a text mode file object like StringIO or a file opened " "with mode 't'"); + } break; case 'b': - if (df_isTextMode) + if (df_isTextMode) { throw ValueErrorException( "Need a binary mode file object like BytesIO or a file opened " "with mode 'b'"); + } break; default: throw std::invalid_argument("bad mode character"); @@ -233,7 +235,9 @@ class streambuf : public std::basic_streambuf { /// Mundane destructor freeing the allocated resources ~streambuf() override { - if (write_buffer) delete[] write_buffer; + if (write_buffer) { + delete[] write_buffer; + } } /// C.f. C++ standard section 27.5.2.4.3 @@ -243,7 +247,9 @@ class streambuf : public std::basic_streambuf { std::streamsize showmanyc() override { int_type const failure = traits_type::eof(); int_type status = underflow(); - if (status == failure) return -1; + if (status == failure) { + return -1; + } return egptr() - gptr(); } @@ -268,7 +274,9 @@ class streambuf : public std::basic_streambuf { pos_of_read_buffer_end_in_py_file += n_read; setg(read_buffer_data, read_buffer_data, read_buffer_data + n_read); // ^^^27.5.2.3.1 (4) - if (n_read == 0) return failure; + if (n_read == 0) { + return failure; + } return traits_type::to_int_type(read_buffer_data[0]); } @@ -335,10 +343,16 @@ class streambuf : public std::basic_streambuf { if (farthest_pptr && farthest_pptr > pbase()) { off_type delta = pptr() - farthest_pptr; int_type status = overflow(); - if (traits_type::eq_int_type(status, traits_type::eof())) result = -1; - if (py_seek != bp::object()) py_seek(delta, 1); + if (traits_type::eq_int_type(status, traits_type::eof())) { + result = -1; + } + if (py_seek != bp::object()) { + py_seek(delta, 1); + } } else if (gptr() && gptr() < egptr()) { - if (py_seek != bp::object()) py_seek(gptr() - egptr(), 1); + if (py_seek != bp::object()) { + py_seek(gptr() - egptr(), 1); + } } return result; } @@ -393,16 +407,21 @@ class streambuf : public std::basic_streambuf { seekoff_without_calling_python(off, way, which); if (!result) { // we need to call Python - if (which == std::ios_base::out) overflow(); + if (which == std::ios_base::out) { + overflow(); + } if (way == std::ios_base::cur) { - if (which == std::ios_base::in) + if (which == std::ios_base::in) { off -= egptr() - gptr(); - else if (which == std::ios_base::out) + } else if (which == std::ios_base::out) { off += pptr() - pbase(); + } } py_seek(off, whence); result = off_type(bp::extract(py_tell())); - if (which == std::ios_base::in) underflow(); + if (which == std::ios_base::in) { + underflow(); + } } return *result; } @@ -475,13 +494,16 @@ class streambuf : public std::basic_streambuf { } // if the sought position is not in the buffer, give up - if (buf_sought < buf_begin || buf_sought >= upper_bound) return failure; + if (buf_sought < buf_begin || buf_sought >= upper_bound) { + return failure; + } // we are in wonderland - if (which == std::ios_base::in) + if (which == std::ios_base::in) { gbump(buf_sought - buf_cur); - else if (which == std::ios_base::out) + } else if (which == std::ios_base::out) { pbump(buf_sought - buf_cur); + } return pos_of_buffer_end_in_py_file + (buf_sought - buf_end); } @@ -509,7 +531,9 @@ class streambuf : public std::basic_streambuf { } ~ostream() override { - if (this->good()) this->flush(); + if (this->good()) { + this->flush(); + } } }; }; diff --git a/Code/RDGeneral/Dict.h b/Code/RDGeneral/Dict.h index 094d29baa..4fdeb81f6 100644 --- a/Code/RDGeneral/Dict.h +++ b/Code/RDGeneral/Dict.h @@ -70,7 +70,9 @@ class RDKIT_RDGENERAL_EXPORT Dict { if (!preserveExisting) { *this = other; } else { - if (other._hasNonPodData) _hasNonPodData = true; + if (other._hasNonPodData) { + _hasNonPodData = true; + } for (size_t i = 0; i < other._data.size(); ++i) { const Pair &pair = other._data[i]; Pair *target = nullptr; @@ -144,7 +146,9 @@ class RDKIT_RDGENERAL_EXPORT Dict { //! key. bool hasVal(const std::string &what) const { for (const auto &data : _data) { - if (data.key == what) return true; + if (data.key == what) { + return true; + } } return false; } diff --git a/Code/RDGeneral/RDValue-taggedunion.h b/Code/RDGeneral/RDValue-taggedunion.h index 7ca8d59e3..39868d265 100644 --- a/Code/RDGeneral/RDValue-taggedunion.h +++ b/Code/RDGeneral/RDValue-taggedunion.h @@ -304,8 +304,9 @@ struct RDValue { // copy act's like a move for better value semantics. // Containers may need to copy though. inline void copy_rdvalue(RDValue &dest, const RDValue &src) { - if (&dest == &src) // don't copy over yourself + if (&dest == &src) { // don't copy over yourself return; + } dest.destroy(); dest.type = src.type; switch (src.type) { @@ -349,7 +350,9 @@ template inline bool rdvalue_is(RDValue_cast_t v) { const short tag = RDTypeTag::GetTag::type>(); - if (v.getTag() == tag) return true; + if (v.getTag() == tag) { + return true; + } // If we are an Any tag, check the any type info if (v.getTag() == RDTypeTag::AnyTag) { @@ -389,45 +392,67 @@ inline T rdvalue_cast(RDValue_cast_t v) { // POD casts template <> inline double rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return v.value.d; - if (rdvalue_is(v)) return v.value.f; + if (rdvalue_is(v)) { + return v.value.d; + } + if (rdvalue_is(v)) { + return v.value.f; + } throw boost::bad_any_cast(); } template <> inline float rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return v.value.f; - if (rdvalue_is(v)) return boost::numeric_cast(v.value.d); + if (rdvalue_is(v)) { + return v.value.f; + } + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.d); + } throw boost::bad_any_cast(); } template <> inline int rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return v.value.i; - if (rdvalue_is(v)) return boost::numeric_cast(v.value.u); + if (rdvalue_is(v)) { + return v.value.i; + } + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.u); + } throw boost::bad_any_cast(); } template <> inline std::int8_t rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return boost::numeric_cast(v.value.i); - if (rdvalue_is(v)) + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.i); + } + if (rdvalue_is(v)) { return boost::numeric_cast(v.value.u); + } throw boost::bad_any_cast(); } template <> inline std::int16_t rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return boost::numeric_cast(v.value.i); - if (rdvalue_is(v)) + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.i); + } + if (rdvalue_is(v)) { return boost::numeric_cast(v.value.u); + } throw boost::bad_any_cast(); } template <> inline std::int64_t rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return static_cast(v.value.i); - if (rdvalue_is(v)) return static_cast(v.value.u); + if (rdvalue_is(v)) { + return static_cast(v.value.i); + } + if (rdvalue_is(v)) { + return static_cast(v.value.u); + } if (rdvalue_is(v)) { return boost::any_cast(*v.ptrCast()); } @@ -436,31 +461,45 @@ inline std::int64_t rdvalue_cast(RDValue_cast_t v) { template <> inline unsigned int rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return v.value.u; - if (rdvalue_is(v)) return boost::numeric_cast(v.value.i); + if (rdvalue_is(v)) { + return v.value.u; + } + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.i); + } throw boost::bad_any_cast(); } template <> inline std::uint8_t rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return boost::numeric_cast(v.value.i); - if (rdvalue_is(v)) + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.i); + } + if (rdvalue_is(v)) { return boost::numeric_cast(v.value.u); + } throw boost::bad_any_cast(); } template <> inline std::uint16_t rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return boost::numeric_cast(v.value.i); - if (rdvalue_is(v)) + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.i); + } + if (rdvalue_is(v)) { return boost::numeric_cast(v.value.u); + } throw boost::bad_any_cast(); } template <> inline std::uint64_t rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return static_cast(v.value.u); - if (rdvalue_is(v)) return boost::numeric_cast(v.value.i); + if (rdvalue_is(v)) { + return static_cast(v.value.u); + } + if (rdvalue_is(v)) { + return boost::numeric_cast(v.value.i); + } if (rdvalue_is(v)) { return boost::any_cast(*v.ptrCast()); } @@ -469,7 +508,9 @@ inline std::uint64_t rdvalue_cast(RDValue_cast_t v) { template <> inline bool rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return v.value.b; + if (rdvalue_is(v)) { + return v.value.b; + } throw boost::bad_any_cast(); } diff --git a/Code/RDGeneral/RDValue.h b/Code/RDGeneral/RDValue.h index b2310ca23..3b1cd0f24 100644 --- a/Code/RDGeneral/RDValue.h +++ b/Code/RDGeneral/RDValue.h @@ -44,88 +44,104 @@ namespace RDKit { // string casts template <> inline std::string rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return *v.ptrCast(); + if (rdvalue_is(v)) { + return *v.ptrCast(); + } throw boost::bad_any_cast(); } template <> inline std::string &rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) return *v.ptrCast(); + if (rdvalue_is(v)) { + return *v.ptrCast(); + } throw boost::bad_any_cast(); } // Special Vecor Casts template <> inline std::vector rdvalue_cast>(RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector &rdvalue_cast &>( RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector rdvalue_cast>(RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector &rdvalue_cast &>( RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector rdvalue_cast>( RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector &rdvalue_cast &>( RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector rdvalue_cast>(RDValue_cast_t v) { - if (rdvalue_is>(v)) return *v.ptrCast>(); + if (rdvalue_is>(v)) { + return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector &rdvalue_cast &>(RDValue_cast_t v) { - if (rdvalue_is>(v)) return *v.ptrCast>(); + if (rdvalue_is>(v)) { + return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector rdvalue_cast>( RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } template <> inline std::vector &rdvalue_cast &>( RDValue_cast_t v) { - if (rdvalue_is>(v)) + if (rdvalue_is>(v)) { return *v.ptrCast>(); + } throw boost::bad_any_cast(); } diff --git a/Code/RDGeneral/Ranking.h b/Code/RDGeneral/Ranking.h index fe2bcaad7..f55244184 100644 --- a/Code/RDGeneral/Ranking.h +++ b/Code/RDGeneral/Ranking.h @@ -67,7 +67,9 @@ void rankVect(const std::vector &vect, T2 &res) { unsigned int nEntries = rdcast(vect.size()); std::vector indices(nEntries); - for (unsigned int i = 0; i < nEntries; ++i) indices[i] = i; + for (unsigned int i = 0; i < nEntries; ++i) { + indices[i] = i; + } std::sort(indices.begin(), indices.end(), argless>(vect)); int currRank = 0; diff --git a/Code/RDGeneral/StreamOps.h b/Code/RDGeneral/StreamOps.h index 8b08f0f59..d8d23e91e 100644 --- a/Code/RDGeneral/StreamOps.h +++ b/Code/RDGeneral/StreamOps.h @@ -42,7 +42,9 @@ enum EEndian { // parameter (could sizeof be used?). template inline T SwapBytes(T value) { - if (size < 2) return value; + if (size < 2) { + return value; + } union { T value; @@ -71,13 +73,17 @@ inline T EndianSwapBytes(T value) { // A : La donnée à swapper à une taille de 2, 4 ou 8 octets BOOST_STATIC_ASSERT(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8); - if (sizeof(T) == 1) return value; + if (sizeof(T) == 1) { + return value; + } // A : La donnée à swapper est d'un type arithmetic // BOOST_STATIC_ASSERT(boost::is_arithmetic::value); // Si from et to sont du même type on ne swap pas. - if (from == to) return value; + if (from == to) { + return value; + } return SwapBytes(value); } @@ -266,7 +272,9 @@ inline void streamWrite(std::ostream &ss, const std::string &what) { template void streamWriteVec(std::ostream &ss, const T &val) { streamWrite(ss, static_cast(val.size())); - for (size_t i = 0; i < val.size(); ++i) streamWrite(ss, val[i]); + for (size_t i = 0; i < val.size(); ++i) { + streamWrite(ss, val[i]); + } } //! does a binary read of an object from a stream @@ -309,7 +317,9 @@ void streamReadVec(std::istream &ss, T &val) { streamRead(ss, size); val.resize(boost::numeric_cast(size)); - for (size_t i = 0; i < size; ++i) streamRead(ss, val[i]); + for (size_t i = 0; i < size; ++i) { + streamRead(ss, val[i]); + } } inline void streamReadStringVec(std::istream &ss, std::vector &val, @@ -318,7 +328,9 @@ inline void streamReadStringVec(std::istream &ss, std::vector &val, streamRead(ss, size); val.resize(size); - for (size_t i = 0; i < size; ++i) streamRead(ss, val[i], version); + for (size_t i = 0; i < size; ++i) { + streamRead(ss, val[i], version); + } } //! grabs the next line from an instream and returns it. diff --git a/Code/RDGeneral/hanoiSort.h b/Code/RDGeneral/hanoiSort.h index cc78bf10a..e9d310d96 100644 --- a/Code/RDGeneral/hanoiSort.h +++ b/Code/RDGeneral/hanoiSort.h @@ -73,16 +73,18 @@ bool hanoi(int *base, int nel, int *temp, int *count, int *changed, if (hanoi(b1, n1, t1, count, changed, compar)) { if (hanoi(b2, n2, t2, count, changed, compar)) { s2 = t2; - } else + } else { s2 = b2; + } result = false; ptr = base; s1 = t1; } else { if (hanoi(b2, n2, t2, count, changed, compar)) { s2 = t2; - } else + } else { s2 = b2; + } result = true; ptr = temp; s1 = b1; @@ -103,7 +105,9 @@ bool hanoi(int *base, int nel, int *temp, int *count, int *changed, ptr += len1; n1 -= len1; if (n1 == 0) { - if (ptr != s2) memmove(ptr, s2, n2 * sizeof(int)); + if (ptr != s2) { + memmove(ptr, s2, n2 * sizeof(int)); + } return result; } s1 += len1; @@ -122,7 +126,9 @@ bool hanoi(int *base, int nel, int *temp, int *count, int *changed, ptr += len1; n1 -= len1; if (n1 == 0) { - if (ptr != s2) memmove(ptr, s2, n2 * sizeof(int)); + if (ptr != s2) { + memmove(ptr, s2, n2 * sizeof(int)); + } return result; } s1 += len1; @@ -147,8 +153,9 @@ void hanoisort(int *base, int nel, int *count, int *changed, assert(base); int *temp = (int *)malloc(nel * sizeof(int)); assert(temp); - if (hanoi(base, nel, temp, count, changed, compar)) + if (hanoi(base, nel, temp, count, changed, compar)) { memmove(base, temp, nel * sizeof(int)); + } free(temp); } } // namespace RDKit diff --git a/Code/RDGeneral/utils.h b/Code/RDGeneral/utils.h index 3adedca9c..813d0f247 100644 --- a/Code/RDGeneral/utils.h +++ b/Code/RDGeneral/utils.h @@ -86,10 +86,11 @@ RDKIT_RDGENERAL_EXPORT std::string augmentTagName(const std::string &tag); template inline double int_pow(double x) { double half = int_pow(x); - if (n % 2 == 0) // even + if (n % 2 == 0) { // even return half * half; - else + } else { return half * half * x; + } } template <> diff --git a/Code/SimDivPickers/LeaderPicker.h b/Code/SimDivPickers/LeaderPicker.h index 36e9df627..9329d2b49 100644 --- a/Code/SimDivPickers/LeaderPicker.h +++ b/Code/SimDivPickers/LeaderPicker.h @@ -99,9 +99,12 @@ class LeaderPicker : public DistPicker { unsigned int pickSize, const RDKit::INT_VECT &firstPicks, double threshold, int nthreads) const { CHECK_INVARIANT(distMat, "Invalid Distance Matrix"); - if (!poolSize) throw ValueErrorException("empty pool to pick from"); - if (poolSize < pickSize) + if (!poolSize) { + throw ValueErrorException("empty pool to pick from"); + } + if (poolSize < pickSize) { throw ValueErrorException("pickSize cannot be larger than the poolSize"); + } distmatFunctor functor(distMat); return this->lazyPick(functor, poolSize, pickSize, firstPicks, threshold, nthreads); @@ -160,7 +163,9 @@ struct LeaderPickerState { LeaderPickerState(unsigned int count, int nt) { v.resize(count); - for (unsigned int i = 0; i < count; i++) v[i] = i; + for (unsigned int i = 0; i < count; i++) { + v[i] = i; + } // InitializeBlocks unsigned int bcount; @@ -170,7 +175,9 @@ struct LeaderPickerState { bcount = (count + (bsize - 1)) / bsize; unsigned int tasks = (bcount + 1) / 2; // limit number of threads to available work - if (nt > (int)tasks) nt = tasks; + if (nt > (int)tasks) { + nt = tasks; + } } else { bsize = 32768; bcount = (count + (bsize - 1)) / bsize; @@ -219,16 +226,18 @@ struct LeaderPickerState { pthread_create(&threads[i].tid, NULL, LeaderPickerWork, (void *)&threads[i]); } - } else + } else { nthreads = 1; + } } ~LeaderPickerState() { if (nthreads > 1) { thread_op = 1; pthread_barrier_wait(&wait); - for (unsigned int i = 0; i < nthreads; i++) + for (unsigned int i = 0; i < nthreads; i++) { pthread_join(threads[i].tid, 0); + } pthread_barrier_destroy(&wait); pthread_barrier_destroy(&done); } @@ -236,9 +245,13 @@ struct LeaderPickerState { bool empty() { while (head_block) { - if (head_block->len) return false; + if (head_block->len) { + return false; + } unsigned int next_tick = head_block->next[tick]; - if (!next_tick) return true; + if (!next_tick) { + return true; + } head_block = &blocks[next_tick]; } return true; @@ -247,7 +260,9 @@ struct LeaderPickerState { unsigned int compact(int *dst, int *src, unsigned int len) { unsigned int count = 0; for (unsigned int i = 0; i < len; i++) { - if ((*func)(query, src[i]) > threshold) dst[count++] = src[i]; + if ((*func)(query, src[i]) > threshold) { + dst[count++] = src[i]; + } } return count; } @@ -273,16 +288,19 @@ struct LeaderPickerState { if (next->len) { list->next[tock] = next_tick; next->next[tock] = next_next_tick; - } else + } else { list->next[tock] = next_next_tick; + } } cycle = nthreads - 1; - } else + } else { cycle--; + } if (next_next_tick) { list = &blocks[next_next_tick]; - } else + } else { break; + } } else { if (cycle == 0) { list->len = compact(list->ptr, list->ptr, list->len); @@ -299,8 +317,9 @@ struct LeaderPickerState { thread_op = 0; pthread_barrier_wait(&wait); pthread_barrier_wait(&done); - } else + } else { compact_job(0); + } tick ^= 1; } @@ -319,7 +338,9 @@ void *LeaderPickerWork(void *arg) { for (;;) { pthread_barrier_wait(&stat->wait); - if (stat->thread_op) return (void *)0; + if (stat->thread_op) { + return (void *)0; + } stat->compact_job(thread->id); pthread_barrier_wait(&stat->done); } @@ -337,7 +358,9 @@ struct LeaderPickerState { LeaderPickerState(unsigned int count, int) : left(count), threshold(0.0), query(0), func(nullptr) { v.resize(count); - for (unsigned int i = 0; i < count; i++) v[i] = i; + for (unsigned int i = 0; i < count; i++) { + v[i] = i; + } } bool empty() { return left == 0; } @@ -347,7 +370,9 @@ struct LeaderPickerState { for (unsigned int i = 0; i < len; i++) { double ld = (*func)(query, src[i]); // std::cerr << query << "-" << src[i] << " " << ld << std::endl; - if (ld > threshold) dst[count++] = src[i]; + if (ld > threshold) { + dst[count++] = src[i]; + } } return count; } @@ -372,12 +397,17 @@ RDKit::INT_VECT LeaderPicker::lazyPick(T &func, unsigned int poolSize, unsigned int pickSize, const RDKit::INT_VECT &firstPicks, double threshold, int nthreads) const { - if (!poolSize) throw ValueErrorException("empty pool to pick from"); + if (!poolSize) { + throw ValueErrorException("empty pool to pick from"); + } - if (poolSize < pickSize) + if (poolSize < pickSize) { throw ValueErrorException("pickSize cannot be larger than the poolSize"); + } - if (!pickSize) pickSize = poolSize; + if (!pickSize) { + pickSize = poolSize; + } RDKit::INT_VECT picks; nthreads = RDKit::getNumThreadsToUse(nthreads); diff --git a/Code/SimDivPickers/MaxMinPicker.h b/Code/SimDivPickers/MaxMinPicker.h index 02c623f7b..407dcda4e 100644 --- a/Code/SimDivPickers/MaxMinPicker.h +++ b/Code/SimDivPickers/MaxMinPicker.h @@ -114,9 +114,12 @@ class RDKIT_SIMDIVPICKERS_EXPORT MaxMinPicker : public DistPicker { unsigned int pickSize, RDKit::INT_VECT firstPicks, int seed = -1) const { CHECK_INVARIANT(distMat, "Invalid Distance Matrix"); - if (!poolSize) throw ValueErrorException("empty pool to pick from"); - if (poolSize < pickSize) + if (!poolSize) { + throw ValueErrorException("empty pool to pick from"); + } + if (poolSize < pickSize) { throw ValueErrorException("pickSize cannot be larger than the poolSize"); + } distmatFunctor functor(distMat); return this->lazyPick(functor, poolSize, pickSize, firstPicks, seed); } @@ -142,10 +145,13 @@ RDKit::INT_VECT MaxMinPicker::lazyPick(T &func, unsigned int poolSize, unsigned int pickSize, const RDKit::INT_VECT &firstPicks, int seed, double &threshold) const { - if (!poolSize) throw ValueErrorException("empty pool to pick from"); + if (!poolSize) { + throw ValueErrorException("empty pool to pick from"); + } - if (poolSize < pickSize) + if (poolSize < pickSize) { throw ValueErrorException("pickSize cannot be larger than the poolSize"); + } RDKit::INT_VECT picks; @@ -201,11 +207,12 @@ RDKit::INT_VECT MaxMinPicker::lazyPick(T &func, unsigned int poolSize, unsigned int pool_list = 0; unsigned int *prev = &pool_list; // enter the pool into a list so that we can pick out of it easily - for (unsigned int i = 0; i < poolSize; i++) + for (unsigned int i = 0; i < poolSize; i++) { if (pinfo[i].picks == 0) { *prev = i; prev = &pinfo[i].next; } + } *prev = 0; unsigned int poolIdx; @@ -240,7 +247,9 @@ RDKit::INT_VECT MaxMinPicker::lazyPick(T &func, unsigned int poolSize, pi++; if (dist <= minTOi) { minTOi = dist; - if (minTOi <= maxOFmin) break; + if (minTOi <= maxOFmin) { + break; + } } } pinfo[poolIdx].dist_bound = minTOi; @@ -255,7 +264,9 @@ RDKit::INT_VECT MaxMinPicker::lazyPick(T &func, unsigned int poolSize, } while (*prev != 0); // if the current distance is closer then threshold, we're done - if (maxOFmin <= threshold && threshold >= 0.0) break; + if (maxOFmin <= threshold && threshold >= 0.0) { + break; + } tmpThreshold = maxOFmin; // now add the new pick to picks and remove it from the pool *pick_prev = pinfo[pick].next; diff --git a/External/GA/ga/LinkedPopLinearSel.h b/External/GA/ga/LinkedPopLinearSel.h index 1aeb8da98..b2a0a7649 100644 --- a/External/GA/ga/LinkedPopLinearSel.h +++ b/External/GA/ga/LinkedPopLinearSel.h @@ -200,7 +200,9 @@ LinkedPopLinearSel::selectParent() { double sum = SELECT_START, currentFitness = SELECT_START; auto iterator = population.begin(); for (size_t i = 0; i < popsize; i++) { - if (val <= sum) return iterator->second; + if (val <= sum) { + return iterator->second; + } currentFitness += scaledFitnessStep; sum += currentFitness; ++iterator; @@ -436,7 +438,9 @@ LinkedPopLinearSel::findExactMatch( for (auto iterator = iterators.first; iterator != iterators.second; ++iterator) { const std::shared_ptr& other = iterator->second; - if (c.equals(*other)) return iterator; + if (c.equals(*other)) { + return iterator; + } } return population.end(); } diff --git a/External/GA/ga/StringChromosome.cpp b/External/GA/ga/StringChromosome.cpp index 39ae4ce62..31d9ee9e5 100644 --- a/External/GA/ga/StringChromosome.cpp +++ b/External/GA/ga/StringChromosome.cpp @@ -26,7 +26,9 @@ int StringChromosome::decodeToInt( int mask = 1, result = 0; bool *ptr = string.get() + start; for (int i = 0; i < nBits; i++, mask <<= 1) { - if (*ptr++ == true) result |= mask; + if (*ptr++ == true) { + result |= mask; + } } return result; } @@ -49,13 +51,13 @@ void StringChromosome::fullMixing( int *p2 = parent2.getString(); for (int i = 0; i < length; i++, c1++, c2++, p1++, p2++) { - if (*p1 == -1 && *p2 == -1) + if (*p1 == -1 && *p2 == -1) { *c1 = *c2 = -1; - else if (*p1 != -1 && *p2 == -1) + } else if (*p1 != -1 && *p2 == -1) { *c1 = *c2 = *p1; - else if (*p1 == -1 && *p2 != -1) + } else if (*p1 == -1 && *p2 != -1) { *c1 = *c2 = *p2; - else { + } else { *c1 = *p1; *c2 = *p2; } @@ -78,7 +80,9 @@ void StringChromosome::fullMixingAndCrossove int site = getRng().randomInt(0, length); bool switchFlag = false; - if (getChromosomePolicy().isAllowSwitch()) switchFlag = getRng().randomBoolean(); + if (getChromosomePolicy().isAllowSwitch()) { + switchFlag = getRng().randomBoolean(); + } int *c1 = switchFlag ? child2.string.get() : child1.string.get(); int *c2 = switchFlag ? child1.string.get() : child2.string.get(); @@ -88,11 +92,11 @@ void StringChromosome::fullMixingAndCrossove // create child before cross point int i = 0; for (; i < site; i++, p1++, p2++, c1++, c2++) { - if (*p1 == -1 && *p2 != -1) + if (*p1 == -1 && *p2 != -1) { *c1 = *c2 = *p2; - else if (*p1 != -1 && *p2 == -1) + } else if (*p1 != -1 && *p2 == -1) { *c1 = *c2 = *p1; - else { + } else { *c2 = *p2; *c1 = *p1; } @@ -100,11 +104,11 @@ void StringChromosome::fullMixingAndCrossove // child after cross point for (; i < length; i++, p1++, p2++, c1++, c2++) { - if (*p1 == -1 && *p2 != -1) + if (*p1 == -1 && *p2 != -1) { *c1 = *c2 = *p2; - else if (*p1 != -1 && *p2 == -1) + } else if (*p1 != -1 && *p2 == -1) { *c1 = *c2 = *p1; - else { + } else { *c2 = *p1; *c1 = *p2; } diff --git a/External/GA/ga/StringChromosomeBase.h b/External/GA/ga/StringChromosomeBase.h index f263a428b..bfb51abeb 100644 --- a/External/GA/ga/StringChromosomeBase.h +++ b/External/GA/ga/StringChromosomeBase.h @@ -123,7 +123,9 @@ void StringChromosomeBase::copyGene( */ template void StringChromosomeBase::mutate(double pMutate) { - if (pMutate < 0.0) pMutate = 1.0 / (length); + if (pMutate < 0.0) { + pMutate = 1.0 / (length); + } bool mutated = false; T *ptr = string.get(); @@ -154,16 +156,18 @@ void StringChromosomeBase::twoPointCrossover( // choose cross point sites int site1 = rng.randomInt(0, length); int site2 = rng.randomInt(0, length - 1); - if (site2 >= site1) + if (site2 >= site1) { site2++; - else { + } else { int n = site1; site1 = site2; site2 = n; } bool switchFlag = false; - if (chromosomePolicy.isAllowSwitch()) switchFlag = rng.randomBoolean(); + if (chromosomePolicy.isAllowSwitch()) { + switchFlag = rng.randomBoolean(); + } T *c1 = switchFlag ? child2.string.get() : child1.string.get(); T *c2 = switchFlag ? child1.string.get() : child2.string.get(); @@ -204,7 +208,9 @@ void StringChromosomeBase::onePointCrossover( // choose cross point site int site = rng.randomInt(0, length - 1); bool switchFlag = false; - if (chromosomePolicy.isAllowSwitch()) switchFlag = rng.randomBoolean(); + if (chromosomePolicy.isAllowSwitch()) { + switchFlag = rng.randomBoolean(); + } T *c1 = switchFlag ? child2.string.get() : child1.string.get(); T *c2 = switchFlag ? child1.string.get() : child2.string.get(); @@ -233,7 +239,9 @@ template std::string StringChromosomeBase::geneInfo() const { std::stringstream ss; for (int i = 0; i < length; i++) { - if (i > 0) ss << ' '; + if (i > 0) { + ss << ' '; + } ss << string[i]; } return ss.str(); diff --git a/External/GA/util/Util.cpp b/External/GA/util/Util.cpp index eaf421ba3..16558fb2a 100644 --- a/External/GA/util/Util.cpp +++ b/External/GA/util/Util.cpp @@ -33,7 +33,9 @@ string currentTime() { } bool startsWith(string str, string prefix) { - if (prefix.length() > str.length()) return false; + if (prefix.length() > str.length()) { + return false; + } return str.compare(0, prefix.length(), prefix) == 0; } @@ -44,16 +46,18 @@ string getUserName() { const int bufsize = 100; char buffer[bufsize]; - if (!getlogin_r(buffer, bufsize)) + if (!getlogin_r(buffer, bufsize)) { return string(buffer); - else + } else { return string(""); + } #endif } string &removeTrailingLF(string &line) { - if (!line.empty() && line[line.length() - 1] == '\r') + if (!line.empty() && line[line.length() - 1] == '\r') { line.erase(line.length() - 1); + } return line; } @@ -81,7 +85,9 @@ bool equalsIgnoreCase(const string &str1, const string &str2) { } bool endsWith(const string &str, const string &suffix) { - if (suffix.length() > str.length()) return false; + if (suffix.length() > str.length()) { + return false; + } return str.compare(str.length() - suffix.length(), string::npos, suffix) == 0; } diff --git a/External/GA/util/Util.h b/External/GA/util/Util.h index 6b572a485..4f2a5445a 100644 --- a/External/GA/util/Util.h +++ b/External/GA/util/Util.h @@ -65,21 +65,26 @@ namespace GarethUtil { template T convertString(const string &str, bool *const ok = nullptr, size_t start = 0, size_t noChars = 0) { - if (ok != nullptr) - *ok = false; + if (ok != nullptr) { + *ok = false; + } T rtn; - if (str.empty()) - return rtn; - if (start >= str.length()) - return rtn; - if (noChars == 0) - noChars = str.length() - start; + if (str.empty()) { + return rtn; + } + if (start >= str.length()) { + return rtn; + } + if (noChars == 0) { + noChars = str.length() - start; + } string field = str.substr(start, noChars); stringstream ss(field); ss >> rtn; if (!ss.fail()) { - if (ok != nullptr) - *ok = true; + if (ok != nullptr) { + *ok = true; + } } return rtn; } @@ -99,8 +104,9 @@ namespace GarethUtil { ostream_iterator(ss, seperator.c_str())); // erase trailing separator string rtn = ss.str(); - if (!rtn.empty()) - rtn.erase(rtn.length() - seperator.length(), seperator.length()); + if (!rtn.empty()) { + rtn.erase(rtn.length() - seperator.length(), seperator.length()); + } return rtn; } @@ -124,8 +130,9 @@ namespace GarethUtil { V *const value = nullptr) { auto iter = map.find(key); if (iter != map.end()) { - if (value != nullptr) - *value = iter->second; + if (value != nullptr) { + *value = iter->second; + } return true; } return false;