11 #ifndef smtk_view_OperationIcons_h
12 #define smtk_view_OperationIcons_h
14 #include "smtk/CoreExports.h"
15 #include "smtk/SystemConfig.h"
17 #include "smtk/common/Factory.h"
18 #include "smtk/operation/Operation.h"
22 #include <unordered_map>
51 using Index = smtk::operation::Operation::Index;
53 using IndexMap = std::unordered_map<std::string, Index>;
55 using FunctorMap = std::unordered_map<Index, IconConstructor>;
58 template<
typename OperationType>
61 Index index =
typeid(OperationType).hash_code();
62 bool didAdd = m_functors.emplace(std::make_pair(index, functor)).second;
64 m_indices.emplace(std::make_pair(smtk::common::typeName<OperationType>(), index)).second;
70 void registerDefaultIconConstructor(IconConstructor&& functor);
73 template<
typename OperationType>
76 Index index =
typeid(OperationType).hash_code();
77 for (
auto it = m_indices.cbegin(); it != m_indices.cend(); )
79 if (it->second == index)
81 it = m_indices.erase(it);
88 return m_functors.erase(index) > 0;
93 template<
typename OperationType>
94 std::string
createIcon(
const std::string& secondaryColor)
const
96 Index index =
typeid(OperationType).hash_code();
97 auto it = m_functors.find(index);
98 if (it == m_functors.end())
100 if (m_defaultIconConstructor)
102 return m_defaultIconConstructor(secondaryColor);
104 return std::string();
106 return it->second(secondaryColor);
109 std::string createIcon(
const std::string& operationName,
const std::string& secondaryColor)
const;
110 std::string createIcon(
const Index& index,
const std::string& secondaryColor)
const;
113 FunctorMap m_functors;
115 IconConstructor m_defaultIconConstructor;