Make WvStreams compile with gcc 4.4.
[wvstreams.git] / include / unimountgen.h
blob9ceabcd5a01156442c4ca0e21cbf3a5d4a60bfb8
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * Defines a UniConfGen that manages a tree of UniConfGen instances.
6 */
7 #ifndef __UNIMOUNTGEN_H
8 #define __UNIMOUNTGEN_H
10 #include "uniconfgen.h"
11 #include "wvmoniker.h"
12 #include "wvstringlist.h"
13 #include "wvtr1.h"
16 /** The UniMountTree implementation realized as a UniConfGen. */
17 class UniMountGen : public UniConfGen
19 protected:
21 // Class to hold the generator with its mountpoint
22 class UniGenMount
24 public:
25 UniGenMount(IUniConfGen *gen, const UniConfKey &key)
26 : gen(gen), key(key)
27 { }
29 xplc_ptr<IUniConfGen> gen;
30 UniConfKey key;
33 typedef class WvList<UniGenMount> MountList;
34 MountList mounts;
36 /** undefined. */
37 UniMountGen(const UniMountGen &other);
39 public:
40 /** Creates an empty UniConf tree with no mounted stores. */
41 UniMountGen();
43 /** Destroys the UniConf tree along with all uncommitted data. */
44 virtual ~UniMountGen();
46 void zap();
48 /**
49 * Mounts a generator at a key using a moniker.
51 * Returns the generator instance pointer, or NULL on failure.
53 virtual IUniConfGen *mount(const UniConfKey &key,
54 WvStringParm moniker,
55 bool refresh);
57 /**
58 * Mounts a generator at a key.
59 * Takes ownership of the supplied generator instance.
61 * "key" is the key
62 * "gen" is the generator instance
63 * "refresh" is if true, refreshes the generator after mount
64 * Returns: the generator instance pointer, or NULL on failure
66 virtual IUniConfGen *mountgen(const UniConfKey &key,
67 IUniConfGen *gen,
68 bool refresh);
70 /**
71 * Unmounts the generator at a key and releases it.
73 * "gen" is the generator instance
74 * "commit" is if true, commits the generator before unmount
76 virtual void unmount(IUniConfGen *gen, bool commit);
78 /**
79 * Finds the generator that owns a key.
81 * If the key exists, returns the generator that provides its
82 * contents. Otherwise returns the generator that would be
83 * updated if a value were set.
85 * "key" is the key
86 * "mountpoint" is if not NULL, replaced with the mountpoint
87 * path on success
88 * Returns: the handle, or a null handle if none
90 virtual IUniConfGen *whichmount(const UniConfKey &key,
91 UniConfKey *mountpoint);
93 /** Determines if a key is a mountpoint. */
94 virtual bool ismountpoint(const UniConfKey &key);
96 /***** Overridden members *****/
98 virtual bool exists(const UniConfKey &key);
99 virtual bool haschildren(const UniConfKey &key);
100 virtual WvString get(const UniConfKey &key);
101 virtual void set(const UniConfKey &key, WvStringParm value);
102 virtual void setv(const UniConfPairList &pairs);
103 virtual void commit();
104 virtual bool refresh();
105 virtual void flush_buffers() { }
106 virtual Iter *iterator(const UniConfKey &key);
107 virtual Iter *recursiveiterator(const UniConfKey &key);
109 private:
110 /** Find the active generator for a given key. */
111 UniGenMount *findmount(const UniConfKey &key);
112 /** Find a unique active generator a given key, will return NULL if
113 * there are other generators beneath that key. */
114 UniGenMount *findmountunder(const UniConfKey &key);
116 // Trim the key so it matches the generator starting point
117 UniConfKey trimkey(const UniConfKey &foundkey, const UniConfKey &key)
118 { return key.removefirst(foundkey.numsegments()); }
120 /** Called by generators when a key changes. */
121 void gencallback(const UniConfKey &base, const UniConfKey &key,
122 WvStringParm value);
124 void makemount(const UniConfKey &key);
126 /** Return true if the given key has a subkey
127 * if you used findmount first, give the result as a parameter to
128 * improve efficiency*/
129 bool has_subkey(const UniConfKey &key, UniGenMount *found = NULL);
131 struct UniGenMountPairs;
132 DeclareWvDict(UniGenMountPairs, WvFastString, key);
136 #endif //__UNIMOUNTGEN_H