feat(const.h): added basic interface definition for constants module

This commit is contained in:
2025-02-10 16:47:58 -05:00
parent 0b4993c2b7
commit 078269fb4a

59
src/const/public/const.h Normal file
View File

@@ -0,0 +1,59 @@
#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