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
13WV_LINK(UniSubtreeGen);
14
15
16static 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
27static WvMoniker<IUniConfGen> subtreereg("subtree", creator);
28
29
30UniSubtreeGen::UniSubtreeGen(IUniConfGen *gen, const UniConfKey &_subkey)
31 : UniFilterGen(gen), subkey(_subkey)
32{
33 // nothing special
34}
35
36
37bool 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
46bool 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}
The basic interface which is included by all other XPLC interfaces and objects.
Definition: IObject.h:65
An abstract data container that backs a UniConf tree.
Definition: uniconfgen.h:40
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:39
bool isempty() const
Returns true if this path has zero segments (also known as root).
Definition: uniconfkey.h:264
bool suborsame(const UniConfKey &key) const
Returns true if 'key' is a the same, or a subkey, of this UniConfKey.
Definition: uniconfkey.cc:294
A UniConfGen that delegates all requests to an inner generator.
Definition: unifiltergen.h:18
A UniConfGen that returns only a particular subtree of a given generator.
Definition: unisubtreegen.h:19
virtual bool reversekeymap(const UniConfKey &mapped_key, UniConfKey &unmapped_key)
A mapping function for filters that unmap a keyspace.
virtual bool keymap(const UniConfKey &unmapped_key, UniConfKey &mapped_key)
A mapping function for filters that remap one keyspace onto another.
The const in place raw memory buffer type.
Definition: wvbuf.h:188
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition: wvstring.h:94
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition: wvmoniker.h:62
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:330
Functions to handle "tcl-style" strings and lists.
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