Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

unimounttreegen.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Defines a UniConfGen that manages a tree of UniConfGen instances. 00006 */ 00007 #ifndef __UNIMOUNTTREEGEN_H 00008 #define __UNIMOUNTTREEGEN_H 00009 00010 #include "uniconfgen.h" 00011 #include "uniconftree.h" 00012 #include "wvcallback.h" 00013 #include "wvstringtable.h" 00014 #include "wvmoniker.h" 00015 00016 /** 00017 * Used by UniMountTreeGen to maintain information about mounted 00018 * subtrees. 00019 */ 00020 class UniMountTree : public UniConfTree<UniMountTree> 00021 { 00022 public: 00023 UniConfGenList generators; 00024 00025 UniMountTree(UniMountTree *parent, const UniConfKey &key); 00026 ~UniMountTree(); 00027 00028 /** Returns true if the node should not be pruned. */ 00029 bool isessential() 00030 { return haschildren() || ! generators.isempty(); } 00031 00032 /** 00033 * Returns the nearest node in the info tree to the key. 00034 * "key" is the key 00035 * "split" is set to the number of leading segments used 00036 * Returns: the node 00037 */ 00038 UniMountTree *findnearest(const UniConfKey &key, int &split); 00039 00040 /** Finds or makes an info node for the specified key. */ 00041 UniMountTree *findormake(const UniConfKey &key); 00042 00043 // an iterator over nodes that have information about a key 00044 class MountIter; 00045 // an iterator over generators about a key 00046 class GenIter; 00047 }; 00048 00049 00050 /** 00051 * An iterator over the UniMountTree nodes that might know something 00052 * about the provided 'key', starting with the nearest match and then 00053 * moving up the tree. 00054 */ 00055 class UniMountTree::MountIter 00056 { 00057 int bestsplit; 00058 UniMountTree *bestnode; 00059 00060 int xsplit; 00061 UniMountTree *xnode; 00062 UniConfKey xkey; 00063 00064 public: 00065 MountIter(UniMountTree &root, const UniConfKey &key); 00066 00067 void rewind(); 00068 bool next(); 00069 00070 int split() const 00071 { return xsplit; } 00072 UniConfKey key() const 00073 { return xkey; } 00074 UniConfKey head() const 00075 { return xkey.first(xsplit); } 00076 UniConfKey tail() const 00077 { return xkey.removefirst(xsplit); } 00078 UniMountTree *node() const 00079 { return xnode; } 00080 UniMountTree *ptr() const 00081 { return node(); } 00082 WvIterStuff(UniMountTree); 00083 }; 00084 00085 00086 /** 00087 * An iterator over the generators that might provide a key 00088 * starting with the nearest match. 00089 * 00090 * eg. if you have something mounted on /foo and /foo/bar/baz, and you ask 00091 * for a GenIter starting at /foo/bar/baz/boo/snoot, GenIter will give you 00092 * /foo/bar/baz followed by /foo; MountIter will give you /foo/bar/baz, 00093 * then /foo/bar, then /foo. 00094 */ 00095 class UniMountTree::GenIter : private UniMountTree::MountIter 00096 { 00097 UniConfGenList::Iter *genit; /*!< active generator iterator */ 00098 00099 public: 00100 GenIter(UniMountTree &root, const UniConfKey &key); 00101 ~GenIter(); 00102 00103 typedef UniMountTree::MountIter ParentClass; 00104 using ParentClass::split; 00105 using ParentClass::key; 00106 using ParentClass::head; 00107 using ParentClass::tail; 00108 using ParentClass::node; 00109 00110 void rewind(); 00111 bool next(); 00112 00113 UniConfGen *ptr() const 00114 { return genit ? genit->ptr() : NULL; } 00115 WvIterStuff(UniConfGen); 00116 }; 00117 00118 00119 /** The UniMountTree implementation realized as a UniConfGen. */ 00120 class UniMountTreeGen : public UniConfGen 00121 { 00122 class KeyIter; 00123 friend class KeyIter; 00124 00125 UniMountTree *mounts; 00126 00127 /** undefined. */ 00128 UniMountTreeGen(const UniMountTreeGen &other); 00129 00130 public: 00131 /** Creates an empty UniConf tree with no mounted stores. */ 00132 UniMountTreeGen(); 00133 00134 /** Destroys the UniConf tree along with all uncommitted data. */ 00135 ~UniMountTreeGen(); 00136 00137 /** 00138 * Mounts a generator at a key using a moniker. 00139 * 00140 * Returns the generator instance pointer, or NULL on failure. 00141 */ 00142 virtual UniConfGen *mount(const UniConfKey &key, WvStringParm moniker, 00143 bool refresh); 00144 00145 /** 00146 * Mounts a generator at a key. 00147 * Takes ownership of the supplied generator instance. 00148 * 00149 * "key" is the key 00150 * "gen" is the generator instance 00151 * "refresh" is if true, refreshes the generator after mount 00152 * Returns: the generator instance pointer, or NULL on failure 00153 */ 00154 virtual UniConfGen *mountgen(const UniConfKey &key, UniConfGen *gen, 00155 bool refresh); 00156 00157 /** 00158 * Unmounts the generator at a key and destroys it. 00159 * 00160 * "key" is the key 00161 * "gen" is the generator instance 00162 * "commit" is if true, commits the generator before unmount 00163 */ 00164 virtual void unmount(const UniConfKey &key, UniConfGen *gen, bool commit); 00165 00166 /** 00167 * Finds the generator that owns a key. 00168 * 00169 * If the key exists, returns the generator that provides its 00170 * contents. Otherwise returns the generator that would be 00171 * updated if a value were set. 00172 * 00173 * "key" is the key 00174 * "mountpoint" is if not NULL, replaced with the mountpoint 00175 * path on success 00176 * Returns: the handle, or a null handle if none 00177 */ 00178 virtual UniConfGen *whichmount(const UniConfKey &key, UniConfKey *mountpoint); 00179 00180 /** Determines if a key is a mountpoint. */ 00181 virtual bool ismountpoint(const UniConfKey &key); 00182 00183 /***** Overridden members *****/ 00184 00185 virtual bool exists(const UniConfKey &key); 00186 virtual bool haschildren(const UniConfKey &key); 00187 virtual WvString get(const UniConfKey &key); 00188 virtual void set(const UniConfKey &key, WvStringParm value); 00189 virtual bool refresh(); 00190 virtual void commit(); 00191 virtual Iter *iterator(const UniConfKey &key); 00192 00193 private: 00194 /** 00195 * Prunes a branch of the tree beginning at the specified node 00196 * and moving towards the root. 00197 * "node" is the node 00198 */ 00199 void prune(UniMountTree *node); 00200 00201 /** Called by generators when a key changes. */ 00202 void gencallback(const UniConfKey &key, WvStringParm value, void *userdata); 00203 }; 00204 00205 00206 /** 00207 * An iterator over the keys in a tree of mounted generators. 00208 */ 00209 class UniMountTreeGen::KeyIter : public UniConfGen::Iter 00210 { 00211 UniMountTreeGen *xroot; 00212 UniConfKey xkey; 00213 00214 UniMountTree::GenIter genit; 00215 WvStringTable hack; // FIXME: ugly hack 00216 WvStringTable::Iter hackit; 00217 00218 public: 00219 KeyIter(UniMountTreeGen &root, const UniConfKey &key); 00220 00221 /***** Overridden members *****/ 00222 00223 virtual void rewind(); 00224 virtual bool next(); 00225 virtual UniConfKey key() const; 00226 }; 00227 00228 #endif //__UNIMOUNTTREEGEN_H

Generated on Tue Oct 5 01:09:19 2004 for WvStreams by doxygen 1.3.7