uchild.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  uchild.hpp [internal implementation]
00004  *  Ubit Project 
00005  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006  *  (C) 1999-2006 / EricLecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007  *
00008  * ***********************************************************************
00009  * COPYRIGHT NOTICE : 
00010  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00011  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00012  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00013  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00014  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016  * ***********************************************************************
00017  * ==================================================== [(c)Elc] ======= *
00018  * ==================================================== ======== ======= */
00019 
00020 #ifndef _uchild_hpp_
00021 #define _uchild_hpp_
00022 //pragma ident  "@(#)uchild.hpp ubit:05.05.00"
00023 namespace ubit {
00024 
00025 /* ==================================================== ===== ======= */
00028 class UChild {
00029 public:
00030   UChild(UBrick& o) : obj(&o), parent(0), cond(0) {}
00031   UChild(UBrick* o) : obj(o),  parent(0), cond(0) {}
00032   UChild(UBrick* o, const UCond& c) : obj(o), parent(0), cond(&c) {}
00033   UChild(const char* s);
00034 
00035   UBrick* operator*() {return obj;}  
00036   const UBrick* operator*() const {return obj;}  
00037   
00038   UGroup* getParent() {return parent;}
00039 
00040   const UCond* getCond() const {return cond;}
00041   void setCond(const UCond& c)  {cond = &c;}
00042   void setCond(const UCond* c)  {cond = c;}
00043   void setCond(const UChild& c) {cond = c.cond;}
00044   void setCond(const UChild* c) {cond = c->cond;}
00045   
00046  private:
00047   friend class UParent;
00048   friend class UBrick;
00049   friend class UGroup;
00050   UBrick* obj;
00051   UGroup* parent;
00052   const UCond* cond;
00053 };
00054 
00055 /* ==================================================== ===== ======= */
00056 
00057 template <class _I>
00058 struct _UChildIter : public _I {
00059   _UChildIter() : _I(null) {}       // !ATT: peut poser probleme si pas g++ !
00060   _UChildIter(const _I& i) : _I(i) {}
00061   _UChildIter(const _UChildIter& i) : _I(i) {}
00062   
00063   UBrick* operator*()     {return static_cast<UBrick*>(*_I::operator*());}
00064   UChild& getNode()       {return _I::operator*();}
00065   const UCond* getCond()  {return _I::operator*().getCond();}
00066 };
00067 
00071 typedef _UChildIter<std::list<UChild>::iterator> UChildIter;
00072 
00076 typedef _UChildIter<std::list<UChild>::reverse_iterator> UChildReverseIter;
00077 
00078 /* ==================================================== ===== ======= */
00082 class UChildren : public std::list<UChild> {
00083 public:
00084   UChildIter at(int position);
00086 
00087   UChildIter find(const UBrick& child);
00089   
00090   UChildIter findStr(const UStr& value, bool ignore_case = true);
00095   UChildIter findBox(const UStr& value, bool ignore_case = true);
00107   template <class CC>
00108     UChildIter findClass(CC*& c) {
00109       c = null;
00110       for (UChildIter i = begin(); i != end(); ++i) {
00111         if (dynamic_cast<CC*>(*i)) {c = (CC*)*i; return i;}
00112       }
00113       return end();
00114     }
00115 };
00116 
00117 }
00118 #endif
00119 /* ==================================================== [TheEnd] ======= */
00120 /* ==================================================== [(c)Elc] ======= */
00121 

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