Fix several warnings that appear in gcc 4.3.2.
[wvstreams.git] / uniconf / uniunwrapgen.cc
blob0d8c3d58d810bde42200e6c0a5703a88a9cf5dc4
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"
12 WV_LINK(UniUnwrapGen);
15 UniUnwrapGen::UniUnwrapGen(const UniConf &inner)
17 refreshing = committing = false;
18 setinner(inner);
22 UniUnwrapGen::~UniUnwrapGen()
24 UniConfRoot *root = xinner.rootobj();
25 if (root)
26 root->mounts.del_callback(this);
30 void UniUnwrapGen::setinner(const UniConf &inner)
32 UniConfRoot *root = xinner.rootobj();
33 if (root)
34 root->mounts.del_callback(this);
36 xinner = inner;
37 xfullkey = xinner.fullkey();
39 root = xinner.rootobj();
40 if (root)
41 root->mounts.add_callback(this, wv::bind(&UniUnwrapGen::gencallback,
42 this, _1, _2));
46 UniConf UniUnwrapGen::_sub(const UniConfKey &key)
48 if (key.isempty())
49 return xinner;
50 else
51 return xinner[key];
55 void UniUnwrapGen::commit()
57 if (!committing)
59 committing = true;
60 xinner.commit();
61 committing = false;
66 bool UniUnwrapGen::refresh()
68 if (!refreshing)
70 refreshing = true;
71 bool ret = xinner.refresh();
72 refreshing = false;
73 return ret;
75 return true;
79 void UniUnwrapGen::prefetch(const UniConfKey &key, bool recursive)
81 _sub(key).prefetch(recursive);
85 WvString UniUnwrapGen::get(const UniConfKey &key)
87 return _sub(key).getme();
91 void UniUnwrapGen::set(const UniConfKey &key, WvStringParm value)
93 _sub(key).setme(value);
97 void UniUnwrapGen::setv(const UniConfPairList &pairs)
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);
105 bool UniUnwrapGen::exists(const UniConfKey &key)
107 return _sub(key).exists();
111 bool UniUnwrapGen::haschildren(const UniConfKey &key)
113 return _sub(key).haschildren();
117 bool UniUnwrapGen::isok()
119 IUniConfGen *gen = xinner.whichmount();
120 return gen ? gen->isok() : false;
124 class UniUnwrapGen::Iter : public UniConfGen::Iter
126 UniConf::Iter i;
128 public:
129 Iter(const UniConf &cfg)
130 : i(cfg)
132 virtual ~Iter()
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(); }
143 class UniUnwrapGen::RecursiveIter : public UniConfGen::Iter
145 UniConf::RecursiveIter i;
147 public:
148 RecursiveIter(const UniConf &cfg)
149 : i(cfg)
151 virtual ~RecursiveIter()
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(); }
162 UniConfGen::Iter *UniUnwrapGen::iterator(const UniConfKey &key)
164 return new Iter(_sub(key));
168 UniConfGen::Iter *UniUnwrapGen::recursiveiterator(const UniConfKey &key)
170 return new RecursiveIter(_sub(key));
174 void UniUnwrapGen::gencallback(const UniConfKey &key, WvStringParm value)
176 UniConfKey subkey;
177 if (xfullkey.suborsame(key, subkey))
178 delta(subkey, value);