WvStreams
unilistiter.cc
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 2002 Net Integration Technologies, Inc.
00004  * 
00005  * A simple implementation of a UniConfGen iterator.  See unilistiter.h.
00006  */
00007 #include "unilistiter.h"
00008 
00009 UniListIter::UniListIter(IUniConfGen *_gen)
00010     : ki(keys), vi(values)
00011 {
00012     gen = _gen;
00013 }
00014 
00015 
00016 void UniListIter::add(const UniConfKey &k, WvStringParm v)
00017 { 
00018     UniConfKey *nk = new UniConfKey(k);
00019     keys.append(nk, true);
00020     keylook.add(nk, false);
00021     if (!v.isnull())
00022         values.append(new WvString(scache.get(v)), true);
00023 }
00024 
00025 
00026 void UniListIter::autofill(IUniConfGen::Iter *_source)
00027 {
00028     IUniConfGen::Iter &source(*_source);
00029     for (source.rewind(); source.next(); )
00030         add(source.key(), source.value());
00031 }
00032 
00033 
00034 void UniListIter::rewind()
00035 {
00036     ki.rewind();
00037     vi.rewind();
00038 }
00039 
00040 
00041 bool UniListIter::next()
00042 {
00043     if (vi.cur())
00044         vi.next();
00045     return ki.next();
00046 }
00047 
00048 
00049 UniConfKey UniListIter::key() const
00050 {
00051     return *ki;
00052 }
00053 
00054 
00055 WvString UniListIter::value() const
00056 {
00057     if (vi.cur())
00058         return *vi;
00059     else
00060         return gen->get(*ki);
00061 }