uclass.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  uclass.hpp
00004 *  Ubit Project 
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006 *  (C) 1999-2006 / Eric Lecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007 * ***********************************************************************
00008 * COPYRIGHT NOTICE :
00009 * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
00010 * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00011 * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
00012 * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
00013 * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00014 * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00015 * ***********************************************************************
00016 * ==================================================== [(c)Elc] ======= *
00017 * ==================================================== ======== ======= */
00018 
00019 #ifndef _uclass_hpp_
00020 #define _uclass_hpp_ 1
00021 //pragma ident  "@(#)uclass.hpp ubit:05.05.00"
00022 #include <ubit/ubrick.hpp>
00023 namespace ubit {
00024 
00025 class UObject;
00026 class UStr;
00027 
00028 /* ==================================================== [Elc] ======= */
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 /* ==================================================== [Elc] ======= */
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   //uptr<UStr> _name;
00106   UStr* _name;
00107   int _id;
00108   static int last_id;
00109 };
00110  
00111 /* ==================================================== [Elc] ======= */
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 /* ==================================================== [Elc] ======= */
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   //uptr<UProps> props;
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 /* ==================================================== [TheEnd] ======= */
00184 /* ==================================================== [(c)Elc] ======= */

Generated on Mon Jan 29 00:20:37 2007 for Ubit by  doxygen 1.4.7