18 template<
typename ObjectType>
21 ObjectType* (*_create)();
29 virtual void Destroy(ObjectType *objptr){(*_destroy)(objptr); };
35 template<
typename ObjectType>
42 virtual dlHandleType
Handle()
const {
return(this->second); };
43 virtual std::string
Name()
const {
return(this->first); };
44 virtual std::string
File()
const {
return(_path); };
45 virtual std::string &
Name() {
return(this->first); };
46 virtual std::string &
File() {
return(_path); };
47 virtual std::string
Error(){
return(std::string(dlerror())); };
52 ObjectType* retval =
static_cast<ObjectType*
>(NULL);
54 std::ostringstream Ostr;
55 Ostr <<
"create_" << objectname;
56 _factory.
SetCreate((ObjectType * (*)())dlsym(this->second,Ostr.str().c_str()));
58 retval = _factory.
Create();
62 virtual void DestroyObject(
const std::string &objectname,ObjectType *objptr)
65 std::ostringstream Ostr;
66 Ostr <<
"destroy_" << objectname;
67 _factory.
SetDestroy((
void (*)(ObjectType *))dlsym(this->second,Ostr.str().c_str()));
72 virtual int Load(
const std::string &name,
const std::string &path)
74 void *handle = dlopen(path.c_str(),RTLD_LAZY);
77 dlclose(this->second);
79 this->second = handle;
88 dlclose(this->second);
virtual void SetDestroy(void(*indestroy)(ObjectType *))
virtual ObjectType * Create()
virtual std::string & Name()
ObjectType *(* _create)()
virtual void Destroy(ObjectType *objptr)
virtual ~DynamicObjectLib()
Defines MPI-specific parallel global and program classes.
virtual int Load(const std::string &name, const std::string &path)
virtual ObjectType * CreateObject(const std::string &objectname)
virtual void SetCreate(ObjectType *(*increate)())
virtual ObjectType *(*)() CreatePtr()
virtual std::string Name() const
virtual ObjectFactory< ObjectType > & Factory()
virtual std::string & File()
virtual std::string Error()
virtual void DestroyObject(const std::string &objectname, ObjectType *objptr)
virtual dlHandleType Handle() const
virtual std::string File() const
virtual void(*)(ObjectType *) DestroyPtr()
ObjectFactory< ObjectType > _factory
virtual ObjectFactory< ObjectType > Factory() const
void(* _destroy)(ObjectType *)