Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef RVE_PLUGINLOADER_TYPE_REGISTRY_H
00031 #define RVE_PLUGINLOADER_TYPE_REGISTRY_H
00032
00033 #include <list>
00034 #include <map>
00035
00036 #include <boost/shared_ptr.hpp>
00037
00038 #include "class_entry.h"
00039
00040 namespace rve_pluginloader
00041 {
00042
00043 class ClassCreator
00044 {
00045 public:
00046 virtual ~ClassCreator() {}
00047 virtual void* create() const = 0;
00048 virtual void destroy(void*) const = 0;
00049 };
00050
00051 template<typename T>
00052 class ClassCreatorT : public ClassCreator
00053 {
00054 public:
00055 virtual void* create() const
00056 {
00057 return new T;
00058 }
00059
00060 virtual void destroy(void* v) const
00061 {
00062 delete reinterpret_cast<T*>(v);
00063 }
00064
00065 };
00066 typedef boost::shared_ptr<ClassCreator> ClassCreatorPtr;
00067
00068 class TypeRegistry
00069 {
00070 public:
00071 TypeRegistry(const std::string& package)
00072 : package_(package)
00073 {}
00074
00075 const M_ClassEntry& getClassEntries() const { return class_entries_; }
00076
00077 template<class T>
00078 void registerClass(const std::string& class_type, const std::string& class_name, const std::string& readable_name)
00079 {
00080 ClassCreatorPtr creator(new ClassCreatorT<T>);
00081 ClassEntryPtr ent(new ClassEntry);
00082 ent->creator = creator;
00083 ent->class_name = class_name;
00084 ent->readable_name = readable_name;
00085 ent->package = package_;
00086 ent->base_class_name = class_type;
00087 class_entries_[class_type].push_back(ent);
00088 }
00089
00090 private:
00091 M_ClassEntry class_entries_;
00092 std::string package_;
00093 };
00094
00095 }
00096
00097 #endif