00001 /* 00002 File: Register.h 00003 00004 Function: Class registry 00005 00006 Author: Andrew Willmott 00007 */ 00008 00009 #ifndef __Register__ 00010 #define __Register__ 00011 00012 #include "cl/Basics.h" 00013 #include "cl/Array.h" 00014 00015 typedef UInt32 ClassID; 00016 typedef Void *(*ObjectCreator)(); 00017 00018 struct RegistryEntry 00019 { 00020 ClassID baseID; 00021 ClassID id; 00022 ObjectCreator creator; 00023 const Char *name; 00024 const Char *description; 00025 }; 00026 00027 typedef Array<RegistryEntry> ClassTable; 00028 00029 struct BaseEntry 00030 { 00031 ClassID baseID; 00032 ClassTable table; 00033 }; 00034 00035 typedef Array<BaseEntry> BaseTable; 00036 00037 class Register 00038 { 00039 public: 00040 Register( 00041 ClassID id, 00042 ObjectCreator creator, 00043 const Char *name = "untitled", 00044 const Char *description = 0 00045 ) { RegisterClass('none', id, creator, name, description); }; 00046 00047 Register( 00048 ClassID baseID, 00049 ClassID id, 00050 ObjectCreator creator, 00051 const Char *name = "untitled", 00052 const Char *description = 0 00053 ) { RegisterClass(baseID, id, creator, name, description); }; 00054 00055 00056 static Void RegisterClass( 00057 ClassID baseID, 00058 ClassID id, 00059 ObjectCreator creator, 00060 const Char *name = "untitled", 00061 const Char *description = 0 00062 ); 00063 00064 static Void *MakeObject(ClassID id); 00065 static Void *MakeObject(const Char *name); 00066 static Void *MakeObject(ClassID baseID, ClassID id); 00067 static Void *MakeObject(ClassID baseID, const Char *name); 00068 static Void ListObjects(); 00069 static Void ListObjects(ClassID baseID); 00070 00071 protected: 00072 static ClassTable *FindClassTable(ClassID baseID); 00073 static BaseTable *table; 00074 }; 00075 00076 #define MAKE_REGISTRAR(REGISTRAR, BASE_ID) \ 00077 class REGISTRAR : public Register \ 00078 { \ 00079 public: \ 00080 REGISTRAR( \ 00081 ClassID id, \ 00082 ObjectCreator creator, \ 00083 const Char *name = "untitled", \ 00084 const Char *description = 0 \ 00085 ) : Register(BASE_ID, id, creator, name, description) {}; \ 00086 } 00087 00088 #endif 00089