WvStreams
unidefgen.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * UniDefGen is a UniConfGen for retrieving data with defaults
00006  * 
00007  * Usable with the moniker default:
00008  */
00009 
00010 #ifndef __UNIDEFGEN_H
00011 #define __UNIDEFGEN_H
00012 
00013 #include "unifiltergen.h"
00014 
00015 /*
00016  * The defaults are stored and accessed by using a * in the keyname. The *
00017  * can represent either a segment of the path, or can can be left as a key
00018  * in a path so that any search to that path returns a result.
00019  *
00020  * (note: odd spacing is only to avoid putting * and / directly together)
00021  *
00022  * For example, you could set /twister/expression/ * /reality =
00023  * "/tmp/twister" and then a search for /twister/expression/bob/reality
00024  * would return the result.
00025  *
00026  * There is no limitation on where the * can be placed or the number of *s.
00027  * For example: /twister/ * / * / reality / *
00028  * would be an acceptable (though somewhat insane) use. This would make it
00029  * so a search to /twister/(whatever)/(whatever)/reality/(whatever) would
00030  * always return a key.
00031  *
00032  * If a more absolute path exists, then it will be returned instead of the
00033  * defaults. Precedence is given to matches existing closer to the end of
00034  * the key.
00035  *
00036  * If the key is set to '*n', it will return the n'th element from the end of
00037  * the absolute path that was passed in.  For instance, if
00038  * /twister/ * / * / reality is set to *1, then a search for
00039  * /twister/expression/bob/reality will return 'bob'.  If it is set to *2, the
00040  * search will return 'expression'.  If it were set to *3 (or *0), the result is
00041  * undefined.
00042  */
00043 class UniDefGen : public UniFilterGen
00044 {
00045     UniConfKey finddefault(const UniConfKey &key, char *p, char *q);
00046     WvString replacewildcard(const UniConfKey &key,
00047                              const UniConfKey &defkey, WvStringParm in);
00048 
00049 public:
00050     UniDefGen(IUniConfGen *gen) : UniFilterGen(gen) { }
00051 
00052     /***** Overridden members *****/
00053 
00054     virtual bool keymap(const UniConfKey &unmapped_key, UniConfKey &mapped_key);
00055     virtual void flush_buffers() { }
00056     virtual WvString get(const UniConfKey &key);
00057     virtual void set(const UniConfKey &key, WvStringParm value);
00058 };
00059 
00060 #endif // __UNIDEFGEN_H