Make WvStreams compile with gcc 4.4.
[wvstreams.git] / uniconf / unisubtreegen.cc
blobf40cbdc3712272a173672afa76dc63c6b69044a6
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * A UniConfGen for returning only a particular subtree of a given generator.
6 */
7 #include "unisubtreegen.h"
8 #include "wvbuf.h"
9 #include "wvtclstring.h"
10 #include "wvmoniker.h"
11 #include "wvlinkerhack.h"
13 WV_LINK(UniSubtreeGen);
16 static IUniConfGen *creator(WvStringParm s, IObject *_obj)
18 WvConstInPlaceBuf buf(s, s.len());
19 WvString one(wvtcl_getword(buf)), two(wvtcl_getword(buf));
21 if (!one) one = "";
22 if (!two) two = "";
24 return new UniSubtreeGen(wvcreate<IUniConfGen>(one), two);
27 static WvMoniker<IUniConfGen> subtreereg("subtree", creator);
30 UniSubtreeGen::UniSubtreeGen(IUniConfGen *gen, const UniConfKey &_subkey)
31 : UniFilterGen(gen), subkey(_subkey)
33 // nothing special
37 bool UniSubtreeGen::keymap(const UniConfKey &unmapped_key, UniConfKey &mapped_key)
39 if (unmapped_key.isempty())
40 mapped_key = subkey;
41 else
42 mapped_key = UniConfKey(subkey, unmapped_key);
43 return true;
46 bool UniSubtreeGen::reversekeymap(const UniConfKey &mapped_key, UniConfKey &unmapped_key)
48 UniConfKey _unmapped_key;
49 bool result = subkey.suborsame(mapped_key, _unmapped_key);
50 if (result)
51 unmapped_key = _unmapped_key;
52 return result;