2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
5 * A totally evil UniConfGen that "unwraps" a UniConf object by turning it
6 * back into a UniConfGen. See uniunwrapgen.h.
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;
22 UniUnwrapGen::~UniUnwrapGen()
24 UniConfRoot
*root
= xinner
.rootobj();
26 root
->mounts
.del_callback(this);
30 void UniUnwrapGen::setinner(const UniConf
&inner
)
32 UniConfRoot
*root
= xinner
.rootobj();
34 root
->mounts
.del_callback(this);
37 xfullkey
= xinner
.fullkey();
39 root
= xinner
.rootobj();
41 root
->mounts
.add_callback(this, wv::bind(&UniUnwrapGen::gencallback
,
46 UniConf
UniUnwrapGen::_sub(const UniConfKey
&key
)
55 void UniUnwrapGen::commit()
66 bool UniUnwrapGen::refresh()
71 bool ret
= xinner
.refresh();
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
129 Iter(const UniConf
&cfg
)
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
;
148 RecursiveIter(const UniConf
&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
)
177 if (xfullkey
.suborsame(key
, subkey
))
178 delta(subkey
, value
);