#include <ClassLoader.h>
Classes | |
class | Iterator |
The ClassLoader's very own iterator class. More... | |
struct | LibraryInfo |
Public Types | |
typedef bool(* | BuildManifestFunc )(ManifestBase *) |
typedef void(* | InitializeLibraryFunc )() |
typedef std::map< std::string, LibraryInfo > | LibraryMap |
typedef Manifest< Base > | Manif |
typedef std::pair< const Manif *, std::string > | manifest_pair |
typedef AbstractMetaObject< Base > | Meta |
typedef void(* | UninitializeLibraryFunc )() |
Public Member Functions | |
Iterator | begin () const |
bool | canCreate (const std::string &className) const |
const Meta & | classFor (const std::string &className) const |
ClassLoader () | |
Creates the ClassLoader. | |
Base * | create (const std::string &className) const |
void | destroy (const std::string &className, Base *pObject) const |
Iterator | end () const |
const Meta * | findClass (const std::string &className) const |
std::vector< manifest_pair > | findManifest (const std::string &path) const |
Base & | instance (const std::string &className) const |
bool | isAutoDelete (const std::string &className, Base *pObject) const |
bool | isLibraryLoaded (const std::string &path) const |
void | loadLibrary (const std::string &path) |
void | loadLibrary (const std::string &path, const std::string &manifest) |
const Manif & | manifestFor (const std::string &path) const |
void | unloadLibrary (const std::string &path) |
virtual | ~ClassLoader () |
Destroys the ClassLoader. | |
Private Attributes | |
LibraryMap | _map |
FastMutex | _mutex |
The ClassLoader loads C++ classes from shared libraries at runtime. It must be instantiated with a root class of the loadable classes. For a class to be loadable from a library, the library must provide a Manifest of all the classes it contains. The Manifest for a shared library can be easily built with the help of the macros in the header file "Foundation/ClassLibrary.h".
Starting with POCO release 1.3, a class library can export multiple manifests. In addition to the default (unnamed) manifest, multiple named manifests can be exported, each having a different base class.
There is one important restriction: one instance of ClassLoader can only load one manifest from a class library.
Definition at line 56 of file ClassLoader.h.
typedef bool(* Poco::ClassLoader< Base >::BuildManifestFunc)(ManifestBase *) |
Definition at line 80 of file ClassLoader.h.
typedef void(* Poco::ClassLoader< Base >::InitializeLibraryFunc)() |
Definition at line 78 of file ClassLoader.h.
typedef std::map<std::string, LibraryInfo> Poco::ClassLoader< Base >::LibraryMap |
Definition at line 90 of file ClassLoader.h.
typedef Manifest<Base> Poco::ClassLoader< Base >::Manif |
Definition at line 77 of file ClassLoader.h.
typedef std::pair<const Manif*, std::string> Poco::ClassLoader< Base >::manifest_pair |
Definition at line 82 of file ClassLoader.h.
typedef AbstractMetaObject<Base> Poco::ClassLoader< Base >::Meta |
Definition at line 76 of file ClassLoader.h.
typedef void(* Poco::ClassLoader< Base >::UninitializeLibraryFunc)() |
Definition at line 79 of file ClassLoader.h.
Poco::ClassLoader< Base >::ClassLoader | ( | ) | [inline] |
Creates the ClassLoader.
Definition at line 151 of file ClassLoader.h.
virtual Poco::ClassLoader< Base >::~ClassLoader | ( | ) | [inline, virtual] |
Destroys the ClassLoader.
Definition at line 156 of file ClassLoader.h.
Iterator Poco::ClassLoader< Base >::begin | ( | ) | const [inline] |
Definition at line 425 of file ClassLoader.h.
bool Poco::ClassLoader< Base >::canCreate | ( | const std::string & | className | ) | const [inline] |
Returns true if create() can create new instances of the class.
Definition at line 373 of file ClassLoader.h.
const Meta& Poco::ClassLoader< Base >::classFor | ( | const std::string & | className | ) | const [inline] |
Returns a reference to the MetaObject for the given class. Throws a NotFoundException if the class is not known.
Definition at line 343 of file ClassLoader.h.
Base* Poco::ClassLoader< Base >::create | ( | const std::string & | className | ) | const [inline] |
Creates an instance of the given class. Throws a NotFoundException if the class is not known.
Definition at line 355 of file ClassLoader.h.
void Poco::ClassLoader< Base >::destroy | ( | const std::string & | className, | |
Base * | pObject | |||
) | const [inline] |
Destroys the object pObject points to. Does nothing if object is not found.
Definition at line 380 of file ClassLoader.h.
Iterator Poco::ClassLoader< Base >::end | ( | ) | const [inline] |
Definition at line 432 of file ClassLoader.h.
const Meta* Poco::ClassLoader< Base >::findClass | ( | const std::string & | className | ) | const [inline] |
Returns a pointer to the MetaObject for the given class, or a null pointer if the class is not known.
Definition at line 323 of file ClassLoader.h.
std::vector<manifest_pair> Poco::ClassLoader< Base >::findManifest | ( | const std::string & | path | ) | const [inline] |
Returns a pointer to the Manifest for the given library, or a null pointer if the library has not been loaded.
Definition at line 394 of file ClassLoader.h.
Base& Poco::ClassLoader< Base >::instance | ( | const std::string & | className | ) | const [inline] |
Returns a reference to the sole instance of the given class. The class must be a singleton, otherwise an InvalidAccessException will be thrown. Throws a NotFoundException if the class is not known.
Definition at line 363 of file ClassLoader.h.
bool Poco::ClassLoader< Base >::isAutoDelete | ( | const std::string & | className, | |
Base * | pObject | |||
) | const [inline] |
Returns true if the object is automatically deleted by its meta object.
Definition at line 387 of file ClassLoader.h.
bool Poco::ClassLoader< Base >::isLibraryLoaded | ( | const std::string & | path | ) | const [inline] |
Returns true if the library with the given name has already been loaded.
Definition at line 418 of file ClassLoader.h.
void Poco::ClassLoader< Base >::loadLibrary | ( | const std::string & | path | ) | [inline] |
Loads a library from the given path. Does nothing if the library is already loaded. Throws a LibraryLoadException if the library cannot be loaded or does not have a Manifest. If the library exports a function named "pocoInitializeLibrary", this function is executed. If called multiple times for the same library, the number of calls to unloadLibrary() must be the same for the library to become unloaded.
Equivalent to loadLibrary(path, "").
Definition at line 269 of file ClassLoader.h.
void Poco::ClassLoader< Base >::loadLibrary | ( | const std::string & | path, | |
const std::string & | manifest | |||
) | [inline] |
Loads a library from the given path, using the given manifest. Does nothing if the library is already loaded. Throws a LibraryLoadException if the library cannot be loaded or does not have a Manifest. If the library exports a function named "pocoInitializeLibrary", this function is executed. If called multiple times for the same library, the number of calls to unloadLibrary() must be the same for the library to become unloaded.
Definition at line 169 of file ClassLoader.h.
const Manif& Poco::ClassLoader< Base >::manifestFor | ( | const std::string & | path | ) | const [inline] |
Returns a reference to the Manifest for the given library Throws a NotFoundException if the library has not been loaded.
Definition at line 407 of file ClassLoader.h.
void Poco::ClassLoader< Base >::unloadLibrary | ( | const std::string & | path | ) | [inline] |
Unloads the given library. Be extremely cautious when unloading shared libraries. If objects from the library are still referenced somewhere, a total crash is very likely. If the library exports a function named "pocoUninitializeLibrary", this function is executed before it is unloaded. If loadLibrary() has been called multiple times for the same library, the number of calls to unloadLibrary() must be the same for the library to become unloaded.
Definition at line 285 of file ClassLoader.h.
LibraryMap Poco::ClassLoader< Base >::_map [private] |
Definition at line 440 of file ClassLoader.h.
FastMutex Poco::ClassLoader< Base >::_mutex [mutable, private] |
Definition at line 441 of file ClassLoader.h.