1 #ifndef CORE_ClassFactory_H
2 #define CORE_ClassFactory_H
11 #include "CORE_Object.h"
14 #include "shared_pointer.h"
17 #include "CORE_OptionsList.h"
39 std::vector<CORE_UniquePointer<CORE_ClassFactory> > mFactoryClasses;
86 std::for_each(mFactoryClasses.cbegin(),mFactoryClasses.cend(),
87 [&](
const auto& cf) {mem+=cf->getMemorySize();});
98 mFactoryClasses.push_back(std::move(child));
106 mFactoryClasses.clear();
116 inline static CORE_UniquePointer<CORE_ClassFactory>
New() {
129 virtual CORE_UniquePointer<CORE_Object>
NewInstance(
const tString& name,
137 inline CORE_UniquePointer<CORE_Object>
NewInstance(
const tString& name)
const {
152 return shared_pointer::dynamic_up_cast<T>(
NewInstance(name,arguments));
161 inline CORE_UniquePointer<T>
NewInstance(
const tString& name)
const {
163 return NewInstance<T>(name,nullArguments);
176 CORE_UniquePointer<T> up=NewInstance<T>(name,arguments);
177 if (up.get()!=
null)
return up->setThis(up);
179 CORE_UniquePointer<T> nullPtr;
191 return NewSharedPointer<T>(name,nullArguments);
200 return NewSharedPointer<T>(nullArguments);
209 return NewSharedPointer<T>(functions_type::getTypeName<T>(),arguments);
218 if (up.get()==
null) {
219 CORE_SharedPointer<T> nullPtr;
222 return up->setThis(up);
230 if (up.get()!=
null)
return up->setThis(up);
231 CORE_SharedPointer<T> nullPtr;
241 std::stringstream ret;
243 std::vector<CORE_UniquePointer<CORE_ClassFactory> >::const_iterator iter=mFactoryClasses.begin();
244 std::vector<CORE_UniquePointer<CORE_ClassFactory> >::const_iterator iterE=mFactoryClasses.end();
245 while (iter!=iterE) {
247 ret<<
"\t"<<(*iter)->getIdentityString()<<
"\n";
264 #define NewUniquePointer NewInstance
265 #define NewUniqueInstance NewInstance
266 #define NewSharedInstance NewSharedPointer
this class describes a class factory to generate classes
Definition: CORE_ClassFactory.h:24
virtual CORE_UniquePointer< CORE_Object > NewInstance(const tString &name, const CORE_OptionsList &arguments) const
create an unique instance of a class as a general CORE_Object
Definition: CORE_ClassFactory.cpp:18
CORE_ClassFactory()
build a CORE_ClassFactory
Definition: CORE_ClassFactory.cpp:11
CORE_UniquePointer< T > NewInstance(const tString &name, const CORE_OptionsList &arguments) const
create an unique instance of a class T
Definition: CORE_ClassFactory.h:150
static CORE_SharedPointer< T > NewSharedPointer(CORE_UniquePointer< T > &up)
create a shared instance of an unique pointer
Definition: CORE_ClassFactory.h:217
CORE_SharedPointer< T > NewSharedPointer(const tString &name) const
create a shared instance of a class with no argument
Definition: CORE_ClassFactory.h:189
virtual ~CORE_ClassFactory(void)
destroy a CORE_ClassFactory
Definition: CORE_ClassFactory.cpp:15
virtual tMemSize getContentsMemorySize() const override
return the memory size in byte
Definition: CORE_ClassFactory.h:84
CORE_SharedPointer< T > NewSharedPointer(const CORE_OptionsList &arguments) const
create a shared instance of a class with same type as T
Definition: CORE_ClassFactory.h:208
static CORE_UniquePointer< CORE_ClassFactory > New()
build a new instance of default class factory
Definition: CORE_ClassFactory.h:116
CORE_UniquePointer< CORE_Object > NewInstance(const tString &name) const
create an unique instance of a class as a general CORE_Object
Definition: CORE_ClassFactory.h:137
virtual tMemSize getMemorySize() const override
return the memory size of the class and the memory size of all its attributes/associations
Definition: CORE_ClassFactory.h:72
static CORE_SharedPointer< T > NewSharedPointer(CORE_UniquePointer< T > &&up)
create a shared instance of an unique pointer as a lvalue
Definition: CORE_ClassFactory.h:229
CORE_UniquePointer< T > NewInstance(const tString &name) const
create an unique instance of a class T with no arguments
Definition: CORE_ClassFactory.h:161
void clearClassFactories()
clear the class factories list
Definition: CORE_ClassFactory.h:105
virtual tString toString() const override
get the string representation of the class
Definition: CORE_ClassFactory.h:239
CORE_SharedPointer< T > NewSharedPointer(const tString &name, const CORE_OptionsList &arguments) const
create a shared instance of a class
Definition: CORE_ClassFactory.h:174
CORE_SharedPointer< T > NewSharedPointer() const
create a shared instance of a class with same type as T with no argument
Definition: CORE_ClassFactory.h:198
void addClassFactory(CORE_UniquePointer< CORE_ClassFactory > child)
add to class factory
Definition: CORE_ClassFactory.h:97
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
abstract base class for most classes.
Definition: CORE_Object.h:65
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
tString getIdentityString() const
retrun the string identification of the class
Definition: CORE_Object.h:321
This class is an list of options.
Definition: CORE_OptionsList.h:36