Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

loader.hh

Go to the documentation of this file.
00001 #ifndef _loader_hh_
00002 #define _loader_hh_
00003 
00004 #include <string>
00005 #include "base.hh"
00006 #include "configuration.hh"
00007 #include "stringhash.hh"
00008 
00009 namespace anoid {
00011     namespace loader {
00012 
00013         class RegisterBase;
00014 
00015         struct DynamicLoadableModuleInfo {
00016             const std::string name;
00017             std::string location;
00018             std::list<std::string> requires;
00019             DynamicLoadableModuleInfo(const std::string& n, const std::string &l): name(n), location(l) {};
00020         };
00021 
00022         struct ClassInfo {
00023             const RegisterBase *const factory;
00024             int count;
00025             ClassInfo(const RegisterBase *const f): factory(f), count(0) {};
00026         };
00027 
00028         class Loader {
00029             private:
00030                 hash_map<const std::string, RegisterBase*> factoryMap;
00031                 hash_map<const std::string, DynamicLoadableModuleInfo *> modules;
00032                 hash_map<const std::string, void *> DLLMap;
00033 
00034                 void associate(const std::string &name, RegisterBase *factory);
00035                 void disassociate(const std::string &name);
00036 
00037                 void load(const std::string &name);
00038                 void unload(const std::string &name);
00039             public:
00040                 Loader();
00041                 ~Loader();
00042 
00043                 Base *getInstance(const std::string &name);
00044                 void includeInformation(config::Configuration &c);
00045 
00046                 friend class RegisterBase;
00047         };
00048 
00049         extern Loader loader;
00050     };
00051 };
00052 
00053 template <class T>
00054 inline T* New(const std::string &name) {
00055     anoid::loader::Base *tmp = anoid::loader::loader.getInstance(name);
00056     return static_cast<T *>(tmp);
00057 /*  T *tmp2 = dynamic_cast<T *>(tmp);
00058 
00059     if (tmp2) return tmp2;
00060 
00061     delete tmp;
00062     return 0;*/
00063 }
00064 
00065 #endif

Anoid NG © Michael Westergaard, Martin Stig Stissing, Ronni Michael Laursen, and Kristian Bisgaard Lassen