diff options
Diffstat (limited to 'NodeFactory.cpp')
-rw-r--r-- | NodeFactory.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/NodeFactory.cpp b/NodeFactory.cpp index da4cc72..4824734 100644 --- a/NodeFactory.cpp +++ b/NodeFactory.cpp @@ -11,14 +11,24 @@ bool NodeFactory::has_type(const char * type) { bool NodeFactory::has_type(string type) { std::ranges::transform(type, type.begin(), [] (unsigned char c) { return std::tolower(c); }); - // TODO: query the map instead - if (type == "and") return true; - if (type == "not") return true; - if (type == "or") return true; - if (type == "input_high") return true; - if (type == "input_low") return true; - if (type == "probe") return true; - - return false; + static NodeFactoryMap & map = get_map(); + + return map.find(type) != map.end(); +} + +void NodeFactory::assign(const char * _type, const Node * node) { + static NodeFactoryMap & map = get_map(); + string type = _type; + + std::ranges::transform(type, type.begin(), [] (unsigned char c) { return std::tolower(c); }); + + if (has_type(type)) return; + + map[type] = node; +} + +NodeFactoryMap & NodeFactory::get_map() { + static NodeFactoryMap map; + return map; } |