Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

sc::PrefixKeyVal Class Reference

PrefixKeyVal is a KeyVal that searches a different KeyVal using modified keys. More...

#include <keyval.h>

Inheritance diagram for sc::PrefixKeyVal:

sc::KeyVal sc::RefCount sc::Identity List of all members.

Public Member Functions

void errortrace (std::ostream &fp=ExEnv::err0())
 Write a message to fp describing the error.

void dump (std::ostream &fp=ExEnv::err0())
 Write a message to fp describing the error.

 PrefixKeyVal (const Ref< KeyVal > &, int i)
 PrefixKeyVal (const Ref< KeyVal > &, int i, int j)
 PrefixKeyVal (const Ref< KeyVal > &, int i, int j, int k)
 PrefixKeyVal (const Ref< KeyVal > &, int i, int j, int k, int l)
 PrefixKeyVal (const Ref< KeyVal > &, const char *prefix)
 PrefixKeyVal (const Ref< KeyVal > &, const char *prefix, int i)
 PrefixKeyVal (const Ref< KeyVal > &, const char *prefix, int i, int j)
 PrefixKeyVal (const Ref< KeyVal > &, const char *prefix, int i, int j, int k)
 PrefixKeyVal (const Ref< KeyVal > &, const char *prefix, int i, int j, int k, int l)
 PrefixKeyVal (const char *, const Ref< KeyVal > &)
 PrefixKeyVal (const char *, const Ref< KeyVal > &, int)
 PrefixKeyVal (const char *, const Ref< KeyVal > &, int, int)
 PrefixKeyVal (const char *, const Ref< KeyVal > &, int, int, int)
 PrefixKeyVal (const char *, const Ref< KeyVal > &, int, int, int, int)

Detailed Description

PrefixKeyVal is a KeyVal that searches a different KeyVal using modified keys.

This is convenient for reading keys grouped together with a common prefix. Consider the following code:

sc::Ref<sc::KeyVal> keyval = new sc::PrefixKeyVal("A",original_keyval); int r = keyval->intvalue("x");
This code will assign to r the value associated with "x" in keyval. keyval will search for "x" by searching for "A::x" in original_keyval.

This class is important for implementing constructors that take KeyVal arguments. When an object is being constructed from a KeyVal, it may contain another object that must be constructed from a KeyVal. In order to let the sub-object read the correct keywords from the KeyVal, without knowledge of the containing objects keyword prefix, a PrefixKeyVal can be constructed. For example, the code

class A: public DescribedClass { double f0_; public: A(const Ref<KeyVal> &keyval): f0_(keyval->doublevalue("f0")) {} } class B: public DescribedClass { double f1_; Ref a_; public: B(const Ref<KeyVal> &keyval): f1_(keyval->doublevalue("f1")), a_(new PrefixKeyVal(keyval,"a")) {} };
can be used to read ParsedKeyVal input that looks like
b: ( f1 = 1.0 a: ( f0 = 2.0 ) )


The documentation for this class was generated from the following file:
Generated at Fri Mar 19 10:48:36 2004 for MPQC 2.2.1 using the documentation package Doxygen 1.3.5.