diff --git a/core/indigo-core/molecule/molecule_gross_formula.h b/core/indigo-core/molecule/molecule_gross_formula.h index f7b1b2edb0..c39c6d5c89 100644 --- a/core/indigo-core/molecule/molecule_gross_formula.h +++ b/core/indigo-core/molecule/molecule_gross_formula.h @@ -19,6 +19,7 @@ #ifndef __molecule_gross_formula__ #define __molecule_gross_formula__ +#include #include #include @@ -43,7 +44,7 @@ namespace indigo { public: Array multiplier; - RedBlackMap isotopes; + std::map isotopes; }; // Represents array of superunits gross formulas. @@ -74,7 +75,7 @@ namespace indigo }; static void _toString(const Array& gross, ArrayOutput& output, int (*cmp)(_ElemCounter&, _ElemCounter&, void*), bool add_rsites); - static void _toString(const RedBlackMap& gross, ArrayOutput& output, int (*cmp)(_ElemCounter&, _ElemCounter&, void*), bool add_rsites); + static void _toString(const std::map& gross, ArrayOutput& output, int (*cmp)(_ElemCounter&, _ElemCounter&, void*), bool add_rsites); static int _cmp(_ElemCounter& ec1, _ElemCounter& ec2, void* context); static int _cmp_hill(_ElemCounter& ec1, _ElemCounter& ec2, void* context); static int _cmp_hill_no_carbon(_ElemCounter& ec1, _ElemCounter& ec2, void* context); diff --git a/core/indigo-core/molecule/src/molecule_gross_formula.cpp b/core/indigo-core/molecule/src/molecule_gross_formula.cpp index d1a6221117..26b29b134d 100644 --- a/core/indigo-core/molecule/src/molecule_gross_formula.cpp +++ b/core/indigo-core/molecule/src/molecule_gross_formula.cpp @@ -120,11 +120,11 @@ void MoleculeGrossFormula::collect(BaseMolecule& molecule, Array& gross_out auto& unit = gross[0]; int number = 0; - for (int i = unit.isotopes.begin(); i < unit.isotopes.end(); i = unit.isotopes.next(i)) + for (auto it = unit.isotopes.begin(); it != unit.isotopes.end(); it++) { - number = unit.isotopes.key(i) & 0xFF; + number = it->first & 0xFF; if (number < ELEM_RSITE + 1) - gross_out[number] += unit.isotopes.value(i); + gross_out[number] += it->second; } } @@ -204,8 +204,10 @@ std::unique_ptr MoleculeGrossFormula::collect(BaseMolecule& mol, bo else continue; - if ((val = unit.isotopes.at2(key)) == 0) - unit.isotopes.insert(key, 1); + auto it = unit.isotopes.find(key); + val = &(it->second); + if (it == unit.isotopes.end()) + unit.isotopes.emplace(key, 1); else *val += 1; @@ -216,8 +218,10 @@ std::unique_ptr MoleculeGrossFormula::collect(BaseMolecule& mol, bo if (implicit_h >= 0) { key = ELEM_H; - if ((val = unit.isotopes.at2(key)) == 0) - unit.isotopes.insert(key, implicit_h); + auto it = unit.isotopes.find(key); + val = &(it->second); + if (it == unit.isotopes.end()) + unit.isotopes.emplace(key, implicit_h); else *val += implicit_h; } @@ -255,7 +259,9 @@ void MoleculeGrossFormula::toString_Hill(GROSS_UNITS& gross, Array& str, b int* val; // First base molecule - if ((val = gross[0].isotopes.at2(ELEM_C)) == 0) + auto it = gross[0].isotopes.find(ELEM_C); + val = &(it->second); + if (it == gross[0].isotopes.end()) _toString(gross[0].isotopes, output, _cmp_hill_no_carbon, add_rsites); else _toString(gross[0].isotopes, output, _cmp_hill, add_rsites); @@ -264,7 +270,9 @@ void MoleculeGrossFormula::toString_Hill(GROSS_UNITS& gross, Array& str, b for (int i = 1; i < gross.size(); i++) { output.writeChar('('); - if ((val = gross[i].isotopes.at2(ELEM_C)) == 0) + auto it = gross[0].isotopes.find(ELEM_C); + val = &(it->second); + if (it == gross[0].isotopes.end()) _toString(gross[i].isotopes, output, _cmp_hill_no_carbon, add_rsites); else _toString(gross[i].isotopes, output, _cmp_hill, add_rsites); @@ -314,8 +322,7 @@ void MoleculeGrossFormula::_toString(const Array& gross, ArrayOutput& outpu } } -void MoleculeGrossFormula::_toString(const RedBlackMap& isotopes, ArrayOutput& output, int (*cmp)(_ElemCounter&, _ElemCounter&, void*), - bool add_rsites) +void MoleculeGrossFormula::_toString(const std::map& isotopes, ArrayOutput& output, int (*cmp)(_ElemCounter&, _ElemCounter&, void*), bool add_rsites) { QS_DEF(Array<_ElemCounter>, counters); @@ -323,19 +330,19 @@ void MoleculeGrossFormula::_toString(const RedBlackMap& isotopes, Arra int number; int isotope; - for (i = isotopes.begin(); i < isotopes.end(); i = isotopes.next(i)) + for (auto it = isotopes.begin(); it != isotopes.end(); it++) { - if (isotopes.key(i) == ELEM_RSITE) + if (it->first == ELEM_RSITE) continue; _ElemCounter& ec = counters.push(); - number = isotopes.key(i) & 0xFF; - isotope = isotopes.key(i) >> 8; + number = it->first & 0xFF; + isotope = it->first >> 8; ec.elem = number; ec.isotope = isotope; - ec.counter = isotopes.value(i); + ec.counter = it->second; } counters.qsort(cmp, 0); @@ -371,8 +378,9 @@ void MoleculeGrossFormula::_toString(const RedBlackMap& isotopes, Arra first_written = true; } - int* val; - if (add_rsites && (val = isotopes.at2(ELEM_RSITE)) != 0) + auto it = isotopes.find(ELEM_RSITE); + const int* val = &(it->second); + if (add_rsites && it != isotopes.end()) { output.writeString(" R#"); if (*val > 1)