60 lines
1.1 KiB
C
60 lines
1.1 KiB
C
|
|
#ifndef CONST_H
|
||
|
|
#define CONST_H
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
#include <fstream>
|
||
|
|
#include <iostream>
|
||
|
|
#include <vector>
|
||
|
|
#include <map>
|
||
|
|
|
||
|
|
struct constant {
|
||
|
|
std::string name;
|
||
|
|
double value;
|
||
|
|
double uncertainty;
|
||
|
|
std::string unit;
|
||
|
|
std::string reference;
|
||
|
|
}
|
||
|
|
|
||
|
|
class constants {
|
||
|
|
private:
|
||
|
|
bool loaded_ = false;
|
||
|
|
std::map<std::string, constant> constants_;
|
||
|
|
|
||
|
|
bool load(const std::string& filename);
|
||
|
|
|
||
|
|
public:
|
||
|
|
constants();
|
||
|
|
|
||
|
|
constants(const std::string& filename);
|
||
|
|
|
||
|
|
bool is_loaded() { return loaded_; }
|
||
|
|
|
||
|
|
bool initialize(const std::string& filename);
|
||
|
|
|
||
|
|
constant get(const std::string& key);
|
||
|
|
|
||
|
|
constant operator[](const std::string& key) const {
|
||
|
|
auto it = constants_.find(key);
|
||
|
|
if (it != constants_.end()) {
|
||
|
|
return it->second;
|
||
|
|
} else {
|
||
|
|
throw std::out_of_range("Constant '" + key + "' not found.");
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
bool has(const std::string& key) const {
|
||
|
|
return constants_.find(key) != constants_.end();
|
||
|
|
};
|
||
|
|
|
||
|
|
std::Vector<std::string> keys() const {
|
||
|
|
std::Vector<std::string> keys;
|
||
|
|
for (auto it = constants_.begin(); it != constants_.end(); ++it) {
|
||
|
|
keys.push_back(it->first);
|
||
|
|
}
|
||
|
|
return keys;
|
||
|
|
};
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif
|