00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _uchild_hpp_
00021 #define _uchild_hpp_
00022
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) {}
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
00120
00121