cisst-saw
Loading...
Searching...
No Matches
osaDynamicLoaderAndFactory.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5
6 Author(s): Peter Kazanzides
7 Created on: 2007-01-16
8
9 (C) Copyright 2007-2007 Johns Hopkins University (JHU), All Rights
10 Reserved.
11
12--- begin cisst license - do not edit ---
13
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://www.cisst.org/cisst/license.txt.
17
18--- end cisst license ---
19*/
20
21
26
27#ifndef _osaDynamicLoaderAndFactory_h
28#define _osaDynamicLoaderAndFactory_h
29
30#include <typeinfo>
33
34// This class serves as the base class for osaDynamicLoaderAndFactory and is not
35// intended to be accessed otherwise. Note that the constructor is protected.
37{
38protected:
39 void* create;
40 void* destroy;
41
43 bool Init(const char* name, const char* file, const char* path,
44 const std::type_info& tinfo, int version);
45
46public:
48
49 void Reset();
50};
51
73
74template <class BaseClass>
76{
77 typedef BaseClass* CreateFunc();
78 typedef void DestroyFunc(BaseClass*);
79
80public:
86
96 bool Init(const char *name, const char *file, const char *path = 0)
97 { return osaDynamicLoaderAndFactoryBase::Init(name, file, path, typeid(BaseClass), BaseClass::VERSION); }
98
104 bool Init(const char* name)
105 { return osaDynamicLoaderAndFactoryBase::Init(name, name, 0, typeid(BaseClass), BaseClass::VERSION); }
106
112
115 BaseClass* CreateObject() const
116 { return create ? (*(reinterpret_cast<CreateFunc*>(create)))() : 0; }
117
121 void DestroyObject(BaseClass* obj) const
122 { if (destroy) (*reinterpret_cast<DestroyFunc*>(destroy))(obj); }
123};
124
125
126#endif // _osaDynamicLoaderAndFactory_h
virtual ~osaDynamicLoaderAndFactoryBase()
Definition osaDynamicLoaderAndFactory.h:47
void * create
Definition osaDynamicLoaderAndFactory.h:39
void * destroy
Definition osaDynamicLoaderAndFactory.h:40
osaDynamicLoaderAndFactoryBase()
Definition osaDynamicLoaderAndFactory.h:42
bool Init(const char *name, const char *file, const char *path, const std::type_info &tinfo, int version)
osaDynamicLoaderAndFactory()
Definition osaDynamicLoaderAndFactory.h:82
void DestroyObject(BaseClass *obj) const
Definition osaDynamicLoaderAndFactory.h:121
virtual ~osaDynamicLoaderAndFactory()
Definition osaDynamicLoaderAndFactory.h:85
bool Init(const char *name)
Definition osaDynamicLoaderAndFactory.h:104
void Reset()
Definition osaDynamicLoaderAndFactory.h:110
BaseClass * CreateObject() const
Definition osaDynamicLoaderAndFactory.h:115
bool Init(const char *name, const char *file, const char *path=0)
Definition osaDynamicLoaderAndFactory.h:96
osaDynamicLoader()
Definition osaDynamicLoader.h:60
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Declaration of osaDynamicLoader.
Macros to export the symbols of cisstOSAbstraction (in a Dll).