2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
5 * A generator to make a UniConf object out of a WvConf.
8 #include "uniwvconfgen.h"
12 * A wrapper class for the wvconf iters to provide a UniConfGen iter.
14 class UniWvConfGen::WvConfIter
: public UniConfGen::Iter
17 WvConfigSection::Iter i
;
20 WvConfIter(WvConfigSection
*sect
);
22 /***** Overridden members *****/
24 virtual void rewind();
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
,
43 UniConfKey
key(section
, entry
);
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
),
60 UniWvConfGen::~UniWvConfGen()
67 WvString
UniWvConfGen::get(const UniConfKey
&key
)
69 if (tempkey
&& key
== *tempkey
)
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
);
85 cfg
->set(section
, keyname
, value
);
89 void UniWvConfGen::setv(const UniConfPairList
&pairs
)
95 bool UniWvConfGen::haschildren(const UniConfKey
&key
)
97 WvConfigSection
*sect
= (*cfg
)[key
];
104 UniWvConfGen::Iter
*UniWvConfGen::iterator(const UniConfKey
&key
)
106 WvConfigSection
*sect
= (*cfg
)[key
];
109 return new WvConfIter(sect
);
116 /***** UniWvConfGen::WvConfIter *****/
118 UniWvConfGen::WvConfIter::WvConfIter(WvConfigSection
*sect
)
124 void UniWvConfGen::WvConfIter::rewind()
130 bool UniWvConfGen::WvConfIter::next()
136 UniConfKey
UniWvConfGen::WvConfIter::key() const
142 WvString
UniWvConfGen::WvConfIter::value() const