13#define WRITE_TO_JSON_IF_TYPE_MATCHES(VARIANT, TYPE) \
14 if (type == typeid(TYPE)) \
16 outputFile << "\t\"" << kv.first << "\": "; \
17 if (typeid(TYPE) == typeid(std::string)) \
19 outputFile << "\"" << boost::any_cast<TYPE>(VARIANT) << "\""; \
23 outputFile << boost::any_cast<TYPE>(VARIANT); \
27#include "OMSimLogger.hh"
30#include <boost/any.hpp>
59 using Key = std::string;
60 using Value = boost::any;
62 bool m_finalized =
false;
63 std::map<Key, Value> m_parameters;
70 void setParameter(
const Key &p_key,
const Value &p_value);
71 bool keyExists(
const Key &p_key);
82 T
get(
const std::string &p_key)
86 return boost::any_cast<T>(m_parameters.at(p_key));
88 catch (
const boost::bad_any_cast &e)
90 log_error((
"Failed to get parameter '" + p_key +
"' as type " +
typeid(T).name()).c_str());
91 throw std::invalid_argument(
"Failed to get parameter " + p_key +
" as type " +
typeid(T).name());
93 catch (
const std::out_of_range &e)
95 log_error((
"Parameter '" + p_key +
"'does not exist").c_str());
96 throw std::invalid_argument(
"Parameter '" + p_key +
"' does not exist");
A class used to hold OMSim command arguments with global instance access.
Definition OMSimCommandArgsTable.hh:51
void writeToJson(std::string p_fileName)
Writes the parameters to a JSON-formatted file.
Definition OMSimCommandArgsTable.cc:62
T get(const std::string &p_key)
Retrieves a parameter from the table.
Definition OMSimCommandArgsTable.hh:82
static void init()
Initializes the global instance of OMSimCommandArgsTable.
Definition OMSimCommandArgsTable.cc:19
void setParameter(const Key &p_key, const Value &p_value)
Sets a parameter in the arg table.
Definition OMSimCommandArgsTable.cc:42
static OMSimCommandArgsTable & getInstance()
Definition OMSimCommandArgsTable.cc:7
void finalize()
Finalizes the table, setting a random seed if none was provided. m_finalized is set to true preventin...
Definition OMSimCommandArgsTable.cc:107
static void shutdown()
Deletes the global instance of OMSimCommandArgsTable.
Definition OMSimCommandArgsTable.cc:30