unihashtree.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 __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 // parameters: a node (won't be NULL), userdata
00017 typedef WvCallback<void, const UniHashTreeBase *,
00018         void *> UniHashTreeBaseVisitor;
00019 // parameters: 1st node (may be NULL), 2nd node (may be NULL), userdata
00020 typedef WvCallback<bool, const UniHashTreeBase *, 
00021         const UniHashTreeBase *, void *> UniHashTreeBaseComparator;
00022 
00023 class UniHashTreeBase
00024 {
00025 protected:
00026     UniConfKey xkey;   
00027     UniHashTreeBase *xparent; 
00029     struct Accessor
00030     {
00031         static const UniConfKey *get_key(const UniHashTreeBase *obj)
00032             { return &obj->key(); }
00033     };
00034 
00035     typedef WvScatterHash<UniHashTreeBase, UniConfKey, Accessor> Container;
00036     typedef UniHashTreeBaseVisitor BaseVisitor;
00037     typedef UniHashTreeBaseComparator BaseComparator;
00038     Container *xchildren; 
00040     UniHashTreeBase(UniHashTreeBase *parent, const UniConfKey &key);
00041 
00042 public:
00043     ~UniHashTreeBase();
00044 
00045 protected:
00046     void _setparent(UniHashTreeBase *parent);
00047     
00048     UniHashTreeBase *_root() const;
00049     UniConfKey _fullkey(const UniHashTreeBase *ancestor = NULL) const;
00050     UniHashTreeBase *_find(const UniConfKey &key) const;
00051     UniHashTreeBase *_findchild(const UniConfKey &key) const;
00052 
00053     static bool _recursivecompare(
00054         const UniHashTreeBase *a, const UniHashTreeBase *b,
00055         const UniHashTreeBaseComparator &comparator, void *userdata);
00056 
00057     static void _recursive_unsorted_visit(
00058         const UniHashTreeBase *a,
00059         const UniHashTreeBaseVisitor &visitor, void *userdata,
00060         bool preorder, bool postorder);
00061 
00062 public:
00063     class Iter : public Container::Iter
00064     {
00065     public:
00066         Iter(UniHashTreeBase &b) : Container::Iter(*b.xchildren) { }
00067     };
00068     friend class Iter;
00069 
00071     const UniConfKey &key() const
00072         { return xkey; }
00073 
00075     bool haschildren() const;
00076 
00077 private:
00079     void link(UniHashTreeBase *node);
00080 
00082     void unlink(UniHashTreeBase *node);
00083 };
00084 
00085 #endif //__UNIHASHTREE_H

Generated on Fri Oct 5 18:20:26 2007 for WvStreams by  doxygen 1.5.3