ubit
uchild.hpp
1 /* ***********************************************************************
2  *
3  * uchild.hpp [internal implementation]
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 _uchild_hpp_
18 #define _uchild_hpp_ 1
19 namespace ubit {
20 
23 class UChild {
24 public:
25  UChild(UNode& o) : obj(&o), parent(0), cond(0) {}
26  UChild(UNode* o) : obj(o), parent(0), cond(0) {}
27  UChild(UNode* o, const UCond& c) : obj(o), parent(0), cond(&c) {}
28  UChild(const char* s);
29 
30  UNode* operator*() {return obj;}
31  const UNode* operator*() const {return obj;}
32 
33  UElem* getParent() {return parent;}
34 
35  const UCond* getCond() const {return cond;}
36  void setCond(const UCond& c) {cond = &c;}
37  void setCond(const UChild& c) {cond = c.cond;}
38 
39  private:
40  friend class UParent;
41  friend class UNode;
42  friend class UElem;
43  UNode* obj;
44  UElem* parent;
45  const UCond* cond;
46 };
47 
48 /* ==================================================== ===== ======= */
49 
50 template <class _Iter>
51 class _UChildIter : public _Iter {
52 public:
53  //_UChildIter() : _Iter(null) {} // !ATT: peut poser probleme si pas g++ !
54  _UChildIter() : _Iter() {}
55  _UChildIter(const _Iter& i) : _Iter(i) {}
56  _UChildIter(const _UChildIter& i) : _Iter(i) {}
57 
58  UNode* operator*() {return static_cast<UNode*>(*_Iter::operator*());}
59  UChild& child() {return _Iter::operator*();}
60  const UCond* getCond() {return _Iter::operator*().getCond();}
61 };
62 
63 // ==================================================== [(c)Elc] =======
64 
69 
74 
75 /* ==================================================== ===== ======= */
79 class UChildren : public std::list<UChild> {
80 public:
81  UChildIter at(int pos);
83 
84  UChildIter find(const UNode& child);
86 
87  UChildIter findStr(const UStr& value, bool ignore_case = true);
92  UChildIter findBox(const UStr& value, bool ignore_case = true);
104  template <class CC>
105  UChildIter findClass(CC*& c) {
106  c = null;
107  for (UChildIter i = begin(); i != end(); ++i) {
108  if (dynamic_cast<CC*>(*i)) {c = (CC*)*i; return i;}
109  }
110  return end();
111  }
112 };
113 
114 }
115 #endif
116 
Base class of objects that can be added to the UBIT scene graph (SEE DETAILS!).
Definition: unode.hpp:38
Base class for Ubit conditions.
Definition: ucond.hpp:29
Definition: uchild.hpp:51
lightweight general purpose container.
Definition: uelem.hpp:44
Child (or attribute) list.
Definition: uchild.hpp:79
[impl] Internal implementation of a parent node.
Definition: uparent.hpp:23
Definition: uhardfont.hpp:31
UChildIter findClass(CC *&c)
returns an iterator to the first child that derives from this class.
Definition: uchild.hpp:105
Ubit String.
Definition: ustr.hpp:72
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23