28 #ifndef _util_keyval_keyval_h
29 #define _util_keyval_keyval_h
40 #include <util/class/class.h>
41 #include <util/misc/scexception.h>
42 #include <util/keyval/keyvalval.h>
74 enum {MaxKeywordLength = 256};
75 enum KeyValError { OK, HasNoValue, WrongType,
76 UnknownKeyword, OperationFailed };
81 void operator=(
const KeyVal&);
90 void seterror(KeyValValue::KeyValValueError err);
136 int count(
const char* =0);
164 DEPRECATED
char*
pcharvalue(
const char* key = 0,
175 virtual const char*
classname(
const char*);
190 int exists(
const char* key,
int i);
191 int count(
const char* key,
int i);
206 DEPRECATED
char*
pcharvalue(
const char* key,
int i,
244 int exists(
const char*,
int,
int);
245 int count(
const char*,
int,
int);
254 int intvalue(
const char* key,
int,
int,
258 size_t sizevalue(
const char* key,
int,
int,
260 DEPRECATED
char*
pcharvalue(
const char* key,
int,
int,
268 int count(
int i,
int j);
297 int Va_exists(
const char* key,
int nindex,...);
298 int Va_count(
const char* key,
int nindex,...);
299 int Va_booleanvalue(
const char* key,
int nindex,...);
300 double Va_doublevalue(
const char* key,
int nindex,...);
301 float Va_floatvalue(
const char* key,
int nindex,...);
302 char Va_charvalue(
const char* key,
int nindex,...);
303 int Va_intvalue(
const char* key,
int nindex,...);
304 long Va_longvalue(
const char* key,
int nindex,...);
305 size_t Va_sizevalue(
const char* key,
int nindex,...);
306 DEPRECATED
char* Va_pcharvalue(
const char* key,
int nindex,...);
307 std::string Va_stringvalue(
const char* key,
int nindex,...);
314 const char*
errormsg(KeyValError err);
342 typedef std::map<std::string,Ref<KeyValValue> > _map_t;
359 void assign(
const char* key,
double val);
360 void assignboolean(
const char* key,
int val);
361 void assign(
const char* key,
float val);
362 void assign(
const char* key,
char val);
363 void assign(
const char* key,
int val);
364 void assign(
const char* key,
long val);
365 void assign(
const char* key,
const char* val);
366 void assign(
const char* key,
const std::string& val);
379 template <
typename ValueType>
382 result->assign(key,
value);
396 std::map<std::string,Ref<KeyValValue> > _map;
408 virtual std::string
stringrep(
const char *key) = 0;
411 virtual const char*
classname(
const char*);
433 enum { MaxKeyVal = 4 };
512 void setup(
const char*,
int,
int,
int,
int,
int);
513 int getnewprefixkey(
const char*key,
char*newkey);
517 int key_exists(
const char*);
579 void read(
const char*);
581 void read(
const std::string &);
583 void read(std::istream&);
604 static bool eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
605 return kv->booleanvalue(key, i);
607 static bool eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
608 return kv->booleanvalue(key, i, j);
612 static double eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
613 return kv->doublevalue(key, i);
615 static double eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
616 return kv->doublevalue(key, i, j);
620 static float eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
621 return kv->floatvalue(key, i);
623 static float eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
624 return kv->floatvalue(key, i, j);
628 static int eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
629 return kv->intvalue(key, i);
631 static int eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
632 return kv->intvalue(key, i, j);
636 static long eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
637 return kv->longvalue(key, i);
639 static long eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
640 return kv->longvalue(key, i, j);
644 static std::size_t eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
645 return kv->sizevalue(key, i);
647 static std::size_t eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
648 return kv->sizevalue(key, i, j);
652 static char eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
653 return kv->charvalue(key, i);
655 static char eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
656 return kv->charvalue(key, i, j);
660 static std::string eval(
const Ref<KeyVal>& kv,
const char* key,
int i) {
661 return kv->stringvalue(key, i);
663 static std::string eval(
const Ref<KeyVal>& kv,
const char* key,
int i,
int j) {
664 return kv->stringvalue(key, i, j);
675 const std::string& key) : kv_(kv), key_(key) {}
678 const std::string& key()
const {
return key_; }
682 template <
typename Value,
typename Alloc>
684 const std::size_t n = kv_->count(key_.c_str());
686 for(std::size_t i=0; i<n; ++i) {
694 template <
typename Key,
typename Compare,
typename Alloc>
696 const std::size_t n = kv_->count(key_.c_str());
697 for(std::size_t i=0; i<n; ++i) {
705 template <
typename Key,
typename Data,
typename Compare,
typename Alloc>
707 const std::size_t n = kv_->count(key_.c_str());
708 for(std::size_t i=0; i<n; ++i) {
709 if (kv_->count(key_.c_str(),i) != 2) {
710 std::ostringstream oss;
711 oss << key_ <<
":" << i;
718 c.insert(std::make_pair(k,d));
ParsedKeyVal()
Create an empty ParsedKeyVal.
int intvalue(const char *key=0, const KeyValValue &def=KeyValValueint())
Returns the int value of key.
Represents a float value.
Definition: keyvalval.h:88
int key_exists(const char *)
Ultimately called by exists.
Keyword & operator>>(std::vector< Value, Alloc > &vec)
fills up std::vector using KeyVal object of the following form key = [ value0 value1 value2 ....
Definition: keyval.h:683
virtual void errortrace(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
DEPRECATED char * pcharvalue(const char *key=0, const KeyValValue &def=KeyValValuestring())
Returns a copy of the string representation of the key's value.
int have_unseen()
Return 1 if there were unseen keywords, 0 if there are none, or -1 this keyval doesn't keep track of ...
const char * classname(const char *)
Returns the name of the exact class of the object at the keyword.
int key_exists(const char *)
Ultimately called by exists.
virtual int key_intvalue(const char *key, const KeyValValue &def)
Ultimately called by intvalue.
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 ...
float floatvalue(const char *key=0, const KeyValValue &def=KeyValValuefloat())
Returns the float value of key.
virtual char key_charvalue(const char *key, const KeyValValue &def)
Ultimately called by charvalue.
virtual const char * classname(const char *)
Returns the name of the exact class of the object at the keyword.
GetValue(keyval, key, i) grabs the value corresponding to key.
Definition: keyval.h:602
void print(std::ostream &os=ExEnv::out0()) const
Represents a std::string value.
Definition: keyvalval.h:168
Represents a Ref<DescribedClass> value.
Definition: keyvalval.h:201
Represents a size_t value.
Definition: keyvalval.h:140
virtual void dump(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
void print_unseen(std::ostream &fp=ExEnv::out0())
Print keywords that were never looked at, if possible.
Ref< KeyValValue > value(const char *key=0, const KeyValValue &def=KeyValValue())
Return the value associated with the keyword.
void errortrace(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
int booleanvalue(const char *key=0, const KeyValValue &def=KeyValValueboolean())
Returns the boolean value (0 = false, 1 = true) of key.
virtual std::string stringrep(const char *key)=0
Returns the string representation of the value assigned to key.
virtual long key_longvalue(const char *key, const KeyValValue &def)
Ultimately called by longvalue.
void dump(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
virtual float key_floatvalue(const char *key, const KeyValValue &def)
Ultimately called by floatvalue.
int exists(const char *)
This takes as its only argument a keyword.
void clear()
Erase all of the stored assignments.
const char * classname(const char *)
Returns the name of the exact class of the object at the keyword.
virtual const char * truekeyword(const char *)
Returns a string which is the actual keyword if some sort of variable substitution takes place (neede...
virtual double key_doublevalue(const char *key, const KeyValValue &def)
Ultimately called by doublevalue.
virtual void print_unseen(std::ostream &fp=ExEnv::out0())
Print keywords that were never looked at, if possible.
virtual Ref< KeyValValue > key_value(const char *, const KeyValValue &def)=0
Ultimately called by value.
virtual std::string key_stringvalue(const char *key, const KeyValValue &def)
Ultimately called by stringvalue.
Ref< DescribedClass > describedclassvalue(const char *key=0, const KeyValValue &def=KeyValValueRefDescribedClass())
Returns a reference to an object of type DescribedClass.
const char * classname(const char *)
Returns the name of the exact class of the object at the keyword.
long longvalue(const char *key=0, const KeyValValue &def=KeyValValuelong())
Returns the long value of key.
virtual void dump(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
KeyValError error()
Return the current error condition.
void dump(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
Represents a long value.
Definition: keyvalval.h:127
static std::ostream & err0()
Return an ostream for error messages that writes from node 0.
Definition: exenv.h:87
std::string stringrep(const char *)
Returns the string representation of the value assigned to key.
Represents a boolean value.
Definition: keyvalval.h:75
virtual int key_booleanvalue(const char *, const KeyValValue &def)
Ultimately called by booleanvalue.
Keyword & operator>>(std::set< Key, Compare, Alloc > &c)
fills up std::set using KeyVal object of the following form key = [ key0 key1 key2 ....
Definition: keyval.h:695
virtual DEPRECATED char * key_pcharvalue(const char *key, const KeyValValue &def)
Ultimately called by pcharvalue.
Represents an int value.
Definition: keyvalval.h:114
size_t sizevalue(const char *key=0, const KeyValValue &def=KeyValValuesize())
Returns the size_t value of key.
Represents a char value.
Definition: keyvalval.h:101
int count(const char *=0)
If the value of a keyword is an array, then return its length.
Ref< KeyValValue > key_value(const char *, const KeyValValue &def)
Ultimately called by value.
Represents the value of a keyword.
Definition: keyvalval.h:38
const char * truekeyword(const char *)
Returns a string which is the actual keyword if some sort of variable substitution takes place (neede...
virtual void errortrace(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
virtual int key_exists(const char *)=0
Ultimately called by exists.
void dump(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
void read(const char *)
Read input data from the given filename.
std::string stringvalue(const char *key=0, const KeyValValue &def=KeyValValuestring())
Returns a string representation of the key's value.
int key_exists(const char *)
Ultimately called by exists.
const char * classname(const char *)
Returns the name of the exact class of the object at the keyword.
char charvalue(const char *key=0, const KeyValValue &def=KeyValValuechar())
Returns the char value of key.
void parse_string(const std::string &)
Read input data from the given string.
virtual const char * classname(const char *)
Returns the name of the exact class of the object at the keyword.
static void cat_files(const char *, const Ref< KeyVal > &, std::ostream &o)
This is like the ParsedKeyVal(const char*,const Ref<KeyVal>&) ctor, but writes the contents of the fi...
static std::ostream & out0()
Return an ostream that writes from node 0.
virtual int key_count(const char *=0)
Ultimately called by count.
void errortrace(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
const char * errormsg()
Return a textual representation of the current error.
The base class for all reference counted objects.
Definition: ref.h:192
double doublevalue(const char *key=0, const KeyValValue &def=KeyValValuedouble())
Returns the double value of key.
Represents a double value.
Definition: keyvalval.h:62
Ref< KeyValValue > key_value(const char *, const KeyValValue &def)
Ultimately called by value.
void errortrace(std::ostream &fp=ExEnv::err0())
Write a message to fp describing the error.
virtual Ref< DescribedClass > describedclass(const char *classname)
Returns a reference to an object of type DescribedClass using the top level keywords of this KeyVal.
virtual size_t key_sizevalue(const char *key, const KeyValValue &def)
Ultimately called by sizevalue.
virtual Ref< DescribedClass > key_describedclassvalue(const char *key, const KeyValValue &def)
Ultimately called by describedclassvalue.
void verbose(int v)
Control printing of assignments.
Definition: keyval.h:330
int verbose() const
Returns nonzero if assignments are printed.
Definition: keyval.h:332
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
Keyword & operator>>(std::map< Key, Data, Compare, Alloc > &c)
fills up std::map using KeyVal object of the following form key = [ [key0 value0] [key1 value1] [key2...
Definition: keyval.h:706
Ref< KeyValValue > key_value(const char *, const KeyValValue &def)
Ultimately called by value.
void seterror(KeyValError err)
Set the current error condition.
~ParsedKeyVal()
Cleanup, deleting the IPV2 object.
Generated at Sun Jan 26 2020 23:24:01 for MPQC
3.0.0-alpha using the documentation package Doxygen
1.8.16.