WvStreams
uniautogen.cc
1 /*
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * A UniConf moniker that uses an .ini file to look up which moniker it
6  * should use to find the config file/subtree for a particular application.
7  */
8 #include "uniconfroot.h"
9 #include "unisubtreegen.h"
10 #include "wvlinkerhack.h"
11 
12 WV_LINK(UniAutoGen);
13 
14 
21 WvString uniautogen_moniker("default:ini:/etc/uniconf.conf");
22 
23 /*
24  * A moniker for finding the "right" config generator for a particular
25  * application, given the application name.
26  *
27  * For example, for moniker "auto:org/gnome/Nautilus", we would:
28  *
29  * - open /etc/uniconf.conf.
30  * - look for org/gnome/Nautilus in there.
31  * - if it exists, use that value as the config moniker, and return.
32  * - else, look for org/gnome
33  * - if it exists, go get that config moniker, take the subtree
34  * "Nautilus" from there, and return.
35  * - else, look for org
36  * - if it exists, go get that config moniker, take the subtree
37  * "gnome/Nautilus" from there, and return.
38  * - else, look for /
39  * - if it exists, go get that config moniker, take the subtree
40  * "org/gnome/Nautilus" from there, and return.
41  * - else, return a null: generator.
42  */
43 static IUniConfGen *creator(WvStringParm s, IObject *_obj)
44 {
45  UniConfRoot cfg((UniConfGen *)
46  wvcreate<IUniConfGen>(uniautogen_moniker, _obj), true);
47  const UniConfKey appname(s);
48 
49  for (int i = appname.numsegments(); i >= 0; i--)
50  {
51  UniConfKey prefix(appname.first(i)), suffix(appname.removefirst(i));
52 
53  if (!!cfg.xget(prefix))
54  {
55  return new UniSubtreeGen(wvcreate<IUniConfGen>(cfg.xget(prefix)),
56  suffix);
57  }
58  }
59 
60  return wvcreate<IUniConfGen>("null:");
61 }
62 
63 
64 static WvMoniker<IUniConfGen> autoreg("auto", creator);
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
IObject
Definition: IObject.h:65
UniConfGen
A default implementation of IUniConfGen, providing various handy features that save trouble when impl...
Definition: uniconfgen.h:199
UniSubtreeGen
A UniConfGen that returns only a particular subtree of a given generator.
Definition: unisubtreegen.h:18
UniConfRoot
Represents the root of a hierarhical registry consisting of pairs of UniConfKeys and associated strin...
Definition: uniconfroot.h:73