WvStreams
unisubtreegen.cc
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"
12 
13 WV_LINK(UniSubtreeGen);
14 
15 
16 static IUniConfGen *creator(WvStringParm s, IObject *_obj)
17 {
18  WvConstInPlaceBuf buf(s, s.len());
19  WvString one(wvtcl_getword(buf)), two(wvtcl_getword(buf));
20 
21  if (!one) one = "";
22  if (!two) two = "";
23 
24  return new UniSubtreeGen(wvcreate<IUniConfGen>(one), two);
25 }
26 
27 static WvMoniker<IUniConfGen> subtreereg("subtree", creator);
28 
29 
30 UniSubtreeGen::UniSubtreeGen(IUniConfGen *gen, const UniConfKey &_subkey)
31  : UniFilterGen(gen), subkey(_subkey)
32 {
33  // nothing special
34 }
35 
36 
37 bool UniSubtreeGen::keymap(const UniConfKey &unmapped_key, UniConfKey &mapped_key)
38 {
39  if (unmapped_key.isempty())
40  mapped_key = subkey;
41  else
42  mapped_key = UniConfKey(subkey, unmapped_key);
43  return true;
44 }
45 
46 bool UniSubtreeGen::reversekeymap(const UniConfKey &mapped_key, UniConfKey &unmapped_key)
47 {
48  UniConfKey _unmapped_key;
49  bool result = subkey.suborsame(mapped_key, _unmapped_key);
50  if (result)
51  unmapped_key = _unmapped_key;
52  return result;
53 }
wvtcl_getword
WvString wvtcl_getword(WvBuf &buf, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
Get a single tcl word from an input buffer, and return the rest of the buffer untouched.
Definition: wvtclstring.cc:359
UniSubtreeGen::keymap
virtual bool keymap(const UniConfKey &unmapped_key, UniConfKey &mapped_key)
A mapping function for filters that remap one keyspace onto another.
Definition: unisubtreegen.cc:37
wvtclstring.h
UniSubtreeGen::reversekeymap
virtual bool reversekeymap(const UniConfKey &mapped_key, UniConfKey &unmapped_key)
A mapping function for filters that unmap a keyspace.
Definition: unisubtreegen.cc:46
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
IUniConfGen
An abstract data container that backs a UniConf tree.
Definition: uniconfgen.h:39
UniConfKey
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:38
WvMoniker
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition: wvmoniker.h:61
UniConfKey::suborsame
bool suborsame(const UniConfKey &key) const
Returns true if 'key' is a the same, or a subkey, of this UniConfKey.
Definition: uniconfkey.cc:294
UniConfKey::isempty
bool isempty() const
Returns true if this path has zero segments (also known as root).
Definition: uniconfkey.h:264
IObject
Definition: IObject.h:65
WvConstInPlaceBuf
The const in place raw memory buffer type.
Definition: wvbuf.h:187
UniSubtreeGen
A UniConfGen that returns only a particular subtree of a given generator.
Definition: unisubtreegen.h:18
UniFilterGen
A UniConfGen that delegates all requests to an inner generator.
Definition: unifiltergen.h:17