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 Builder,
class... CtorArgs>
101 const std::string& elem,
103 elemlib_(elemlib), elem_(elem), builder_(builder)
107 void load()
override {
109 ->readdBuilder(elem_,builder_);
113 std::string elemlib_;
118 template <
class Base,
class... CtorArgs>
121 auto loader =
new BuilderLoader<Base,BaseBuilder,CtorArgs...>(elemlib, elem, fact);
125 template <
class Base,
class T>
127 static bool isLoaded() {
131 static const bool loaded;
135 = Base::Ctor::template add<T>();
137 template <
class Base,
class T,
class Enable=
void>
140 template <
class... Args>
141 T* operator()(Args&&... args){
142 return new T(std::forward<Args>(args)...);
146 template <
class Base,
class T>
149 template <
class... Args>
150 Base* operator()(Args&&... ctorArgs) {
152 cached_ =
new T(std::forward<Args>(ctorArgs)...);
157 static Base* cached_;
159 template <
class Base,
class T>
162 template <
class T,
class Base,
class... Args>
165 Base* create(Args... ctorArgs)
override {
171 template <
class T,
class U>
174 template <
class T,
class... Args>
176 public std::is_constructible<T, Args...>
181 template <
class T,
class... Args>
182 static BuilderLibrary<T,Args...>* getLibrary(
const std::string& name){
187 template <
class Base,
class CtorTuple>
190 template <
class Base,
class... Args>
193 static BuilderLibrary<Base,Args...>* getLibrary(
const std::string& name){
197 template <
class T>
static Builder<Base,Args...>* makeBuilder(){
203 template <
class NewCtor,
class OldCtor>
206 template <
class T>
static bool add(){
208 return NewCtor::template add<T>() && OldCtor::template add<T>();
211 template <
class __NewCtor>
214 template <
class NewBase>
215 using ChangeBase =
typename NewCtor::template ChangeBase<NewBase>;
218 template <
class Base,
class... Args>
221 template <
class T>
static bool add(){
224 return Base::addBuilder(T::ELI_getLibrary(),T::ELI_getName(),fact);
227 template <
class NewBase>
230 template <
class NewCtor>
235 template <
class Base,
class Ctor,
class... Ctors>
238 template <
class T,
int NumVal
id=0,
class U=T>
243 Base::addBuilder(T::ELI_getLibrary(),T::ELI_getName(),fact);
244 return CtorList<Base,Ctors...>::template add<T,NumValid+1>();
247 template <
class T,
int NumVal
id=0,
class U=T>
250 return CtorList<Base,Ctors...>::template add<T,NumValid>();
253 template <
class NewBase>
258 template <
int NumVal
id>
260 static constexpr
bool atLeastOneValidCtor =
true;
267 template <
class T,
int numVal
idCtors>
276 #define ELI_CTOR(...) std::tuple<__VA_ARGS__>
277 #define ELI_DEFAULT_CTOR() std::tuple<>
279 #define SST_ELI_CTORS_COMMON(...) \
280 using Ctor = ::SST::ELI::CtorList<__LocalEliBase,__VA_ARGS__,void>; \
281 template <class __TT, class... __CtorArgs> \
282 using DerivedBuilder = ::SST::ELI::DerivedBuilder<__LocalEliBase,__TT,__CtorArgs...>; \
283 template <class... __InArgs> static SST::ELI::BuilderLibrary<__LocalEliBase,__InArgs...>* \
284 getBuilderLibraryTemplate(const std::string& name){ \
285 return ::SST::ELI::BuilderDatabase::getLibrary<__LocalEliBase,__InArgs...>(name); \
287 template <class __TT> static bool addDerivedBuilder(const std::string& lib, const std::string& elem){ \
288 return Ctor::template add<0,__TT>(lib,elem); \
291 #define SST_ELI_DECLARE_CTORS(...) \
292 SST_ELI_CTORS_COMMON(ELI_FORWARD_AS_ONE(__VA_ARGS__)) \
293 template <class... Args> static bool addBuilder(const std::string& elemlib, const std::string& elem, \
294 SST::ELI::Builder<__LocalEliBase,Args...>* builder){ \
295 return getBuilderLibraryTemplate<Args...>(elemlib)->addBuilder(elem, builder); \
298 #define SST_ELI_DECLARE_CTORS_EXTERN(...) \
299 SST_ELI_CTORS_COMMON(ELI_FORWARD_AS_ONE(__VA_ARGS__))
304 #define SST_ELI_BUILDER_TYPEDEFS(...) \
305 using BaseBuilder = ::SST::ELI::Builder<__VA_ARGS__>; \
306 using BuilderLibrary = ::SST::ELI::BuilderLibrary<__VA_ARGS__>; \
307 using BuilderLibraryDatabase = ::SST::ELI::BuilderLibraryDatabase<__VA_ARGS__>; \
308 template <class __TT> using DerivedBuilder = ::SST::ELI::DerivedBuilder<__TT,__VA_ARGS__>;
310 #define SST_ELI_BUILDER_FXNS() \
311 static BuilderLibrary* getBuilderLibrary(const std::string& name){ \
312 return BuilderLibraryDatabase::getLibrary(name); \
314 static bool addBuilder(const std::string& elemlib, const std::string& elem, BaseBuilder* builder){ \
315 return getBuilderLibrary(elemlib)->addBuilder(elem,builder); \
319 #define SST_ELI_DECLARE_CTOR(...) \
320 using Ctor = ::SST::ELI::SingleCtor<__LocalEliBase,__VA_ARGS__>; \
321 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase,__VA_ARGS__) \
322 SST_ELI_BUILDER_FXNS()
324 #define SST_ELI_BUILDER_FXNS_EXTERN() \
325 static BuilderLibrary* getBuilderLibrary(const std::string& name); \
326 static bool addBuilder(const std::string& elemlib, const std::string& elem, BaseBuilder* builder);
328 #define SST_ELI_DECLARE_CTOR_EXTERN(...) \
329 using Ctor = ::SST::ELI::SingleCtor<__LocalEliBase,__VA_ARGS__>; \
330 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase,__VA_ARGS__); \
331 SST_ELI_BUILDER_FXNS_EXTERN()
333 #define SST_ELI_DEFINE_CTOR_EXTERN(base) \
334 bool base::addBuilder(const std::string& elemlib, const std::string& elem, BaseBuilder* builder){ \
335 return getBuilderLibrary(elemlib)->addBuilder(elem,builder); \
337 base::BuilderLibrary* base::getBuilderLibrary(const std::string& elemlib){ \
338 return BuilderLibraryDatabase::getLibrary(elemlib); \
342 #define SST_ELI_DECLARE_DEFAULT_CTOR() \
343 using Ctor = ::SST::ELI::SingleCtor<__LocalEliBase>; \
344 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase) \
345 SST_ELI_BUILDER_FXNS()
347 #define SST_ELI_DECLARE_DEFAULT_CTOR_EXTERN() \
348 SST_ELI_DEFAULT_CTOR_COMMON() \
349 SST_ELI_BUILDER_FXNS_EXTERN()
351 #define SST_ELI_EXTEND_CTOR() \
352 using Ctor = ::SST::ELI::ExtendedCtor<LocalCtor, __ParentEliBase::Ctor>;
354 #define SST_ELI_SAME_BASE_CTOR() \
355 using LocalCtor = __ParentEliBase::Ctor::ChangeBase<__LocalEliBase>; \
356 SST_ELI_EXTEND_CTOR() \
357 using BaseBuilder = typename __ParentEliBase::BaseBuilder::template ChangeBase<__LocalEliBase>; \
358 using BuilderLibrary = __ParentEliBase::BuilderLibrary::ChangeBase<__LocalEliBase>; \
359 using BuilderLibraryDatabase = __ParentEliBase::BuilderLibraryDatabase::ChangeBase<__LocalEliBase>; \
360 SST_ELI_BUILDER_FXNS()
362 #define SST_ELI_NEW_BASE_CTOR(...) \
363 using LocalCtor = ::SST::ELI::SingleCtor<__LocalEliBase,__VA_ARGS__>; \
364 SST_ELI_EXTEND_CTOR() \
365 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase, __VA_ARGS__) \
366 SST_ELI_BUILDER_FXNS()
368 #define SST_ELI_DEFAULT_BASE_CTOR() \
369 using LocalCtor = ::SST::ELI::SingleCtor<__LocalEliBase>; \
370 SST_ELI_EXTEND_CTOR() \
371 SST_ELI_BUILDER_TYPEDEFS(__LocalEliBase) \
372 SST_ELI_BUILDER_FXNS()
Definition: elementbuilder.h:172
Definition: elementbuilder.h:188
Definition: elementbuilder.h:99
Definition: elementbuilder.h:236
Definition: elementbuilder.h:23
Definition: elementbuilder.h:163
Definition: elementbuilder.h:180
Definition: elementbuilder.h:259
Definition: elibase.h:107
Definition: elementbuilder.h:138
Definition: elementbuilder.h:126
Definition: elementbuilder.h:67
Definition: elementbuilder.h:219
Definition: elementbuilder.h:12
Definition: elementbuilder.h:204
Definition: elementbuilder.h:147
static bool addLoader(const std::string &lib, const std::string &name, LibraryLoader *loader)
Definition: elibase.cc:32