Fix several warnings that appear in gcc 4.3.2.
[wvstreams.git] / uniconf / uniwvconfgen.cc
blob097d541c7391d20bf85097c275802d3f569d6303
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
4 *
5 * A generator to make a UniConf object out of a WvConf.
6 */
7 #include "wvconf.h"
8 #include "uniwvconfgen.h"
9 #include "wvmoniker.h"
11 /**
12 * A wrapper class for the wvconf iters to provide a UniConfGen iter.
14 class UniWvConfGen::WvConfIter : public UniConfGen::Iter
16 protected:
17 WvConfigSection::Iter i;
19 public:
20 WvConfIter(WvConfigSection *sect);
22 /***** Overridden members *****/
24 virtual void rewind();
25 virtual bool next();
26 virtual UniConfKey key() const;
27 virtual WvString value() const;
31 static IUniConfGen *creator(WvStringParm s, IObject*)
33 return new UniWvConfGen(new WvConf(s));
36 static WvMoniker<IUniConfGen> reg("wvconf", creator);
39 void UniWvConfGen::notify(void *userdata, WvStringParm section,
40 WvStringParm entry, WvStringParm oldval,
41 WvStringParm newval)
43 UniConfKey key(section, entry);
45 tempvalue = newval;
46 tempkey = &key;
47 delta(key, newval);
48 tempkey = NULL;
52 UniWvConfGen::UniWvConfGen(WvConf *_cfg):
53 tempkey(NULL), tempvalue(), cfg(_cfg)
55 cfg->add_callback(wv::bind(&UniWvConfGen::notify, this, _1, _2, _3, _4, _5),
56 NULL, "", "", this);
60 UniWvConfGen::~UniWvConfGen()
62 if (cfg)
63 delete cfg;
67 WvString UniWvConfGen::get(const UniConfKey &key)
69 if (tempkey && key == *tempkey)
70 return tempvalue;
71 else
72 return cfg->get(key.first(), key.last(key.numsegments() - 1));
76 void UniWvConfGen::set(const UniConfKey &key, WvStringParm value)
78 WvString section = key.first();
79 WvString keyname = key.last(key.numsegments() - 1);
81 WvConfigSection *sect = (*cfg)[section];
82 if (value == WvString::null && sect)
83 cfg->delete_section(key);
84 else
85 cfg->set(section, keyname, value);
89 void UniWvConfGen::setv(const UniConfPairList &pairs)
91 setv_naive(pairs);
95 bool UniWvConfGen::haschildren(const UniConfKey &key)
97 WvConfigSection *sect = (*cfg)[key];
98 if (sect)
99 return true;
100 return false;
104 UniWvConfGen::Iter *UniWvConfGen::iterator(const UniConfKey &key)
106 WvConfigSection *sect = (*cfg)[key];
108 if (sect)
109 return new WvConfIter(sect);
110 else
111 return NULL;
116 /***** UniWvConfGen::WvConfIter *****/
118 UniWvConfGen::WvConfIter::WvConfIter(WvConfigSection *sect)
119 : i(*sect)
124 void UniWvConfGen::WvConfIter::rewind()
126 i.rewind();
130 bool UniWvConfGen::WvConfIter::next()
132 return i.next();
136 UniConfKey UniWvConfGen::WvConfIter::key() const
138 return i->name;
142 WvString UniWvConfGen::WvConfIter::value() const
144 return i->value;