11 #ifndef smtk_attribute_EvaluatorFactory_h
12 #define smtk_attribute_EvaluatorFactory_h
14 #include "smtk/CoreExports.h"
16 #include "smtk/attribute/Attribute.h"
17 #include "smtk/attribute/Evaluator.h"
19 #include "smtk/common/Factory.h"
23 #include <unordered_map>
24 #include <unordered_set>
42 template<
typename EvaluatorType>
43 void registerEvaluator(
const std::string& alias);
51 bool addDefinitionForEvaluator(
const std::string& alias,
const std::string& definitionName);
54 bool unregisterEvaluator(
const std::string& alias);
58 template<
typename EvaluatorType>
59 bool unregisterEvaluator();
64 std::unique_ptr<smtk::attribute::Evaluator> createEvaluator(
67 bool isDefinitionRegistered(
const std::string& definitionName)
const;
71 std::map<std::string, std::vector<std::string>> aliasesToDefinitions()
const;
77 FactoryInfo() =
default;
78 FactoryInfo(std::size_t typeHash,
const std::unordered_set<std::string>& definitionNames)
79 : m_typeHash(typeHash)
80 , m_definitionNames(definitionNames)
83 FactoryInfo(
const FactoryInfo&) =
default;
85 std::size_t m_typeHash;
86 std::unordered_set<std::string> m_definitionNames;
89 std::unordered_map<std::string, FactoryInfo> m_aliasesToFactoryInfo;
94 template<
typename EvaluatorType>
95 void EvaluatorFactory::registerEvaluator(
const std::string& alias)
97 std::size_t typeHash = std::type_index(
typeid(EvaluatorType)).hash_code();
99 const auto it = m_aliasesToFactoryInfo.find(alias);
100 if (it != m_aliasesToFactoryInfo.end() && it->second.m_typeHash == typeHash)
105 m_aliasesToFactoryInfo[alias] = FactoryInfo(typeHash, std::unordered_set<std::string>{});
107 if (m_internal.
contains<EvaluatorType>())
115 template<
typename EvaluatorType>
116 bool EvaluatorFactory::unregisterEvaluator()
118 for (
const auto& p : m_aliasesToFactoryInfo)
120 std::size_t typeHash = std::type_index(
typeid(EvaluatorType)).hash_code();
121 if (p.second.m_typeHash == typeHash)
123 m_aliasesToFactoryInfo.erase(p.first);
135 #endif // smtk_attribute_EvaluatorFactory_h