00001
00002
00003
00004
00005
00006 #ifndef DYNAMICOBJECT_H
00007 #define DYNAMICOBJECT_H
00008
00009 #include<Class.h>
00010 #include<RefCount.h>
00011
00012 #include<string>
00013 #include<map>
00014 #include<iostream>
00015
00016 class Mutex;
00017 class Token;
00018
00019 #define DYNAMIC_OBJECT \
00020 private: static Class classObject; \
00021 public: static Class& myClass() { return classObject; }; \
00022 virtual Class& getClass() { return classObject; };
00023
00024 #define IMPLEMENT_DYNAMIC(CLASS, SUPER) \
00025 static DynamicObject *create##CLASS() { \
00026 return new CLASS; \
00027 } \
00028 Class CLASS::classObject(#CLASS, #SUPER, create##CLASS);
00029
00030 #define IMPLEMENT_SINGLETON(CLASS, SUPER) \
00031 static CLASS instance; \
00032 static DynamicObject *create##CLASS() { \
00033 return &instance; \
00034 } \
00035 Class CLASS::classObject(#CLASS, #SUPER, create##CLASS);
00036
00037 using namespace std;
00038
00039 class ObjectFile;
00040 class DynamicObject;
00041 typedef RefCount<DynamicObject> RefObject;
00042
00067 class DynamicObject
00068 {
00069 DYNAMIC_OBJECT;
00070
00071 public:
00073 static bool find(RefObject &object, const string &name);
00074
00076 static RefObject &store(RefObject &object, const string &name);
00077
00079 static RefObject readRefObject(const string className, ObjectFile &file);
00080
00081 virtual ~DynamicObject();
00082
00084 const string &className() {
00085 return getClass().name();
00086 }
00088 bool isKindOf(const string aClass) {
00089 return getClass().isKindOf(aClass);
00090 }
00092 bool isKindOf(Class &aClass) {
00093 return getClass().isKindOf(&aClass);
00094 }
00095
00097 void read(ObjectFile &file);
00098
00100 void write(ostream &stream);
00101
00104 void readParams(ObjectFile &file);
00105
00108 virtual void writeParams(ostream &stream);
00109
00112 virtual void parseSymbol(Token &t, ObjectFile &file);
00113
00114 protected:
00117 virtual void createSymbols();
00118
00120 static Mutex mutex;
00121
00123 static map<string, RefObject> objectPool;
00124 };
00125
00126
00127
00131 ObjectFile &operator>>(ObjectFile &file, DynamicObject *&obj);
00132
00136 ObjectFile &operator>>(ObjectFile &file, RefObject &obj);
00137
00141 inline ostream &operator<<(ostream &stream, DynamicObject &obj)
00142 {
00143 obj.write(stream);
00144 return stream;
00145 }
00146 #endif