ubrick.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  ubrick.hpp: base class for objects that can be added to the 
00004  *  scene graph and UBrick smart pointers
00005  *  Ubit Project
00006  *  Author: Eric Lecolinet
00007  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00008  *  (C) 1999-2006 / EricLecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00009  *
00010  * ***********************************************************************
00011  * COPYRIGHT NOTICE : 
00012  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00013  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00014  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00015  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00016  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00017  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00018  * ***********************************************************************
00019  * ==================================================== [(c)Elc] ======= *
00020  * ==================================================== ======== ======= */
00021 
00022 #ifndef _ubrick_hpp_
00023 #define _ubrick_hpp_
00024 //pragma ident  "@(#)ubrick.hpp         ubit:05.05.00"
00025 #include <stdlib.h>  // for size_t, new(), delete()
00026 #include <ubit/udefs.hpp>
00027 #include <ubit/uobject.hpp>
00028 #include <ubit/uclass.hpp>
00029 #include <ubit/ugeom.hpp>
00030 #include <ubit/uchild.hpp>
00031 #include <ubit/uparent.hpp>
00032 
00033 namespace ubit {
00034 
00035 /* ==================================================== [Elc] ======= */
00036 /* ==================================================== ===== ======= */
00078 class UBrick : public UObject {
00079 public:
00080   enum {
00081     ELEMENT_NODE                   = 1,
00082     ATTRIBUTE_NODE                 = 2,
00083     TEXT_NODE                      = 3,
00084     CDATA_SECTION_NODE             = 4,
00085     ENTITY_REFERENCE_NODE          = 5,
00086     ENTITY_NODE                    = 6,
00087     PROCESSING_INSTRUCTION_NODE    = 7,
00088     COMMENT_NODE                   = 8,
00089     DOCUMENT_NODE                  = 9,
00090     DOCUMENT_TYPE_NODE             = 10,
00091     DOCUMENT_FRAGMENT_NODE         = 11,
00092     NOTATION_NODE                  = 12
00093   };
00094     
00095   UBIT_ABSTRACT_CLASS(UBrick, UObject)
00097     
00098   virtual unsigned short getNodeType() const {return 0;}
00100   
00101   virtual const UStr* getNodeName() const {return null;}
00103 
00104   virtual const UStr* getNodeValue() const {return null;}
00106 
00107   virtual UBrick* brickCast() {return this;}
00109 
00110    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00111   // parents.
00112 
00113   virtual bool isChildOf(const UGroup& parent, bool indirect = true) const;
00118   UParentIter pbegin() const {return parents().begin();}
00130   UParentIter pend() const {return parents().end();}
00132 
00133   virtual UParents& parents() const {return _parents;}
00135 
00136   virtual bool hasFullParent() const;
00137   virtual bool hasOnlyPseudoParents() const;
00138     
00139   virtual UGroup* getParent(int pos = 0) const;
00148   template <class CC>
00149     CC* findParent() const {
00150       for (UParentIter p = pbegin(); p != pend(); ++p) {
00151         if (dynamic_cast<CC*>(*p)) {return (CC*)*p;}
00152         else return ((UBrick*)(*p))->findParent<CC>();
00153       }
00154       return null;
00155     }
00157 
00158   virtual int getBoxParents(std::vector<UBox*>& parvect) const;
00160 
00161   virtual UBox* getParent(const UView*) const;
00166   virtual UView* getParentView(const UView*) const;
00171   virtual UBox*  getParent(const UEvent&) const;
00172   virtual UView* getParentView(const UEvent&) const;
00177   virtual void removeFromParents(bool update_parents = true);
00185   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00186   // attributes.
00187   
00188   UChildIter abegin() const {return attributes().begin();}
00200   UChildIter aend() const {return attributes().end();}
00202 
00203   virtual UChildren& attributes() const {return _attributes;}
00205 
00206   virtual void addAttr(const UChild& attribute);
00208     
00209   //virtual void removeAttr(UBrick&);
00210   //to be added!
00211 
00212   virtual void removeAllAttrs(bool autodel = true);
00214     
00215   friend UChild operator/(const UCond&, UBrick&);
00216   friend UChild operator/(const UCond&, UBrick*);
00234   virtual bool fire(UEvent&, const UOn& condition) const;
00236 
00237   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00238       
00239   virtual void update() {}
00241 
00242   UBrick& autoUpdate(bool state);
00252   bool isAutoUpdate() const;
00254   
00255   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00256 
00257   bool isConst() const;
00259     
00260   void setConst();
00267   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00268     
00269   UMask getBModes() const {return bmodes;}
00271 
00272   bool hasBMode(UMask modes) const {return (bmodes & modes) != 0;}
00274   
00275   void addBModes(UMask modes) {bmodes |= modes;}
00277   
00278   void removeBModes(UMask modes) {bmodes &= ~modes;}
00280 
00281   // - - - Impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00282 
00283 private:
00284   UBrick(const UBrick&); 
00286   
00287   UBrick& operator=(const UBrick&); 
00289   
00290 protected:
00291   explicit UBrick();
00293   
00294   explicit UBrick(UMask b_modes);
00296   
00297   virtual ~UBrick() {destructs();}
00302   virtual void addingTo(UChild* self, UGroup* parent) {}
00304   
00305   virtual void removingFrom(UChild* self, UGroup* parent) {}
00315   virtual void destructs();
00317 
00318   virtual bool canPtrDelete() const;  
00320   
00321 #ifndef NO_DOC 
00322 public:
00323   void* operator new(size_t);
00324   void  operator delete(void*);
00325   // [impl] internal memory management.
00326   
00327   bool checkConst() const;
00328   // [impl] generates a (non fatal) error if this object is logically constant (see setConst()).
00329 
00330   void fireParents(UEvent& e, const UOn& on) const {_parents.fireParents(e, on);}
00331   //void updateAutoParents() {_parents.updateAutoParents();}
00332   void updateAutoParents(const UUpdate& m) {_parents.updateAutoParents(m);}
00333     
00334   virtual void addChangeCall(UCall&);
00335   virtual UGroup* getSubGroup() {return null;}
00336 
00337 protected:
00338   friend class UChild;
00339   friend class UArgs;
00340   friend class UGroup;
00341   friend class UBox;
00342   friend class UParents;
00343   mutable UParents _parents;
00344   mutable UChildren _attributes;  // (including callbacks)
00345   mutable UMask bmodes;
00346   void _setBmodes(UMask bmodes, bool on_off) const;
00347 #endif
00348 };
00349 
00350 }
00351 #endif 
00352 /* ==================================================== [TheEnd] ======= */
00353 /* ==================================================== [(c)Elc] ======= */

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