00001
00002
00003
00004
00005
00006
00007 #ifndef __UNIHASHTREE_H
00008 #define __UNIHASHTREE_H
00009
00010 #include "uniconfkey.h"
00011 #include "wvcallback.h"
00012 #include "wvscatterhash.h"
00013
00014 class UniHashTreeBase;
00015
00016
00017 typedef WvCallback<bool, const UniHashTreeBase *,
00018 const UniHashTreeBase *, void *> UniHashTreeBaseComparator;
00019
00020 class UniHashTreeBase
00021 {
00022 protected:
00023 UniConfKey xkey;
00024 UniHashTreeBase *xparent;
00025
00026 struct Accessor
00027 {
00028 static const UniConfKey *get_key(const UniHashTreeBase *obj)
00029 { return &obj->key(); }
00030 };
00031
00032 typedef WvScatterHash<UniHashTreeBase, UniConfKey, Accessor> Container;
00033 typedef UniHashTreeBaseComparator BaseComparator;
00034 Container *xchildren;
00035
00036 UniHashTreeBase(UniHashTreeBase *parent, const UniConfKey &key);
00037
00038 public:
00039 ~UniHashTreeBase();
00040
00041 protected:
00042 void _setparent(UniHashTreeBase *parent);
00043
00044 UniHashTreeBase *_root() const;
00045 UniConfKey _fullkey(const UniHashTreeBase *ancestor = NULL) const;
00046 UniHashTreeBase *_find(const UniConfKey &key) const;
00047 UniHashTreeBase *_findchild(const UniConfKey &key) const;
00048
00049 static void _recursivecompare(
00050 const UniHashTreeBase *a, const UniHashTreeBase *b,
00051 const UniHashTreeBaseComparator &comparator, void *userdata);
00052
00053 public:
00054 class Iter : public Container::Iter
00055 {
00056 public:
00057 Iter(UniHashTreeBase &b) : Container::Iter(*b.xchildren) { }
00058 };
00059 friend class Iter;
00060
00061
00062 const UniConfKey &key() const
00063 { return xkey; }
00064
00065
00066 bool haschildren() const;
00067
00068 private:
00069
00070 void link(UniHashTreeBase *node);
00071
00072
00073 void unlink(UniHashTreeBase *node);
00074 };
00075
00076 #endif //__UNIHASHTREE_H