MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
sc::PrefixKeyVal Class Reference

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

#include <util/keyval/keyval.h>

Inheritance diagram for sc::PrefixKeyVal:
sc::KeyVal sc::RefCount

Public Member Functions

Constructors.

Construct a PrefixKeyVal, using the given prefix and indices.

 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)
 
const char * classname (const char *)
 Returns the name of the exact class of the object at the keyword.
 
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.
 
- Public Member Functions inherited from sc::KeyVal
int exists (const char *)
 This takes as its only argument a keyword.
 
int count (const char *=0)
 If the value of a keyword is an array, then return its length.
 
Ref< KeyValValuevalue (const char *key=0, const KeyValValue &def=KeyValValue())
 Return the value associated with the keyword.
 
int booleanvalue (const char *key=0, const KeyValValue &def=KeyValValueboolean())
 Returns the boolean value (0 = false, 1 = true) of key.
 
double doublevalue (const char *key=0, const KeyValValue &def=KeyValValuedouble())
 Returns the double value of key.
 
float floatvalue (const char *key=0, const KeyValValue &def=KeyValValuefloat())
 Returns the float value of key.
 
char charvalue (const char *key=0, const KeyValValue &def=KeyValValuechar())
 Returns the char value of key.
 
int intvalue (const char *key=0, const KeyValValue &def=KeyValValueint())
 Returns the int value of key.
 
long longvalue (const char *key=0, const KeyValValue &def=KeyValValuelong())
 Returns the long value of key.
 
size_t sizevalue (const char *key=0, const KeyValValue &def=KeyValValuesize())
 Returns the size_t value of key.
 
DEPRECATED char * pcharvalue (const char *key=0, const KeyValValue &def=KeyValValuestring())
 Returns a copy of the string representation of the key's value.
 
std::string stringvalue (const char *key=0, const KeyValValue &def=KeyValValuestring())
 Returns a string representation of the key's value.
 
Ref< DescribedClassdescribedclassvalue (const char *key=0, const KeyValValue &def=KeyValValueRefDescribedClass())
 Returns a reference to an object of type DescribedClass.
 
virtual Ref< DescribedClassdescribedclass (const char *classname)
 Returns a reference to an object of type DescribedClass using the top level keywords of this KeyVal.
 
int exists (const char *key, int i)
 
int count (const char *key, int i)
 
int booleanvalue (const char *key, int i, const KeyValValue &def=KeyValValueboolean())
 
double doublevalue (const char *key, int i, const KeyValValue &def=KeyValValuedouble())
 
float floatvalue (const char *key, int i, const KeyValValue &def=KeyValValuefloat())
 
char charvalue (const char *key, int i, const KeyValValue &def=KeyValValuechar())
 
int intvalue (const char *key, int i, const KeyValValue &def=KeyValValueint())
 
long longvalue (const char *key, int i, const KeyValValue &def=KeyValValuelong())
 
size_t sizevalue (const char *key, int i, const KeyValValue &def=KeyValValuesize())
 
DEPRECATED char * pcharvalue (const char *key, int i, const KeyValValue &def=KeyValValuestring())
 
std::string stringvalue (const char *key, int i, const KeyValValue &def=KeyValValuestring())
 
Ref< DescribedClassdescribedclassvalue (const char *key, int, const KeyValValue &def=KeyValValueRefDescribedClass())
 
int exists (int i)
 
int count (int i)
 
int booleanvalue (int i, const KeyValValue &def=KeyValValueboolean())
 
double doublevalue (int i, const KeyValValue &def=KeyValValuedouble())
 
float floatvalue (int i, const KeyValValue &def=KeyValValuefloat())
 
char charvalue (int i, const KeyValValue &def=KeyValValuechar())
 
int intvalue (int i, const KeyValValue &def=KeyValValueint())
 
long longvalue (int i, const KeyValValue &def=KeyValValuelong())
 
size_t sizevalue (int i, const KeyValValue &def=KeyValValuesize())
 
DEPRECATED char * pcharvalue (int i, const KeyValValue &def=KeyValValuestring())
 
std::string stringvalue (int i, const KeyValValue &def=KeyValValuestring())
 
Ref< DescribedClassdescribedclassvalue (int i, const KeyValValue &def=KeyValValueRefDescribedClass())
 
int exists (const char *, int, int)
 
int count (const char *, int, int)
 
int booleanvalue (const char *, int, int, const KeyValValue &def=KeyValValueboolean())
 
double doublevalue (const char *key, int, int, const KeyValValue &def=KeyValValuedouble())
 
float floatvalue (const char *key, int, int, const KeyValValue &def=KeyValValuefloat())
 
char charvalue (const char *key, int, int, const KeyValValue &def=KeyValValuechar())
 
int intvalue (const char *key, int, int, const KeyValValue &def=KeyValValueint())
 
long longvalue (const char *key, int, int, const KeyValValue &def=KeyValValuelong())
 
size_t sizevalue (const char *key, int, int, const KeyValValue &def=KeyValValuesize())
 
DEPRECATED char * pcharvalue (const char *key, int, int, const KeyValValue &def=KeyValValuestring())
 
std::string stringvalue (const char *key, int, int, const KeyValValue &def=KeyValValuestring())
 
Ref< DescribedClassdescribedclassvalue (const char *key, int, int, const KeyValValue &def=KeyValValueRefDescribedClass())
 
int exists (int i, int j)
 
int count (int i, int j)
 
int booleanvalue (int i, int j, const KeyValValue &def=KeyValValueboolean())
 
double doublevalue (int i, int j, const KeyValValue &def=KeyValValuedouble())
 
float floatvalue (int i, int j, const KeyValValue &def=KeyValValuefloat())
 
char charvalue (int i, int j, const KeyValValue &def=KeyValValuechar())
 
