25string const ElementMap::knownElements[] = {
26"H" ,
"He",
"Li",
"Be",
"B" ,
"C" ,
"N" ,
"O" ,
"F" ,
"Ne",
"Na",
"Mg",
"Al",
27"Si",
"P" ,
"S" ,
"Cl",
"Ar",
"K" ,
"Ca",
"Sc",
"Ti",
"V" ,
"Cr",
"Mn",
"Fe",
28"Co",
"Ni",
"Cu",
"Zn",
"Ga",
"Ge",
"As",
"Se",
"Br",
"Kr",
"Rb",
"Sr",
"Y" ,
29"Zr",
"Nb",
"Mo",
"Tc",
"Ru",
"Rh",
"Pd",
"Ag",
"Cd",
"In",
"Sn",
"Sb",
"Te",
30"I" ,
"Xe",
"Cs",
"Ba",
"La",
"Ce",
"Pr",
"Nd",
"Pm",
"Sm",
"Eu",
"Gd",
"Tb",
31"Dy",
"Ho",
"Er",
"Tm",
"Yb",
"Lu",
"Hf",
"Ta",
"W" ,
"Re",
"Os",
"Ir",
"Pt",
32"Au",
"Hg",
"Tl",
"Pb",
"Bi",
"Po",
"At",
"Rn",
"Fr",
"Ra",
"Ac",
"Th",
"Pa",
33"U" ,
"Np",
"Pu",
"Am",
"Cm",
"Bk",
"Cf",
"Es",
"Fm",
"Md",
"No"
36size_t ElementMap::registerElements(
string const& elementLine)
38 vector<string> elements =
split(
reduce(elementLine));
44 throw runtime_error(
"ERROR: Element map not empty.\n");
47 for (
size_t i = 0; i < elements.size(); i++)
60 if (
size() == 0)
return elements;
62 if (
size() == 1)
return elements;
63 for (
size_t i = 1; i <
size(); ++i)
93 for (
size_t i = 0; i < numKnownElements; i++)
101 throw runtime_error(
"ERROR: Element \"" +
symbol +
"\" unknown.\n");
112 throw runtime_error(
strpr(
"ERROR: Only the first %zu elements are "
113 "known to this library.\n",
118 throw runtime_error(
"ERROR: Invalid atomic number.\n");
129 v.push_back(
strpr(
"********************************\n"));
130 v.push_back(
strpr(
"ELEMENT MAP \n"));
131 v.push_back(
strpr(
"********************************\n"));
132 v.push_back(
strpr(
"--------------------------------\n"));
134 v.push_back(
strpr(
"--------------------------------\n"));
135 for (map<string, size_t>::const_iterator it =
forwardMap.begin();
138 v.push_back(
strpr(
"%29s : %d\n", it->first.c_str(), it->second));
140 v.push_back(
strpr(
"--------------------------------\n"));
141 v.push_back(
strpr(
"--------------------------------\n"));
143 v.push_back(
strpr(
"--------------------------------\n"));
144 for (map<size_t, string>::const_iterator it =
reverseMap.begin();
147 v.push_back(
strpr(
"%29d : %s\n", it->first, it->second.c_str()));
149 v.push_back(
strpr(
"--------------------------------\n"));
150 v.push_back(
strpr(
"********************************\n"));
std::size_t index(std::string const &symbol) const
Get index of given element.
std::map< std::string, std::size_t > forwardMap
Map of elements present and corresponding index number.
std::map< std::size_t, std::string > reverseMap
Reverse element map.
std::vector< std::string > info() const
Get map information as a vector of strings.
std::size_t size() const
Get element map size.
static std::string symbolFromAtomicNumber(std::size_t const atomicNumber)
Get element symbol from atomic number.
void deregisterElements()
Clear element map.
std::string getElementsString() const
Get sorted list of elements in one string (space separated).
static bool compareAtomicNumber(std::string const &symbol1, std::string const &symbol2)
Check if arguments are sorted according to atomic number.
std::size_t atomicNumber(std::size_t index) const
Get atomic number from element index.
static std::string const knownElements[]
List of element symbols (e.g. "He" for Helium).
std::string symbol(std::size_t const index) const
Get element symbol for given element index.
string strpr(const char *format,...)
String version of printf function.
vector< string > split(string const &input, char delimiter)
Split string at each delimiter.
string reduce(string const &line, string const &whitespace, string const &fill)
Replace multiple whitespaces with fill.
V const & safeFind(std::map< K, V > const &stdMap, typename std::map< K, V >::key_type const &key)
Safely access map entry.