00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "unilistgen.h"
00010 #include "wvmoniker.h"
00011 #include "wvtclstring.h"
00012 #include "wvstringlist.h"
00013
00014
00015
00016
00017
00018
00019
00020
00021 static UniConfGen *creator(WvStringParm s, IObject *obj, void *)
00022 {
00023 UniConfGenList *l = new UniConfGenList();
00024 UniConfGen *gen = NULL;
00025
00026 if (obj)
00027 {
00028 gen = mutate<UniConfGen>(obj);
00029 if (gen)
00030 l->append(gen, true);
00031 }
00032
00033 if (!gen)
00034 {
00035 WvStringList gens;
00036 wvtcl_decode(gens, s);
00037 WvStringList::Iter i(gens);
00038
00039 for (i.rewind(); i.next();)
00040 {
00041 gen = wvcreate<UniConfGen>(i());
00042 if (gen)
00043 l->append(gen, true);
00044 }
00045 }
00046
00047 return new UniListGen(l);
00048 }
00049
00050 static WvMoniker<UniConfGen> reg("list", creator);
00051
00052
00053 void UniListGen::commit()
00054 {
00055 for (i.rewind(); i.next();)
00056 i().commit();
00057 }
00058
00059 bool UniListGen::refresh()
00060 {
00061 bool result = true;
00062
00063 for (i.rewind(); i.next();)
00064 result = result && i().refresh();
00065 return result;
00066 }
00067
00068 WvString UniListGen::get(const UniConfKey &key)
00069 {
00070 for (i.rewind(); i.next();)
00071 {
00072 if (i().exists(key))
00073 return i().get(key);
00074 }
00075
00076 return WvString::null;
00077 }
00078
00079 void UniListGen::set(const UniConfKey &key, WvStringParm value)
00080 {
00081 for (i.rewind(); i.next();)
00082 i().set(key, value);
00083 }
00084
00085 bool UniListGen::exists(const UniConfKey &key)
00086 {
00087 for (i.rewind(); i.next();)
00088 {
00089 if (i().exists(key))
00090 return true;
00091 }
00092 return false;
00093 }
00094
00095 bool UniListGen::haschildren(const UniConfKey &key)
00096 {
00097 for (i.rewind(); i.next();)
00098 {
00099 if (i().haschildren(key))
00100 return true;
00101 }
00102 return false;
00103 }
00104
00105 bool UniListGen::isok()
00106 {
00107 for (i.rewind(); i.next();)
00108 {
00109 if (!i().isok())
00110 return false;
00111 }
00112 return true;
00113 }
00114
00115 UniConfGen::Iter *UniListGen::iterator(const UniConfKey &key)
00116 {
00117 return new IterIter(i, key);
00118 }
00119
00120
00121
00122
00123 UniListGen::IterIter::IterIter(UniConfGenList::Iter &geniter,
00124 const UniConfKey &key)
00125 {
00126 for (geniter.rewind(); geniter.next(); )
00127 l.append(geniter->iterator(key), true);
00128
00129 i = new IterList::Iter(l);
00130 }
00131
00132 void UniListGen::IterIter::rewind()
00133 {
00134 for ((*i).rewind(); (*i).next(); )
00135 (*i)->rewind();
00136
00137 i->rewind();
00138 i->next();
00139
00140 d.zap();
00141 }
00142
00143
00144 bool UniListGen::IterIter::next()
00145 {
00146 if ((*i)->next())
00147 {
00148
00149
00150 if (!d[(*i)->key()])
00151 {
00152 d.add(new UniConfKey((*i)->key()), true);
00153 return true;
00154 }
00155 else
00156 return next();
00157 }
00158
00159 if (!i->next())
00160 return false;
00161
00162 return next();
00163 }
00164
00165 UniConfKey UniListGen::IterIter::key() const
00166 {
00167 return (*i)->key();
00168 }