18 #include "selective_build.h"
21 #include <type_traits>
22 #include <unordered_map>
27 template<
typename Key,
typename T>
30 template<
typename Key,
typename T,
typename ...Args>
36 using builder_t = std::function<T(Args...)>;
38 Factory(
const std::string & name)
41 #ifdef SELECTIVE_BUILD
42 #define registerNodeIfRequired(Module, Name, key, Impl) \
43 OV_PP_EXPAND(OV_PP_CAT(registerImpl, OV_CC_SCOPE_IS_ENABLED(OV_PP_CAT3(Module, _, Name)))<Impl>(key))
44 #define createNodeIfRegistered(Module, key, ...) createImpl(key, __VA_ARGS__)
46 template<
typename Impl>
47 void registerImpl0(
const Key &) {
50 template<
typename Impl>
51 void registerImpl1(
const Key & key) {
52 builders[key] = [](Args... args) -> T {
53 Impl *impl =
new Impl(args...);
54 return static_cast<T
>(impl);
58 T createImpl(
const Key & key, Args... args) {
59 auto builder = builders.find(key);
60 if (builder != builders.end()) {
61 return builder->second(args...);
66 #elif defined(SELECTIVE_BUILD_ANALYZER)
67 #define registerNodeIfRequired(Module, Name, key, Impl) registerImpl<OV_PP_CAT(FACTORY_, Module), Impl>(key, OV_PP_TOSTRING(Name))
68 #define createNodeIfRegistered(Module, key, ...) createImpl<OV_PP_CAT(FACTORY_, Module)>(key, __VA_ARGS__)
70 template<openvino::itt::domain_t(*domain)(),
typename Impl>
71 void registerImpl(
const Key & key,
const char *typeName) {
72 const std::string task_name =
"REG$" + name +
"$" + to_string(key) +
"$" + typeName;
74 builders[key] = [](Args... args) -> T {
75 Impl *impl =
new Impl(args...);
76 return static_cast<T
>(impl);
80 template<openvino::itt::domain_t(*domain)()>
81 T createImpl(
const Key & key, Args... args) {
82 auto builder = builders.find(key);
83 if (builder != builders.end()) {
84 const std::string task_name =
"CREATE$" + name +
"$" + to_string(key);
86 return builder->second(args...);
93 #define registerNodeIfRequired(Module, Name, key, Impl) registerImpl<Impl>(key)
94 #define createNodeIfRegistered(Module, key, ...) createImpl(key, __VA_ARGS__)
96 template<
typename Impl>
97 void registerImpl(
const Key & key) {
98 builders[key] = [](Args... args) -> T {
99 Impl *impl =
new Impl(args...);
100 return static_cast<T
>(impl);
104 T createImpl(
const Key & key, Args... args) {
105 auto builder = builders.find(key);
106 if (builder != builders.end()) {
107 return builder->second(args...);
113 template<
typename Fn>
114 void foreach(Fn fn)
const {
115 for (
auto itm : builders)
119 size_t size()
const noexcept {
120 return builders.size();
124 const std::string & to_string(
const std::string & str)
const noexcept {
129 typename std::enable_if<std::is_enum<V>::value,
bool>::type =
true>
130 std::string to_string(V val)
const {
131 return std::to_string(
static_cast<int>(val));
135 typename std::enable_if<!std::is_enum<V>::value,
bool>::type =
true>
136 std::string to_string(V val)
const {
137 return std::to_string(val);
140 template <
typename K>
141 struct EnumClassHash {
142 std::size_t operator()(K t)
const {
143 return static_cast<std::size_t
>(t);
147 using hash_t =
typename std::conditional<std::is_enum<Key>::value, EnumClassHash<Key>, std::hash<Key>>::type;
148 using map_t = std::unordered_map<Key, builder_t, hash_t>;
150 const std::string name;
Used to annotate section of code which would be named at runtime.
Definition: itt.hpp:121