ubit
uclass.hpp
1 /************************************************************************
2  *
3  * uclass.hpp: Ubit MetaClasses
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _uclass_hpp_
18 #define _uclass_hpp_ 1
19 #include <ubit/udefs.hpp>
20 namespace ubit {
21 
22 
23 #define UCLASSDEF(NAME,C,CREATOR) \
24 struct MetaClass : public UClass { \
25 MetaClass(): UClass(NAME) {} \
26 virtual bool isInstance(UObject& obj) const {return dynamic_cast<C*>(&obj);} \
27 virtual bool isInstance(UObject* obj) const {return dynamic_cast<C*>(obj);} \
28 virtual C* newInstance() const {return CREATOR;} \
29 virtual UStyle* newStyle() const {return C::createStyle();} \
30 }; \
31 static const UClass& Class() {static MetaClass& c = *new MetaClass; return c;} \
32 virtual const UClass& getClass() const {return Class();}
33 
34 
38 #define UCLASS(C) UCLASSDEF(#C, C, new C)
39 
43 #define UABSTRACT_CLASS(C) UCLASSDEF(#C, C, null)
44 
45 
74  class UClass {
75  public:
85  enum ParseModes {
86  EMPTY_ELEMENT = 1<<0,
87  DONT_PARSE_CONTENT = 1<<1,
88  PRESERVE_SPACES = 1<<2
89  };
90 
91  UClass(const char* name);
92  UClass(const UStr& name);
93  virtual ~UClass();
94 
95  const UStr& getName() const {return *name;}
97 
98  unsigned int getNo() const {return no;}
104  virtual int getParseModes() const {return 0;}
106 
107  virtual bool isInstance(UObject& object) const {return false;}
109 
110  virtual UObject* newInstance() const {return null;}
116  virtual UStyle* newStyle() const {return null;}
122  UStyle* obtainStyle() const {return style ? style : (style = newStyle());}
130  UAttrList* getAttributes() const {return attributes;}
135  void setAttributes(UAttrList* alist) const {attributes = alist;}
141  private:
142  static unsigned int count;
143  unsigned int no;
144  UStr* name;
145  mutable UStyle* style;
146  mutable UAttrList* attributes;
147 
148  UClass(const UClass&); // assignment is forbidden.
149  UClass& operator=(const UClass&);
150  };
151 
152 }
153 #endif
void setAttributes(UAttrList *alist) const
changes the class properties.
Definition: uclass.hpp:135
unsigned int getNo() const
returns the class #.
Definition: uclass.hpp:98
Attribute list.
Definition: uattr.hpp:167
virtual bool isInstance(UObject &object) const
returns true if this &#39;object&#39; derives from this class.
Definition: uclass.hpp:107
UAttrList * getAttributes() const
returns current class properties.
Definition: uclass.hpp:130
Ubit class.
Definition: uclass.hpp:74
Definition: uhardfont.hpp:31
UStyle * obtainStyle() const
returns the style prototype that is associated to this class.
Definition: uclass.hpp:122
virtual UStyle * newStyle() const
creates a new instance of the style of this class (if applicable).
Definition: uclass.hpp:116
ParseModes
Parse Modes returned by UClass::getParseModes():
Definition: uclass.hpp:85
Compiled Object Style.
Definition: ustyle.hpp:44
virtual UObject * newInstance() const
creates a new instance of the corresponding class (if applicable).
Definition: uclass.hpp:110
const UStr & getName() const
returns the class name.
Definition: uclass.hpp:95
Ubit String.
Definition: ustr.hpp:72
virtual int getParseModes() const
returns an ORed combination of the parse modes (0 if none).
Definition: uclass.hpp:104
Base class of most Ubit objects (SEE DETAILS!).
Definition: uobject.hpp:113