00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _uclass_hpp_
00020 #define _uclass_hpp_ 1
00021
00022 #include <ubit/ubrick.hpp>
00023 namespace ubit {
00024
00025 class UObject;
00026 class UStr;
00027
00028
00029
00030 #define UBIT_CLASS_DEF(CLASSTYPE, NAME, CLASS, PARENT, NEWCLASS, NEWSTYLE, MODES) \
00031 struct Class : public CLASSTYPE { \
00032 Class() : CLASSTYPE(NAME) {initClass();} \
00033 virtual bool isInstance(UObject& obj) const {return dynamic_cast<CLASS*>(&obj);} \
00034 virtual CLASS* newInstance() const {return NEWCLASS;} \
00035 virtual UStyle* newStyle() const {return NEWSTYLE;} \
00036 virtual UMask getModes() const {return MODES;} \
00037 };\
00038 static const CLASSTYPE& classid() {static Class& _cid_ = *new Class; return _cid_;} \
00039 virtual const CLASSTYPE& getClass() const {return classid();}
00040
00041
00047 #define UBIT_CLASS(CLASS, PARENT) \
00048 UBIT_CLASS_DEF(UClass, #CLASS, CLASS, PARENT, new CLASS, null, 0)
00049
00050
00056 #define UBIT_ABSTRACT_CLASS(CLASS, PARENT) \
00057 UBIT_CLASS_DEF(UClass, #CLASS, CLASS, PARENT, null, null, 0)
00058
00059
00060
00069 class UClass {
00070 public:
00071 const UStr& name() const {return *_name;}
00073
00074 const UStr& getName() const {return *_name;}
00076
00077 int id() const {return _id;}
00079
00080 int getId() const {return _id;}
00082
00083 virtual bool isInstance(UObject& obj) const {return false;}
00085
00086 virtual UObject* newInstance() const {return null;}
00088
00089 virtual UStyle* newStyle() const {return null;}
00091
00092 virtual UMask getModes() const {return 0;}
00094
00095 virtual ~UClass();
00096
00097 protected:
00098 UClass(const char* name);
00099 UClass(const UStr& name);
00100 virtual void initClass();
00101
00102 private:
00103 UClass(const UClass&);
00104 UClass& operator=(const UClass&);
00105
00106 UStr* _name;
00107 int _id;
00108 static int last_id;
00109 };
00110
00111
00112
00115 class UAttributeClass : public UClass {
00116 protected:
00117 friend class UAttributeClassMap;
00118 UAttributeClass(const char* name);
00119 UAttributeClass(const UStr& name);
00120 };
00121
00125 #define UBIT_ATTR_CLASS(CLASS, PARENT) \
00126 UBIT_CLASS_DEF(UAttributeClass, #CLASS, CLASS, PARENT, new CLASS, null, 0)
00127
00128
00129
00132 class UElementClass : public UClass {
00133 public:
00134 enum {
00135 EMPTY_ELEMENT = 1<<0,
00136 DONT_PARSE_CONTENT = 1<<1,
00137 PRESERVE_SPACES = 1<<2
00138 };
00150 virtual UStyle* getStyle() const;
00152
00153 virtual UProps* getProps() const {return props;}
00154 virtual void setProps(UProps*) const;
00155
00156 virtual ~UElementClass();
00157
00158 protected:
00159 UElementClass(const char* name);
00160 UElementClass(const UStr& name);
00161
00162 private:
00163 friend class UElementClassMap;
00164 mutable UStyle* style;
00165
00166 mutable UProps* props;
00167 };
00168
00172 #define UBIT_ELEMENT_CLASS(CLASS,PARENT) \
00173 UBIT_CLASS_DEF(UElementClass, #CLASS, CLASS, PARENT, new CLASS, CLASS::createStyle(), 0)
00174
00178 #define UBIT_DATA_ELEMENT_CLASS(CLASS,PARENT) \
00179 UBIT_CLASS_DEF(UElementClass, #CLASS, CLASS, PARENT, new CLASS, null, 0)
00180
00181 }
00182 #endif
00183
00184