Debian Codegraph @

ncrystal_core/include/NCrystal/internal/NCAtomUtils.hh

raw symbols SCIP
1 #cxx . . $ `<file>/ncrystal_core/include/NCrystal/internal/NCAtomUtils.hh`/ifndef NCrystal_AtomUtils_hh
2 #define NCrystal_AtomUtils_hhcxx . . $ `ncrystal_core/include/NCrystal/internal/NCAtomUtils.hh:2:9`!
3
4 ////////////////////////////////////////////////////////////////////////////////
5 // //
6 // This file is part of NCrystal (see https://mctools.github.io/ncrystal/) //
7 // //
8 // Copyright 2015-2022 NCrystal developers //
9 // //
10 // Licensed under the Apache License, Version 2.0 (the "License"); //
11 // you may not use this file except in compliance with the License. //
12 // You may obtain a copy of the License at //
13 // //
14 // http://www.apache.org/licenses/LICENSE-2.0 //
15 // //
16 // Unless required by applicable law or agreed to in writing, software //
17 // distributed under the License is distributed on an "AS IS" BASIS, //
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
19 // See the License for the specific language governing permissions and //
20 // limitations under the License. //
21 // //
22 ////////////////////////////////////////////////////////////////////////////////
23
24 #include "NCrystal/NCSmallVector.hh"cxx . . $ `<file>/ncrystal_core/include/NCrystal/NCSmallVector.hh`/
25
26 namespace NCrystalcxx . . $ NCrystal/ {
27
28 /////////////////////////////
29 // Z<->elementName mapping //
30 /////////////////////////////
31
32 const stdcxx . . $ std/::stringcxx . . $ std/string#& elementZToNamecxx . . $ NCrystal/elementZToName(3361b5b26a453b9d).(unsigned z);//returns empty string if invalid
33 unsigned elementNameToZcxx . . $ NCrystal/elementNameToZ(3fcf6099b9b98586).(const stdcxx . . $ std/::stringcxx . . $ std/string#&);//returns 0 if invalid
34
35 ////////////////////////////
36 // Decode atomic symbols. //
37 ////////////////////////////
38
39 class AtomSymbolcxx . . $ NCrystal/AtomSymbol# final {
40 public:
41 //Valid atomic symbols are:
42 //
43 //1) Elements: "H", "He", "Li", ...
44 //2) Isotopes: "H1", "H2", "He3", "Li6", ... (impossible ones with A<Z are invalid)#
45 // NB: special aliases: "D" for "H2" and "T" for "H3".
46 //3) Custom markers: "X", "X1", "X2", ..., "X99" (and no others).
47
48 AtomSymbolcxx . . $ NCrystal/AtomSymbol#AtomSymbol(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string#&);
49 ~cxx . . $ NCrystal/AtomSymbol#`~AtomSymbol`(ced63f7c635d850d).AtomSymbolcxx . . $ NCrystal/AtomSymbol#() = default;
50
51 bool isInvalidcxx . . $ NCrystal/AtomSymbol#isInvalid(50ce9a9e25b4a850).() const;
52 bool isCustomMarkercxx . . $ NCrystal/AtomSymbol#isCustomMarker(50ce9a9e25b4a850).() const;
53 bool isElementcxx . . $ NCrystal/AtomSymbol#isElement(50ce9a9e25b4a850).() const;
54 bool isIsotopecxx . . $ NCrystal/AtomSymbol#isIsotope(50ce9a9e25b4a850).() const;
55
56 //If isElement() or isIsotope() it is safe to call (NB: A() returns 0 for
57 //elements):
58 unsigned Zcxx . . $ NCrystal/AtomSymbol#Z(ddd8539a2fcdd4ce).() const;
59 unsigned Acxx . . $ NCrystal/AtomSymbol#A(ddd8539a2fcdd4ce).() const;
60
61 ncconstexpr17cxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:66:13`! bool operatorcxx . . $ NCrystal/AtomSymbol#`operator==`(3b2f428520b7fa5e).==( const AtomSymbolcxx . . $ NCrystal/AtomSymbol#& ) const noexcept;
62 ncconstexpr17cxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:66:13`! bool operatorcxx . . $ NCrystal/AtomSymbol#`operator<`(3b2f428520b7fa5e).<( const AtomSymbolcxx . . $ NCrystal/AtomSymbol#& ) const noexcept;
63
64 private:
65 unsigned m_zcxx . . $ NCrystal/AtomSymbol#m_z. = 0, m_acxx . . $ NCrystal/AtomSymbol#m_a. = 0;
66 //(Z,0)=element, (Z,A>Z)=isotope, (0,1-100)=custom("X{i-1}") (0,0)=invalid
67 void longInitcxx . . $ NCrystal/AtomSymbol#longInit(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string#&);
68 };
69
70 /////////////////////////////////////////////////////////////////////////////////
71 // Validate the syntex of atomdb lines. This should be kept in sync with the //
72 // NCMAT data spec in ncmat_doc.md and the cfg-str description in NCMatCfg.hh. //
73 // NCMatCfg.hh. The special syntax available/required in cfg-strings (with //
74 // semicolons and @) is not handled here. In case of problems, a BadInput //
75 // exception is thrown, which means that any code implementing subsequent //
76 // parsing of the lines is allowed to simply assume correct format. Note that //
77 // it only validates a single line at a time, and therefore does not verify //
78 // that a line with the word "nodefaults" comes at the beginning. It also does //
79 // not verify if a line is missing previous definitions (i.e. if it refers to //
80 // X5 it can't check if X5 was defined previously): //
81 /////////////////////////////////////////////////////////////////////////////////
82
83 void validateAtomDBLinecxx . . $ NCrystal/validateAtomDBLine(379f51b3a003aadd).(const VectScxx . . $ NCrystal/VectS#& words,
84 unsigned ncmat_version = supported_ncmat_format_version_maxcxx . . $ NCrystal/supported_ncmat_format_version_max.);
85
86 //Helper function which can be used to decode chemical formulas like "He",
87 //"SiO2", "Al2O3", etc. Will return a list of fractions and associated decoded
88 //AtomSymbols. These symbols will always be valid elements (or perhaps one day
89 //isotopes), never custom markers.
90 //
91 //This function only supports simple formulas like "Al2O3". In the future we
92 //might add versions which would support fractions or isotopes.
93
94 using DecodedChemFormcxx . . $ NCrystal/DecodedChemForm# = SmallVectorcxx . . $ NCrystal/SmallVector#<stdcxx . . $ std/::pair<stdcxx . . $ std/::uint_least32_tcxx . . $ std/uint_least32_t#,AtomSymbolcxx . . $ NCrystal/AtomSymbol#>,
95 4,SVModecxx . . $ NCrystal/SVMode#::FASTACCESS_IMPLICITCOPYcxx . . $ NCrystal/SVMode#FASTACCESS_IMPLICITCOPY.>;
96 DecodedChemFormcxx . . $ NCrystal/DecodedChemForm# decodeSimpleChemicalFormulacxx . . $ NCrystal/decodeSimpleChemicalFormula(c0bbbc412820c5c4).( stdcxx . . $ std/::stringcxx . . $ std/string# );
97 Optionalcxx . . $ NCrystal/Optional#<DecodedChemFormcxx . . $ NCrystal/DecodedChemForm#> tryDecodeSimpleChemicalFormulacxx . . $ NCrystal/tryDecodeSimpleChemicalFormula(c9795f97866fee73).( stdcxx . . $ std/::stringcxx . . $ std/string# );
98 void streamSimpleChemicalFormulacxx . . $ NCrystal/streamSimpleChemicalFormula(b18fad4dbd910d11).( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#&, const DecodedChemFormcxx . . $ NCrystal/DecodedChemForm#& );
99
100 //Order entries in standard form (merge duplicates and sort by the Hill System):
101 DecodedChemFormcxx . . $ NCrystal/DecodedChemForm# normaliseSimpleChemicalFormulacxx . . $ NCrystal/normaliseSimpleChemicalFormula(c4a84dc6807f9b92).(const DecodedChemFormcxx . . $ NCrystal/DecodedChemForm#&);
102 }
103
104
105 ////////////////////////////
106 // Inline implementations //
107 ////////////////////////////
108
109 inline NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::AtomSymbolcxx . . $ NCrystal/AtomSymbol#AtomSymbol(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string#& ss)
110 : m_zcxx . . $ NCrystal/AtomSymbol#m_z.(elementNameToZcxx . . $ NCrystal/elementNameToZ(3fcf6099b9b98586).(ss)),
111 m_acxx . . $ NCrystal/AtomSymbol#m_a.(0)
112 {
113 //Usual case of regular element names is inlined, other cases needs
114 //longer init:
115 if (m_zcxx . . $ NCrystal/AtomSymbol#m_z.==0)
116 longInitcxx . . $ NCrystal/AtomSymbol#longInit(9c546c94e5fcce4e).(ss);
117 }
118
119 inline ncconstexpr17cxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:66:13`! bool NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::operatorcxx . . $ NCrystal/AtomSymbol#`operator==`(3b2f428520b7fa5e).==( const AtomSymbolcxx . . $ NCrystal/AtomSymbol#& o ) const noexcept
120 {
121 return m_zcxx . . $ NCrystal/AtomSymbol#m_z. == o.m_zcxx . . $ NCrystal/AtomSymbol#m_z. && m_acxx . . $ NCrystal/AtomSymbol#m_a. == o.m_acxx . . $ NCrystal/AtomSymbol#m_a.;
122 }
123
124 inline ncconstexpr17cxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:66:13`! bool NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::operatorcxx . . $ NCrystal/AtomSymbol#`operator<`(3b2f428520b7fa5e).<( const AtomSymbolcxx . . $ NCrystal/AtomSymbol#& o ) const noexcept
125 {
126 return m_zcxx . . $ NCrystal/AtomSymbol#m_z. == o.m_zcxx . . $ NCrystal/AtomSymbol#m_z. ? (m_acxx . . $ NCrystal/AtomSymbol#m_a. < o.m_acxx . . $ NCrystal/AtomSymbol#m_a.) : ( m_zcxx . . $ NCrystal/AtomSymbol#m_z. < o.m_zcxx . . $ NCrystal/AtomSymbol#m_z.);
127 }
128
129 inline bool NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::isInvalidcxx . . $ NCrystal/AtomSymbol#isInvalid(50ce9a9e25b4a850).() const { return m_zcxx . . $ NCrystal/AtomSymbol#m_z. == 0 && m_acxx . . $ NCrystal/AtomSymbol#m_a. ==0; }
130 inline bool NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::isCustomMarkercxx . . $ NCrystal/AtomSymbol#isCustomMarker(50ce9a9e25b4a850).() const { return m_zcxx . . $ NCrystal/AtomSymbol#m_z. == 0 && m_acxx . . $ NCrystal/AtomSymbol#m_a. !=0; }
131 inline bool NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::isElementcxx . . $ NCrystal/AtomSymbol#isElement(50ce9a9e25b4a850).() const { return m_zcxx . . $ NCrystal/AtomSymbol#m_z. != 0 && m_acxx . . $ NCrystal/AtomSymbol#m_a. ==0; }
132 inline bool NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::isIsotopecxx . . $ NCrystal/AtomSymbol#isIsotope(50ce9a9e25b4a850).() const { return m_zcxx . . $ NCrystal/AtomSymbol#m_z. != 0 && m_acxx . . $ NCrystal/AtomSymbol#m_a. !=0; }
133 inline unsigned NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::Zcxx . . $ NCrystal/AtomSymbol#Z(ddd8539a2fcdd4ce).() const { nc_assertcxx . . $ `ncrystal_core/include/NCrystal/NCException.hh:153:11`!(m_z != 0); return m_zcxx . . $ NCrystal/AtomSymbol#m_z.; }
134 inline unsigned NCrystalcxx . . $ NCrystal/::AtomSymbolcxx . . $ NCrystal/AtomSymbol#::Acxx . . $ NCrystal/AtomSymbol#A(ddd8539a2fcdd4ce).() const { nc_assertcxx . . $ `ncrystal_core/include/NCrystal/NCException.hh:153:11`!(m_z != 0); return m_acxx . . $ NCrystal/AtomSymbol#m_a.; }
135
136 #endif