Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

unilistgen.cc

Go to the documentation of this file.
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 2002 Net Integration Technologies, Inc. 00004 * 00005 * UniListGen is a UniConf generator to allow multiple generators to be 00006 * stacked in a priority sequence for get/set/etc. 00007 * 00008 */ 00009 #include "unilistgen.h" 00010 #include "wvmoniker.h" 00011 #include "wvtclstring.h" 00012 #include "wvstringlist.h" 00013 00014 00015 // if 'obj' is non-NULL and is a UniConfGen then whoever invoked this is being 00016 // silly. we'll make a list and add the single generator to it anyways, for the 00017 // sake of not breaking things 00018 // 00019 // otherwise, treat the moniker as a tcl list of monikers and add the generator 00020 // made by each moniker to the generator list 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 /***** UniListGen::IterIter *****/ 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 // When iterating, make sure each key value is only returned once (from 00149 // the top item in the list) 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 }

Generated on Tue Oct 5 01:09:19 2004 for WvStreams by doxygen 1.3.7