#include <env.h>
Public Types | |
enum | Type { NIL, STRING, MAP, ARRAY } |
Type of Box. More... | |
Public Methods | |
Env () | |
Create a NIL environment. | |
Env (const Env &e) | |
Create a deep copy of its argument. | |
Env (std::istream &is) throw (Exception) | |
Convenience constructor. | |
Env (const std::string &fn) throw (Exception) | |
Convenience constructor. | |
~Env () | |
Destructor. | |
const std::string & | svalue () const throw (Exception) |
Return string from an underlying SBox. | |
std::string & | slvalue () throw (Exception) |
Return non-const reference to string from an underlying SBox. | |
template<typename T> | operator T () const throw (Exception) |
Convert to any non-pointer type T for which operator>>(std::istream&,T&) is defined. | |
template<typename T> | operator T * () const throw (Exception) |
We refuse to convert to T*, except if T = const char. | |
operator const char * () const throw (Exception) | |
The exception about converting to pointers. | |
operator const std::string & () const throw (Exception) | |
Attempt to convert an Env to a string. | |
operator std::string & () throw (Exception) | |
Attempt to convert an Env to a non-const reference to a string. | |
bool | defined () const |
Check whether this environment has an associated Box. | |
Type | type () const |
Return type of underlying box. | |
bool | is_string () const |
Is this environment associated with a string box? | |
bool | is_array () const |
Is this environment associated with an array box? | |
bool | is_map () const |
Is this environment associated with a map box? | |
Env & | operator[] (int i) throw (Exception) |
Return lvalue environment associated with index i. | |
const Env & | operator() (int i) const throw (Exception) |
Return (const reference to) environment associated with index i. | |
Env & | operator[] (const std::string &s) throw (Exception) |
Return lvalue environment associated with key string s. | |
const Env & | operator() (const std::string &s) const throw (Exception) |
Return environment associated with key string s. | |
template<typename T> Env & | operator= (const T &t) |
Assign a T object to en environment. | |
Env & | operator= (const std::string &s) |
Specialization of assignment for string. | |
Env & | operator= (const Env &e) |
Specialization of assignment for Env. | |
Env & | clear () |
Clear an environment. | |
Env & | merge (const Env &e) |
Merge an environment into the current one. | |
size_t | size () const |
Return number of top-level entries in underlying structure. | |
template<typename T> bool | operator== (const T &t) const |
Compare after converting *this to T. | |
bool | operator== (const std::string &s) const |
Specialization of operator==(const T &) for string. | |
bool | operator== (const Env &e) const |
Specialization of operator==(const T &) for Env. | |
template<typename T> bool | operator!= (const T &t) const |
const Env & | substitute (std::ostream &os, std::istream &is) const throw (Exception) |
Copy is to os, recursively replacing variables by their value in *this. | |
const Env & | substitute (std::string &out, const std::string &ins) const throw (Exception) |
Copy ins to out, recursively replacing variables by their value in *this. | |
std::ostream & | print (std::ostream &os, const std::string &prefix="") const |
Auxiliary function for operator<<. | |
Env & | read_key (const std::string &s) throw (Exception) |
const Env * | access (const std::string &key) const |
Return child environment corresponding with key. | |
Env & | read (std::istream &is) throw (Dv::Util::Env::Exception) |
Merge environment data from is with this environment. | |
iterator | begin () const |
iterator | end () const |
Static Public Methods | |
const char * | type_s (Type t) |
const Env & | nil () |
Return reference to a fixed constant environment without a box. | |
bool | explode (const std::string &index, std::vector< std::string > &keys) |
Decompose index of form "a::b::c" into vector [a,b,c]. |
Here, ``extended environment'' means either a string or a finite mapping from string (or int) to string (or other environments). An Env object e corresponds to either
Env es, em, ev, e; es = "value"; // a string environment em["key"] = "value"; // a string environment ev[1] = "value"; e["es"] = es; // nesting e["key"] = em; e["vec"] = ev; cout << e["vec"][1]; // will print "value"
Env e; e["key"] = "value"; e[1] = "error"; // will throw exception
cout << e("key"); // throw exception if not defined e("key") = "value"; // will not compile
In general the following expressions are supported (we only show three occurrences of [i] or (i) but any number of them is allowed):
e[i][i][i] e[i][i][i] = t lt = e(i)(i)(i) if (e(i)(i)(i).defined()) ... if (e(i)(i)(i).is_array()) ... if (e(i)(i)(i).is_map()) ... if (e(i)(i)(i).is_string()) ...
|database::name=my-database |query=select name, semester |>from course |answer::0::field-1=f1 |answer::1::field-2=f2 |host=mainserver |# a comment |age=99
The format of a single entry is
entry = index '=' value \n
Note that
index = simple-index | index '::' simple-index ; simple-index = name | number ; name = [a-zA-Z_-][a-zA-Z_-0-9]* number = [0-9]+
|
Type of Box.
|
|
Create a NIL environment.
|
|
Create a deep copy of its argument.
|
|
Convenience constructor. Read a fresh environment from a stream.
|
|
Convenience constructor. Read a fresh environment from a file stream.
|
|
Destructor.
|
|
Return string from an underlying SBox.
|
|
Return non-const reference to string from an underlying SBox. If there is no underlying box, an SBox will be created.
|
|
Convert to any non-pointer type T for which operator>>(std::istream&,T&) is defined.
|
|
We refuse to convert to T*, except if T = const char.
|
|
The exception about converting to pointers.
|
|
Attempt to convert an Env to a string. Calls Env::Slvalue().
|
|
Attempt to convert an Env to a non-const reference to a string. Calls Env::Slvalue().
|
|
Check whether this environment has an associated Box.
|
|
Return type of underlying box.
|
|
|
|
Is this environment associated with a string box?
|
|
Is this environment associated with an array box?
|
|
Is this environment associated with a map box?
|
|
Return reference to a fixed constant environment without a box.
|
|
Return lvalue environment associated with index i. If the there is no box, an ABox will be created.
|
|
Return (const reference to) environment associated with index i.
|
|
Return lvalue environment associated with key string s. If the there is no box, an MBox will be created.
|
|
Return environment associated with key string s.
|
|
Assign a T object to en environment.
|
|
Specialization of assignment for string.
|
|
Specialization of assignment for Env.
|
|
Clear an environment.
|
|
Merge an environment into the current one. The merging proceeds as follows:
|
|
Return number of top-level entries in underlying structure.
|
|
Compare after converting *this to T.
|
|
Specialization of operator==(const T &) for string.
|
|
Specialization of operator==(const T &) for Env. Does a ``deep'' comparison.
|
|
|
|
Copy is to os, recursively replacing variables by their value in *this. A variable reference is of the form like ${k} ('$' can be escaped by preceding it with '\') where k is of the form i [ :: i ]+
|
|
Copy ins to out, recursively replacing variables by their value in *this. A variable reference is of the form like ${k} ('$' can be escaped by preceding it with '\') where k is of the form i [ :: i ]+
|
|
Auxiliary function for operator<<. Print *this in the format prefix key=value ..
|
|
|
|
Decompose index of form "a::b::c" into vector [a,b,c].
|
|
Return child environment corresponding with key.
|
|
Merge environment data from is with this environment. Environments written with operator<<(ostream&,const Env&) can be read with this function.
|
|
|
|
|
dvenv-0.2.2 | [20 October, 2002] |