WvStreams
uniconfgen.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
4 *
5 * An abstract data container that backs a UniConf tree.
6 */
7#ifndef __UNICONFGEN_H
8#define __UNICONFGEN_H
9
10#include "uniconfpair.h"
11#include "wvcallbacklist.h"
12#include "wvtr1.h"
13
14class UniConfGen;
15class UniListIter;
16
30typedef wv::function<void(const UniConfKey&, WvStringParm)>
31 UniConfGenCallback;
32
39class IUniConfGen : public IObject
40{
41public:
42 virtual ~IUniConfGen();
43
44 /***** Notification API *****/
45
47 virtual void add_callback(void *cookie,
48 const UniConfGenCallback &callback) = 0;
49
51 virtual void del_callback(void *cookie) = 0;
52
53
54 /***** Status API *****/
55
60 virtual bool isok() = 0;
61
62
63 /***** Key Persistence API *****/
64
66 virtual void commit() = 0;
67
74 virtual bool refresh() = 0;
75
82 virtual void flush_buffers() = 0;
83
84 /***** Key Retrieval API *****/
85
95 virtual void prefetch(const UniConfKey &key, bool recursive) = 0;
96
101 virtual WvString get(const UniConfKey &key) = 0;
102
111 virtual bool exists(const UniConfKey &key) = 0;
112
113
123 virtual int str2int(WvStringParm s, int defvalue) const = 0;
124
125
126 /***** Key Storage API *****/
127
132 virtual void set(const UniConfKey &key, WvStringParm value) = 0;
133
134
139 virtual void setv(const UniConfPairList &pairs) = 0;
140
141
142 /***** Key Enumeration API *****/
143
154 virtual bool haschildren(const UniConfKey &key) = 0;
155
157 class Iter;
158
160 class NullIter;
161
164
172 virtual Iter *iterator(const UniConfKey &key) = 0;
173
188 virtual Iter *recursiveiterator(const UniConfKey &key) = 0;
189};
190
191DEFINE_IID(IUniConfGen, {0x7ca76e98, 0xb694, 0x43ca,
192 {0xb0, 0x56, 0x8b, 0x9d, 0xde, 0x9a, 0xbe, 0x9f}});
193
194
200{
201 IMPLEMENT_IOBJECT(UniConfGen);
202
203 // These fields are deliberately hidden to encourage use of the
204 // special notification members
205
207 int hold_nesting;
208 UniConfPairList deltas;
209
210protected:
212 UniConfGen();
213
214public:
216 virtual ~UniConfGen();
217
218 /***** Notification API *****/
219
224 virtual void add_callback(void *cookie,
225 const UniConfGenCallback &callback);
226 virtual void del_callback(void *cookie);
227
234 void dispatch_delta(const UniConfKey &key, WvStringParm value);
235
244 void hold_delta();
245
254 void unhold_delta();
255
260 void clear_delta();
261
266 void flush_delta();
267
274 void delta(const UniConfKey &key, WvStringParm value);
275
276 /***** Status API *****/
277 virtual bool isok();
278
279 /***** Key Persistence API *****/
280 virtual void commit() { }
281 virtual bool refresh() { return true; }
282 virtual void prefetch(const UniConfKey &key, bool recursive) { }
283 virtual WvString get(const UniConfKey &key) = 0;
284 virtual bool exists(const UniConfKey &key);
285 virtual int str2int(WvStringParm s, int defvalue) const;
286
287 /***** Key Storage API *****/
288 virtual void set(const UniConfKey &key, WvStringParm value) = 0;
289 virtual void setv(const UniConfPairList &pairs) = 0;
290
291 virtual void flush_buffers() = 0;
292
293 /***** Key Enumeration API *****/
294 virtual bool haschildren(const UniConfKey &key);
295 virtual Iter *iterator(const UniConfKey &key) = 0;
296
297 // a helpful default that just calls iterator() recursively
298 virtual Iter *recursiveiterator(const UniConfKey &key);
299
300protected:
301 // A naive implementation of setv() that uses only set().
302 void setv_naive(const UniConfPairList &pairs);
303};
304
305DeclareWvList(IUniConfGen);
306DeclareWvList2(UniConfGenList, IUniConfGen);
307
308
324{
325public:
327 virtual ~Iter() { }
328
333 virtual void rewind() = 0;
334
340 virtual bool next() = 0;
341
343 virtual UniConfKey key() const = 0;
344
349 virtual WvString value() const = 0;
350};
351
352
358{
359public:
360 /***** Overridden members *****/
361
362 virtual void rewind() { }
363 virtual bool next() { return false; }
364 virtual UniConfKey key() const { return UniConfKey::EMPTY; }
365 virtual WvString value() const { return WvString(); }
366};
367
368
369#endif // __UNICONFGEN_H
The basic interface which is included by all other XPLC interfaces and objects.
Definition: IObject.h:65
An abstract data container that backs a UniConf tree.
Definition: uniconfgen.h:40
virtual void setv(const UniConfPairList &pairs)=0
Stores multiple key-value pairs into the registry.
virtual bool exists(const UniConfKey &key)=0
Without fetching its value, returns true if a key exists.
virtual void flush_buffers()=0
Flushes any commitment/notification buffers .
virtual bool isok()=0
Determines if the generator is usable and working properly.
virtual bool haschildren(const UniConfKey &key)=0
Returns true if a key has children.
virtual bool refresh()=0
Refreshes information about a key recursively.
virtual Iter * iterator(const UniConfKey &key)=0
Returns an iterator over the children of the specified key.
virtual void prefetch(const UniConfKey &key, bool recursive)=0
Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" ope...
virtual int str2int(WvStringParm s, int defvalue) const =0
Converts a string to an integer.
virtual WvString get(const UniConfKey &key)=0
Fetches a string value for a key from the registry.
::UniListIter ListIter
An iterator over a constant list of keys (see below)
Definition: uniconfgen.h:163
virtual void add_callback(void *cookie, const UniConfGenCallback &callback)=0
Adds a callback for change notification.
virtual void commit()=0
Commits any changes.
virtual void del_callback(void *cookie)=0
Removes a callback for change notification.
virtual Iter * recursiveiterator(const UniConfKey &key)=0
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
virtual void set(const UniConfKey &key, WvStringParm value)=0
Stores a string value for a key into the registry.
An abstract iterator over keys and values in a generator.
Definition: uniconfgen.h:324
virtual bool next()=0
Seeks to the next element in the sequence.
virtual ~Iter()
Destroys the iterator.
Definition: uniconfgen.h:327
virtual WvString value() const =0
Returns the value of the current key.
virtual void rewind()=0
Rewinds the iterator.
virtual UniConfKey key() const =0
Returns the current key.
An iterator that's always empty.
Definition: uniconfgen.h:358
virtual bool next()
Seeks to the next element in the sequence.
Definition: uniconfgen.h:363
virtual UniConfKey key() const
Returns the current key.
Definition: uniconfgen.h:364
virtual WvString value() const
Returns the value of the current key.
Definition: uniconfgen.h:365
virtual void rewind()
Rewinds the iterator.
Definition: uniconfgen.h:362
A default implementation of IUniConfGen, providing various handy features that save trouble when impl...
Definition: uniconfgen.h:200
virtual void flush_buffers()=0
Flushes any commitment/notification buffers .
void dispatch_delta(const UniConfKey &key, WvStringParm value)
Immediately sends notification that a key has possibly changed.
Definition: uniconfgen.cc:71
void hold_delta()
Pauses notifications until matched with a call to unhold_delta().
Definition: uniconfgen.cc:32
virtual void setv(const UniConfPairList &pairs)=0
Stores multiple key-value pairs into the registry.
void unhold_delta()
Resumes notifications when each hold_delta() has been matched.
Definition: uniconfgen.cc:38
virtual ~UniConfGen()
Destroys the UniConfGen and may discard uncommitted data.
Definition: uniconfgen.cc:26
virtual void set(const UniConfKey &key, WvStringParm value)=0
Stores a string value for a key into the registry.
UniConfGen()
Creates a UniConfGen object.
Definition: uniconfgen.cc:20
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
Definition: uniconfgen.cc:77
virtual WvString get(const UniConfKey &key)=0
Fetches a string value for a key from the registry.
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
Definition: uniconfgen.cc:260
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
Definition: uniconfgen.cc:101
virtual void add_callback(void *cookie, const UniConfGenCallback &callback)
Adds a callback for change notification.
Definition: uniconfgen.cc:158
virtual int str2int(WvStringParm s, int defvalue) const
Converts a string to an integer.
Definition: uniconfgen.cc:126
virtual void del_callback(void *cookie)
Removes a callback for change notification.
Definition: uniconfgen.cc:165
void flush_delta()
Flushes the list of pending notifications by sending them.
Definition: uniconfgen.cc:53
virtual Iter * iterator(const UniConfKey &key)=0
Returns an iterator over the children of the specified key.
void clear_delta()
Clears the list of pending notifications without sending them.
Definition: uniconfgen.cc:47
virtual void commit()
Commits any changes.
Definition: uniconfgen.h:280
virtual bool isok()
Determines if the generator is usable and working properly.
Definition: uniconfgen.cc:152
virtual void prefetch(const UniConfKey &key, bool recursive)
Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" ope...
Definition: uniconfgen.h:282
virtual bool refresh()
Refreshes information about a key recursively.
Definition: uniconfgen.h:281
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
Definition: uniconfgen.cc:120
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:39
static UniConfKey EMPTY
Definition: uniconfkey.h:171
An iterator that iterates through a constant list of keys.
Definition: unilistiter.h:28
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition: wvstring.h:94
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:330
#define DEFINE_IID(iface, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11)
Used to define the IID of an interface.
Definition: uuid.h:134