19 #include <momemta/ParameterSet.h> 21 #include <momemta/Unused.h> 23 #include <lua/LazyTable.h> 24 #include <lua/utils.h> 26 ParameterSet::ParameterSet(
const std::string& module_type,
const std::string& module_name) {
27 m_set.emplace(
"@type", Element(module_type));
28 m_set.emplace(
"@name", Element(module_name));
32 auto value = m_set.find(name);
33 if (value == m_set.end())
34 throw not_found_error(
"Parameter '" + name +
"' not found.");
36 return value->second.value;
43 bool ParameterSet::exists(
const std::string& name)
const {
44 auto value = m_set.find(name);
45 return (value != m_set.end());
49 m_set.emplace(name,
Element(value,
false));
52 void ParameterSet::setInternal(
const std::string& name,
Element& element,
const momemta::any& value) {
55 element.value = value;
59 void ParameterSet::freeze() {
65 for (
auto& p: m_set) {
66 auto& element = p.second;
80 }
else if (element.value.type() ==
typeid(std::vector<ParameterSet>)) {
81 std::vector<ParameterSet>& v = momemta::any_cast<std::vector<ParameterSet>&>(element.value);
87 LOG(fatal) <<
"Exception while trying to parse parameter " << getModuleType() <<
"." << getModuleName() <<
"::" << p.first;
88 std::rethrow_exception(std::current_exception());
93 void ParameterSet::setGlobalParameters(
const ParameterSet& parameters) {
94 m_set.emplace(
"@global_parameters",
Element(parameters,
false));
101 std::vector<std::string> ParameterSet::getNames()
const {
102 std::vector<std::string> names;
103 for (
const auto& it: m_set) {
104 names.push_back(it.first);
110 void ParameterSet::remove(
const std::string& name) {
Lazy table field in lua (delayed table access)
A small wrapper around a momemta::any value.
virtual void create(const std::string &name, const momemta::any &value)
Add a new element to the ParameterSet.
A class encapsulating a lua table.
virtual bool lazy() const
A flag indicating if this ParameterSet lazy loads its fields or not.
virtual ParameterSet * clone() const
Clone this ParameterSet.
Lazy function in lua (delayed function evaluation)
const momemta::any & rawGet(const std::string &name) const