2 #ifndef SST_CORE_FACTORY_INFO_H
3 #define SST_CORE_FACTORY_INFO_H
5 #include <sst/core/eli/elibase.h>
11 template <
class Base,
class... Args>
14 typedef Base* (*createFxn)(Args...);
16 virtual Base* create(Args... ctorArgs) = 0;
18 template <
class NewBase>
22 template <
class Base,
class... CtorArgs>
34 auto iter = factories_.find(name);
35 if (iter == factories_.end()){
42 const std::map<std::string, BaseBuilder*>& getMap()
const {
46 void readdBuilder(
const std::string& name,
BaseBuilder* fact){
47 factories_[name] = fact;
50 bool addBuilder(
const std::string& elem,
BaseBuilder* fact){
51 readdBuilder(elem, fact);
52 return addLoader(name_, elem, fact);
55 template <
class NewBase>
59 bool addLoader(
const std::string& elemlib,
const std::string& elem,
BaseBuilder* fact);
61 std::map<std::string, BaseBuilder*> factories_;
66 template <
class Base,
class... CtorArgs>
71 using Map=std::map<std::string,Library*>;
73 static Library* getLibrary(
const std::string& name){
75 libraries =
new std::map<std::string,Library*>;
77 auto iter = libraries->find(name);
78 if (iter == libraries->end()){
80 (*libraries)[name] = info;
87 template <
class NewBase>
92 static Map* libraries;
98 template <
class Base,
class... CtorArgs>
105 template <
class Base,
class T>
107 static bool isLoaded() {
111 static const bool loaded;
115 = Base::Ctor::template add<T>();
117 template <
class Base,
class T,
class Enable=
void>
120 template <
class... Args>
121 T* operator()(Args&&... args){
122 return new T(std::forward<Args>(args)...);
126 template <
class Base,
class T>
129 template <
class... Args>
130 Base* operator()(Args&&... ctorArgs) {
132 cached_ =
new T(std::forward<Args>(ctorArgs)...);
137 static Base* cached_;
139 template <
class Base,
class T>
142 template <
class T,
class Base,
class... Args>
145 Base* create(Args... ctorArgs)
override {
151 template <
class T,
class U>
154 template <
class T,
class... Args>
156 public std::is_constructible<T, Args...>
161 template <
class T,
class... Args>
162 static BuilderLibrary<T,Args...>* getLibrary(
const std::string& name){
167 template <
class Base,
class CtorTuple>
170 template <
class Base,
class... Args>
173 static BuilderLibrary<Base,Args...>* getLibrary(
const std::string& name){
177 template <
class T>
static Builder<Base,Args...>* makeBuilder(){
183 template <
class NewCtor,
class OldCtor>
186 template <
class T>
static bool add(){
188 return NewCtor::template add<T>() && OldCtor::template add<T>();
191 template <
class __NewCtor>
194 template <
class NewBase>
195 using ChangeBase =
typename NewCtor::template ChangeBase<NewBase>;
198 template <
class Base,
class... Args>
201 template <
class T>
static bool add(){
204 return Base::addBuilder(T::ELI_getLibrary(),T::ELI_getName(),fact);
207 template <
class NewBase>
210 template <
class NewCtor>
215 template <
class Base,
class Ctor,
class... Ctors>
218 template <
class T,
int NumVal
id=0,
class U=T>
223 Base::addBuilder(T::ELI_getLibrary(),T::ELI_getName(),fact);
224 return CtorList<Base,Ctors...>::template add<T,NumValid+1>();
227 template <
class T,
int NumVal
id=0,
class U=T>
230 return CtorList<Base,Ctors...>::template add<T,NumValid>();
233 template <
class NewBase>
238 template <
int NumVal
id>
240 static constexpr
bool atLeastOneValidCtor =
true;
247 template <
class T,
int numVal
idCtors>
256 #define ELI_CTOR(...) std::tuple<__VA_ARGS__>
257 #define ELI_DEFAULT_CTOR() std::tuple<>
259 #define SST_ELI_CTORS_COMMON(...) \
260 using Ctor = ::SST::ELI::CtorList<__LocalEliBase,__VA_ARGS__,void>; \
261 template <class __TT, class... __CtorArgs> \
262 using DerivedBuilder = ::SST::ELI::DerivedBuilder<__LocalEliBase,__TT,__CtorArgs...>; \
263 template <class... __InArgs> static SST::ELI::BuilderLibrary<__LocalEliBase,__InArgs...>* \
264 getBuilderLibraryTemplate(const std::string& name){ \
265 return ::SST::ELI::BuilderDatabase::getLibrary<__LocalEliBase,__InArgs...>(name); \
267 template <class __TT> static bool addDerivedBuilder(const std::string& lib, const std::string& elem){ \
268 return Ctor::template add<0,__TT>(lib,elem); \
271 #define SST_ELI_DECLARE_CTORS(...) \
272 SST_ELI_CTORS_COMMON(ELI_FORWARD_AS_ONE(__VA_ARGS__)) \
273 template <class... Args> static bool addBuilder(const std::string& elemlib, const std::string& elem, \
274 SST::ELI::Builder<__LocalEliBase,Args...>* builder){ \
275 return getBuilderLibraryTemplate<Args...>(elemlib)->addBuilder(elem, builder); \
278 #define SST_ELI_DECLARE_CTORS_EXTERN(...) \
279 SST_ELI_CTORS_COMMON(ELI_FORWARD_AS_ONE(__VA_ARGS__))
284 #define SST_ELI_BUILDER_TYPEDEFS(...) \
285 using BaseBuilder = ::SST::ELI::Builder<__VA_ARGS__>; \
286 using BuilderLibrary = ::SST::ELI::BuilderLibrary<__VA_ARGS__>; \
287 using BuilderLibraryDatabase = ::SST::ELI::BuilderLibraryDatabase<__VA_ARGS__>; \
288 template <class __TT> using DerivedBuilder = ::SST::ELI::DerivedBuilder<__TT,__VA_ARGS__>;
290 #define SST_ELI_BUILDER_FXNS() \
291 static BuilderLibrary* getBuilderLibrary(const std::string& name){ \
292 return BuilderLibraryDatabase::getLibrary(name); \
294 static bool addBuilder(const std::string& elemlib, const std::string& elem, BaseBuilder* builder){ \
295 return getBuilderLibrary(elemlib)->addBuilder(elem,builder); \
299 #define SST_ELI_DECLARE_CTOR(...) \
300 using Ctor = ::SST::ELI::SingleCtor<__LocalEliBase,__VA_ARGS__>; \
301 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase,__VA_ARGS__) \
302 SST_ELI_BUILDER_FXNS()
304 #define SST_ELI_BUILDER_FXNS_EXTERN() \
305 static BuilderLibrary* getBuilderLibrary(const std::string& name); \
306 static bool addBuilder(const std::string& elemlib, const std::string& elem, BaseBuilder* builder);
308 #define SST_ELI_DECLARE_CTOR_EXTERN(...) \
309 using Ctor = ::SST::ELI::SingleCtor<__LocalEliBase,__VA_ARGS__>; \
310 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase,__VA_ARGS__); \
311 SST_ELI_BUILDER_FXNS_EXTERN()
313 #define SST_ELI_DEFINE_CTOR_EXTERN(base) \
314 bool base::addBuilder(const std::string& elemlib, const std::string& elem, BaseBuilder* builder){ \
315 return getBuilderLibrary(elemlib)->addBuilder(elem,builder); \
317 base::BuilderLibrary* base::getBuilderLibrary(const std::string& elemlib){ \
318 return BuilderLibraryDatabase::getLibrary(elemlib); \
322 #define SST_ELI_DECLARE_DEFAULT_CTOR() \
323 using Ctor = ::SST::ELI::SingleCtor<__LocalEliBase>; \
324 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase) \
325 SST_ELI_BUILDER_FXNS()
327 #define SST_ELI_DECLARE_DEFAULT_CTOR_EXTERN() \
328 SST_ELI_DEFAULT_CTOR_COMMON() \
329 SST_ELI_BUILDER_FXNS_EXTERN()
331 #define SST_ELI_EXTEND_CTOR() \
332 using Ctor = ::SST::ELI::ExtendedCtor<LocalCtor, __ParentEliBase::Ctor>;
334 #define SST_ELI_SAME_BASE_CTOR() \
335 using LocalCtor = __ParentEliBase::Ctor::ChangeBase<__LocalEliBase>; \
336 SST_ELI_EXTEND_CTOR() \
337 using BaseBuilder = typename __ParentEliBase::BaseBuilder::template ChangeBase<__LocalEliBase>; \
338 using BuilderLibrary = __ParentEliBase::BuilderLibrary::ChangeBase<__LocalEliBase>; \
339 using BuilderLibraryDatabase = __ParentEliBase::BuilderLibraryDatabase::ChangeBase<__LocalEliBase>; \
340 SST_ELI_BUILDER_FXNS()
342 #define SST_ELI_NEW_BASE_CTOR(...) \
343 using LocalCtor = ::SST::ELI::SingleCtor<__LocalEliBase,__VA_ARGS__>; \
344 SST_ELI_EXTEND_CTOR() \
345 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase, __VA_ARGS__) \
346 SST_ELI_BUILDER_FXNS()
348 #define SST_ELI_DEFAULT_BASE_CTOR() \
349 using LocalCtor = ::SST::ELI::SingleCtor<__LocalEliBase>; \
350 SST_ELI_EXTEND_CTOR() \
351 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase) \
352 SST_ELI_BUILDER_FXNS()
static bool addLoader(const std::string &lib, const std::string &name, std::function< void()> &&loader)
Definition: elibase.cc:32
Definition: elementbuilder.h:152
Definition: elementbuilder.h:168
Definition: elementbuilder.h:216
Definition: elementbuilder.h:23
Definition: elementbuilder.h:143
Definition: elementbuilder.h:160
Definition: elementbuilder.h:239
Definition: elementbuilder.h:118
Definition: elementbuilder.h:106
Definition: elementbuilder.h:67
Definition: elementbuilder.h:199
Definition: elementbuilder.h:12
Definition: elementbuilder.h:184
Definition: elementbuilder.h:127