Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

uniconftree.h

00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * UniConf low-level tree storage abstraction.
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 
00023 template<class Sub, class Base = UniHashTreeBase>
00024 class UniConfTree : public Base
00025 {
00026    
00027 public:
00028     typedef WvCallback<void, const Sub *, void *> Visitor;
00029     typedef WvCallback<bool, const Sub *, const Sub *, void *> Comparator;
00030 
00032     UniConfTree(Sub *parent, const UniConfKey &key) :
00033         Base(parent, key)
00034         { }
00035 
00037     ~UniConfTree()
00038         { zap(); }
00039 
00041     Sub *parent() const
00042         { return static_cast<Sub*>(this->xparent); }
00043 
00045     void setparent(Sub *parent)
00046         { Base::_setparent(parent); }
00047     
00049     Sub *root() const
00050         { return static_cast<Sub*>(Base::_root()); }
00051     
00056     UniConfKey fullkey(const Sub *ancestor = NULL) const
00057         { return Base::_fullkey(ancestor); }
00058 
00063     Sub *find(const UniConfKey &key) const
00064         { return static_cast<Sub*>(Base::_find(key)); }
00065     
00072     Sub *findchild(const UniConfKey &key) const
00073         { return static_cast<Sub*>(Base::_findchild(key)); }
00074 
00081     void remove(const UniConfKey &key)
00082         { delete find(key); }
00083     
00085     void zap()
00086     {
00087         if (!(this->xchildren))
00088             return;
00089         // set xchildren to NULL first so that the zap() will happen faster
00090         // otherwise, each child will attempt to unlink itself uselessly
00091 
00092         typename Base::Container *oldchildren = this->xchildren;
00093         this->xchildren = NULL;
00094 
00095         // delete all children
00096         typename Base::Container::Iter i(*oldchildren);
00097         for (i.rewind(); i.next();)
00098             delete static_cast<Sub*>(i.ptr());
00099 
00100         delete oldchildren;
00101     }
00102 
00109     void visit(const Visitor &visitor, void *userdata,
00110         bool preorder = true, bool postorder = false) const
00111     {
00112         _recursive_unsorted_visit(this, reinterpret_cast<
00113             const typename Base::BaseVisitor&>(visitor), userdata,
00114             preorder, postorder);
00115     }
00116 
00125     bool compare(const Sub *other, const Comparator &comparator,
00126         void *userdata)
00127     {
00128         return _recursivecompare(this, other, reinterpret_cast<
00129             const typename Base::BaseComparator&>(comparator), userdata);
00130     }
00131 
00136     class Iter : public Base::Iter
00137     {
00138     public:
00139         typedef typename Base::Iter MyBase;
00140 
00142         Iter(Sub &tree) : Base::Iter(tree)
00143             { }
00144 
00146         Sub *ptr() const
00147             { return static_cast<Sub*>(MyBase::ptr()); }
00148         WvIterStuff(Sub);
00149     };
00150 };
00151 
00152 
00154 class UniConfValueTree : public UniConfTree<UniConfValueTree>
00155 {
00156     WvString xvalue;  
00158 public:
00159     UniConfValueTree(UniConfValueTree *parent,
00160                      const UniConfKey &key, WvStringParm value)
00161         : UniConfTree<UniConfValueTree>(parent, key), xvalue(value)
00162         { }
00163     
00165     const WvString &value() const
00166         { return xvalue; }
00167 
00169     void setvalue(WvStringParm value)
00170         { xvalue = value; }
00171 };
00172 
00173 
00174 #endif // __UNICONFTREE_H

Generated on Sun Jul 10 18:25:50 2005 for WvStreams by  doxygen 1.4.0