WvStreams
unifiltergen.cc
1/*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
4 *
5 * A UniConfGen framework to simplify writing filtering generators.
6 */
7#include "unifiltergen.h"
8
9/***** UniFilterGen *****/
10
11UniFilterGen::UniFilterGen(IUniConfGen *inner)
12 : xinner(NULL)
13{
14 setinner(inner);
15}
16
17
18UniFilterGen::~UniFilterGen()
19{
20 IUniConfGen *gen = xinner;
21 setinner(NULL);
22 WVRELEASE(gen);
23}
24
25
27{
28 if (xinner)
29 xinner->del_callback(this);
30 xinner = inner;
31 if (xinner)
32 xinner->add_callback(this, wv::bind(&UniFilterGen::gencallback, this,
33 _1, _2));
34}
35
36
37bool UniFilterGen::keymap(const UniConfKey &unmapped_key, UniConfKey &mapped_key)
38{
39 // by default, don't rename the key
40 mapped_key = unmapped_key;
41 return true;
42}
43
44bool UniFilterGen::reversekeymap(const UniConfKey &mapped_key, UniConfKey &unmapped_key)
45{
46 // by default, don't rename the key
47 unmapped_key = mapped_key;
48 return true;
49}
50
51
53{
54 if (xinner)
55 xinner->commit();
56}
57
58
60{
61 if (xinner)
62 return xinner->refresh();
63 else
64 return false;
65}
66
67
68void UniFilterGen::prefetch(const UniConfKey &key, bool recursive)
69{
70 UniConfKey mapped_key;
71 if (xinner && keymap(key, mapped_key))
72 xinner->prefetch(mapped_key, recursive);
73}
74
75
77{
78 UniConfKey mapped_key;
79 if (xinner && keymap(key, mapped_key))
80 return xinner->get(mapped_key);
81 else
82 return WvString::null;
83}
84
85
87{
88 if (xinner)
89 xinner->flush_buffers();
90}
91
92
94{
95 UniConfKey mapped_key;
96 if (xinner && keymap(key, mapped_key))
97 xinner->set(mapped_key, value);
98}
99
100
101void UniFilterGen::setv(const UniConfPairList &pairs)
102{
103 if (xinner)
104 xinner->setv(pairs);
105}
106
107
109{
110 UniConfKey mapped_key;
111 if (xinner && keymap(key, mapped_key))
112 return xinner->exists(mapped_key);
113 else
114 return false;
115}
116
117
119{
120 UniConfKey mapped_key;
121 if (xinner && keymap(key, mapped_key))
122 return xinner->haschildren(mapped_key);
123 else
124 return false;
125}
126
127
129{
130 if (xinner)
131 return xinner->isok();
132 else
133 return false;
134}
135
136
138{
139 UniConfKey mapped_key;
140 if (xinner && keymap(key, mapped_key))
141 return xinner->iterator(mapped_key);
142 else
143 return NULL;
144}
145
146
148{
149 UniConfKey mapped_key;
150 if (xinner && keymap(key, mapped_key))
151 return xinner->recursiveiterator(mapped_key);
152 else
153 return NULL;
154}
155
156
158{
159 UniConfKey unmapped_key;
160 if (xinner && reversekeymap(key, unmapped_key))
161 delta(unmapped_key, value);
162}
An abstract data container that backs a UniConf tree.
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 WvString get(const UniConfKey &key)=0
Fetches a string value for a key from the registry.
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.
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
Definition uniconfgen.cc:77
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
virtual void prefetch(const UniConfKey &key, bool recursive)
Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" ope...
virtual void gencallback(const UniConfKey &key, WvStringParm value)
Called by inner generator when a key changes.
void setinner(IUniConfGen *inner)
Rebinds the inner generator and prepares its callback.
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into 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...
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
virtual bool keymap(const UniConfKey &unmapped_key, UniConfKey &mapped_key)
A mapping function for filters that remap one keyspace onto another.
IUniConfGen * inner() const
Returns the inner generator.
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
virtual bool refresh()
Refreshes information about a key recursively.
virtual void commit()
Commits any changes.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
virtual bool isok()
Determines if the generator is usable and working properly.
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
virtual void flush_buffers()
Flushes any commitment/notification buffers .
virtual bool reversekeymap(const UniConfKey &mapped_key, UniConfKey &unmapped_key)
A mapping function for filters that unmap a keyspace.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
WvString is an implementation of a simple and efficient printable-string class.