00001
00002
00003
00004
00005
00006
00007 #ifndef __UNICONFTREE_H
00008 #define __UNICONFTREE_H
00009
00010 #include "uniconfkey.h"
00011 #include "wvvector.h"
00012 #include "wvcallback.h"
00013 #include "unihashtree.h"
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 template<class Sub, class Base = UniHashTreeBase>
00034 class UniConfTree : public Base
00035 {
00036
00037 public:
00038 typedef WvCallback<bool, const Sub *, const Sub *, void *> Comparator;
00039
00040
00041 UniConfTree(Sub *parent, const UniConfKey &key) :
00042 Base(parent, key)
00043 { }
00044
00045
00046 ~UniConfTree()
00047 { zap(); }
00048
00049
00050 Sub *parent() const
00051 { return static_cast<Sub*>(xparent); }
00052
00053
00054 void setparent(Sub *parent)
00055 { Base::_setparent(parent); }
00056
00057
00058 Sub *root() const
00059 { return static_cast<Sub*>(Base::_root()); }
00060
00061
00062
00063
00064
00065 UniConfKey fullkey(const Sub *ancestor = NULL) const
00066 { return Base::_fullkey(ancestor); }
00067
00068
00069
00070
00071
00072 Sub *find(const UniConfKey &key) const
00073 { return static_cast<Sub*>(Base::_find(key)); }
00074
00075
00076
00077
00078
00079
00080
00081 Sub *findchild(const UniConfKey &key) const
00082 { return static_cast<Sub*>(Base::_findchild(key)); }
00083
00084
00085
00086
00087
00088
00089
00090 void remove(const UniConfKey &key)
00091 { delete find(key); }
00092
00093
00094 void zap()
00095 {
00096 if (!xchildren)
00097 return;
00098
00099
00100
00101 typename Base::Container *oldchildren = xchildren;
00102 xchildren = NULL;
00103
00104
00105 typename Base::Container::Iter i(*oldchildren);
00106 for (i.rewind(); i.next();)
00107 delete static_cast<Sub*>(i.ptr());
00108
00109 delete oldchildren;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 void compare(const Sub *other, const Comparator &comparator,
00121 void *userdata)
00122 {
00123 _recursivecompare(this, other, reinterpret_cast<
00124 const typename Base::BaseComparator&>(comparator), userdata);
00125 }
00126
00127
00128
00129
00130
00131 class Iter : public Base::Iter
00132 {
00133 public:
00134 typedef typename Base::Iter MyBase;
00135
00136
00137 Iter(Sub &tree) : Base::Iter(tree)
00138 { }
00139
00140
00141 Sub *ptr() const
00142 { return static_cast<Sub*>(MyBase::ptr()); }
00143 WvIterStuff(Sub);
00144 };
00145 };
00146
00147
00148
00149 class UniConfValueTree : public UniConfTree<UniConfValueTree>
00150 {
00151 WvString xvalue;
00152
00153 public:
00154 UniConfValueTree(UniConfValueTree *parent,
00155 const UniConfKey &key, WvStringParm value) :
00156 UniConfTree<UniConfValueTree>(parent, key), xvalue(value)
00157 {
00158 }
00159
00160
00161 const WvString &value() const
00162 { return xvalue; }
00163
00164
00165 void setvalue(WvStringParm value)
00166 { xvalue = value; }
00167 };
00168
00169
00170 #endif // __UNICONFTREE_H