1 #ifndef INC_FUNCTION_MAP_H
2 #define INC_FUNCTION_MAP_H
23 #include <initializer_list>
40 using FunctionType = std::function<S>;
44 using MapType = std::map<const std::string, const FunctionType>;
51 FunctionMap(std::initializer_list<typename MapType::value_type> l) : m_map(l) {}
57 FunctionType
Get(
const std::string& name)
const
59 return (m_map.count(name) != 0) ? m_map.at(name) : FunctionType();
63 bool IsValid(
const std::string& name)
const
65 return (m_map.count(name) != 0) && (m_map.at(name));
69 bool Register(
const std::string& name,
const FunctionType& f)
72 if ((m_map.count(name) == 0) && (f)){
73 m_map.insert(std::make_pair(name, f));
80 std::list<std::string>
List()
const
82 std::list<std::string> l;
83 for (
const auto& e : m_map) {
96 #endif // end-of-include-guard
virtual ~FunctionMap()
Destructor must be virtual.
bool Register(const std::string &name, const FunctionType &f)
Register a function.
Namespace for the core simulator.
bool IsValid(const std::string &name) const
Check whether function name is present.
std::list< std::string > List() const
List the names.
A map to hold std::functions.
FunctionType Get(const std::string &name) const
Return function for given name.
FunctionMap()
Construct an empty map.
FunctionMap(std::initializer_list< typename MapType::value_type > l)
Construct map from initializer_list.