int intvalue (int i, int j, const KeyValValue &def=KeyValValueint())
 
long longvalue (int i, int j, const KeyValValue &def=KeyValValuelong())
 
size_t sizevalue (int i, int j, const KeyValValue &def=KeyValValuesize())
 
DEPRECATED char * pcharvalue (int i, int j, const KeyValValue &def=KeyValValuestring())
 
std::string stringvalue (int i, int j, const KeyValValue &def=KeyValValuestring())
 
Ref< DescribedClassdescribedclassvalue (int i, int j, const KeyValValue &def=KeyValValueRefDescribedClass())
 
int Va_exists (const char *key, int nindex,...)
 
int Va_count (const char *key, int nindex,...)
 
int Va_booleanvalue (const char *key, int nindex,...)
 
double Va_doublevalue (const char *key, int nindex,...)
 
float Va_floatvalue (const char *key, int nindex,...)
 
char Va_charvalue (const char *key, int nindex,...)
 
int Va_intvalue (const char *key, int nindex,...)
 
long Va_longvalue (const char *key, int nindex,...)
 
size_t Va_sizevalue (const char *key, int nindex,...)
 
DEPRECATED char * Va_pcharvalue (const char *key, int nindex,...)
 
std::string Va_stringvalue (const char *key, int nindex,...)
 
Ref< DescribedClassVa_describedclassvalue (const char *key, int nindex,...)
 
KeyValError error ()
 Return the current error condition.
 
const char * errormsg (KeyValError err)
 Return a textual representation of err.
 
const char * errormsg ()
 Return a textual representation of the current error.
 
virtual void print_unseen (std::ostream &fp=ExEnv::out0())
 Print keywords that were never looked at, if possible.
 
virtual int have_unseen ()
 Return 1 if there were unseen keywords, 0 if there are none, or -1 this keyval doesn't keep track of unseen keywords.
 
void verbose (int v)
 Control printing of assignments.
 
int verbose () const
 Returns nonzero if assignments are printed.
 
- Public Member Functions inherited from sc::RefCount
size_t identifier () const
 Return the unique identifier for this object that can be compared for different objects of different types.
 
int lock_ptr () const
 Lock this object.
 
int unlock_ptr () const
 Unlock this object.
 
void use_locks (bool inVal)
 start and stop using locks on this object
 
refcount_t nreference () const
 Return the reference count.
 
refcount_t reference ()
 Increment the reference count and return the new count.
 
refcount_t dereference ()
 Decrement the reference count and return the new count.
 
int managed () const
 Return 1 if the object is managed. Otherwise return 0.
 

Additional Inherited Members

- Public Types inherited from sc::KeyVal
enum  { MaxKeywordLength = 256 }
 
enum  KeyValError {
  OK , HasNoValue , WrongType , UnknownKeyword ,
  OperationFailed
}
 
- Protected Member Functions inherited from sc::KeyVal
void seterror (KeyValError err)
 Set the current error condition.
 
void seterror (KeyValValue::KeyValValueError err)
 Set the current error condition.
 
virtual int key_count (const char *=0)
 Ultimately called by count.
 
virtual int key_booleanvalue (const char *, const KeyValValue &def)
 Ultimately called by booleanvalue.
 
virtual double key_doublevalue (const char *key, const KeyValValue &def)
 Ultimately called by doublevalue.
 
virtual float key_floatvalue (const char *key, const KeyValValue &def)
 Ultimately called by floatvalue.
 
virtual char key_charvalue (const char *key, const KeyValValue &def)
 Ultimately called by charvalue.
 
virtual int key_intvalue (const char *key, const KeyValValue &def)
 Ultimately called by intvalue.
 
virtual long key_longvalue (const char *key, const KeyValValue &def)
 Ultimately called by longvalue.
 
virtual size_t key_sizevalue (const char *key, const KeyValValue &def)
 Ultimately called by sizevalue.
 
virtual DEPRECATED char * key_pcharvalue (const char *key, const KeyValValue &def)
 Ultimately called by pcharvalue.
 
virtual std::string key_stringvalue (const char *key, const KeyValValue &def)
 Ultimately called by stringvalue.
 
virtual Ref< DescribedClasskey_describedclassvalue (const char *key, const KeyValValue &def)
 Ultimately called by describedclassvalue.
 
- Protected Member Functions inherited from sc::RefCount
 RefCount (const RefCount &)
 
RefCountoperator= (const RefCount &)
 
- Protected Attributes inherited from sc::KeyVal
int verbose_
 

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(original_keyval,"A");
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> a_;
public:
B(const Ref<KeyVal> &keyval):
f1_(keyval->doublevalue("f1")),
a_(new PrefixKeyVal(keyval,"a"))
{}
};
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition class.h:233
A template class that maintains references counts.
Definition ref.h:361

can be used to read ParsedKeyVal input that looks like

b<B>: (
  f1 = 1.0
  a<A>: (
    f0 = 2.0
  )
)

Member Function Documentation

◆ classname()

const char * sc::PrefixKeyVal::classname ( const char * )
virtual

Returns the name of the exact class of the object at the keyword.

If no classname is assigned, or this KeyVal does not support classes, then 0 is returned.

Reimplemented from sc::KeyVal.

◆ dump()

void sc::PrefixKeyVal::dump ( std::ostream & fp = ExEnv::err0())
virtual

Write a message to fp describing the error.

Reimplemented from sc::KeyVal.

◆ errortrace()

void sc::PrefixKeyVal::errortrace ( std::ostream & fp = ExEnv::err0())
virtual

Write a message to fp describing the error.

Reimplemented from sc::KeyVal.


The documentation for this class was generated from the following file:

Generated at Wed Sep 25 2024 02:45:34 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.