WvStreams
uniunwrapgen.cc
1/*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
4 *
5 * A totally evil UniConfGen that "unwraps" a UniConf object by turning it
6 * back into a UniConfGen. See uniunwrapgen.h.
7 */
8#include "uniconfroot.h"
9#include "uniunwrapgen.h"
10#include "wvlinkerhack.h"
11
12WV_LINK(UniUnwrapGen);
13
14
15UniUnwrapGen::UniUnwrapGen(const UniConf &inner)
16{
17 refreshing = committing = false;
18 setinner(inner);
19}
20
21
22UniUnwrapGen::~UniUnwrapGen()
23{
24 UniConfRoot *root = xinner.rootobj();
25 if (root)
26 root->mounts.del_callback(this);
27}
28
29
30void UniUnwrapGen::setinner(const UniConf &inner)
31{
32 UniConfRoot *root = xinner.rootobj();
33 if (root)
34 root->mounts.del_callback(this);
35
36 xinner = inner;
37 xfullkey = xinner.fullkey();
38
39 root = xinner.rootobj();
40 if (root)
41 root->mounts.add_callback(this, wv::bind(&UniUnwrapGen::gencallback,
42 this, _1, _2));
43}
44
45
46UniConf UniUnwrapGen::_sub(const UniConfKey &key)
47{
48 if (key.isempty())
49 return xinner;
50 else
51 return xinner[key];
52}
53
54
56{
57 if (!committing)
58 {
59 committing = true;
60 xinner.commit();
61 committing = false;
62 }
63}
64
65
67{
68 if (!refreshing)
69 {
70 refreshing = true;
71 bool ret = xinner.refresh();
72 refreshing = false;
73 return ret;
74 }
75 return true;
76}
77
78
79void UniUnwrapGen::prefetch(const UniConfKey &key, bool recursive)
80{
81 _sub(key).prefetch(recursive);
82}
83
84
86{
87 return _sub(key).getme();
88}
89
90
91void UniUnwrapGen::set(const UniConfKey &key, WvStringParm value)
92{
93 _sub(key).setme(value);
94}
95
96
97void UniUnwrapGen::setv(const UniConfPairList &pairs)
98{
99 // Extremely evil. This pokes directly into UniMountGen, because we
100 // don't want to expose setv to users.
101 xinner.rootobj()->mounts.setv(pairs);
102}
103
104
106{
107 return _sub(key).exists();
108}
109
110
112{
113 return _sub(key).haschildren();
114}
115
116
118{
119 IUniConfGen *gen = xinner.whichmount();
120 return gen ? gen->isok() : false;
121}
122
123
125{
127
128public:
129 Iter(const UniConf &cfg)
130 : i(cfg)
131 { }
132 virtual ~Iter()
133 { }
134
135 /***** Overridden members *****/
136 virtual void rewind() { i.rewind(); }
137 virtual bool next() { return i.next(); }
138 virtual UniConfKey key() const { return i->key(); }
139 virtual WvString value() const { return i->getme(); }
140};
141
142
144{
146
147public:
148 RecursiveIter(const UniConf &cfg)
149 : i(cfg)
150 { }
151 virtual ~RecursiveIter()
152 { }
153
154 /***** Overridden members *****/
155 virtual void rewind() { i.rewind(); }
156 virtual bool next() { return i.next(); }
157 virtual UniConfKey key() const { return i->key(); }
158 virtual WvString value() const { return i->getme(); }
159};
160
161
163{
164 return new Iter(_sub(key));
165}
166
167
169{
170 return new RecursiveIter(_sub(key));
171}
172
173
174void UniUnwrapGen::gencallback(const UniConfKey &key, WvStringParm value)
175{
176 UniConfKey subkey;
177 if (xfullkey.suborsame(key, subkey))
178 delta(subkey, value);
179}
An abstract data container that backs a UniConf tree.
virtual bool isok()=0
Determines if the generator is usable and working properly.
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...
bool isempty() const
Returns true if this path has zero segments (also known as root).
bool suborsame(const UniConfKey &key) const
Returns true if 'key' is a the same, or a subkey, of this UniConfKey.
This iterator walks through all immediate children of a UniConf node.
This iterator performs depth-first traversal of a subtree.
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
void prefetch(bool recursive) const
See UniConfGen::prefetch().
Definition uniconf.cc:62
UniConfRoot * rootobj() const
Returns a pointer to the UniConfRoot that manages this node.
virtual ~Iter()
Destroys the iterator.
virtual UniConfKey key() const
Returns the current key.
virtual void rewind()
Rewinds the iterator.
virtual WvString value() const
Returns the value of the current key.
virtual bool next()
Seeks to the next element in the sequence.
virtual void rewind()
Rewinds the iterator.
virtual bool next()
Seeks to the next element in the sequence.
virtual WvString value() const
Returns the value of the current key.
virtual UniConfKey key() const
Returns the current key.
Deprecated: a UniConfGen that delegates all requests to an inner UniConf.
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 void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
virtual void commit()
Commits any changes.
virtual bool refresh()
Refreshes information about a key recursively.
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
const UniConf & inner() const
Returns the inner generator.
virtual bool isok()
Determines if the generator is usable and working properly.
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 bool haschildren(const UniConfKey &key)
Returns true if a key has children.
WvString is an implementation of a simple and efficient printable-string class.