#include <props.h>
Public Types | |
typedef std::map< std::string, std::string * > | propmap |
The underlying implementation type. | |
typedef propmap::const_iterator | iterator |
Map iterator, *iterator is a pair<std::string,*std::string>. | |
Public Member Functions | |
Props () | |
Default constructor. | |
Props (std::istream &is) | |
Reads value=key pairs from istream. | |
virtual | ~Props () |
Virtual destructor. | |
Props & | erase (const std::string &key) |
Erase any value that is associated with key. | |
Props & | clear () |
Erase all key = value pairs from the property list. | |
Props & | add (const std::string &key, const std::string &value) |
Add a key = value pair. | |
Props & | append (const std::string &key, const std::string &value, const std::string &separator=" ") |
Append to a value associated with a key. | |
const std::string * | find (const std::string &key) const |
Try to find value for key, return null if not found. | |
const std::string * | operator() (const std::string &key) const |
Try to find value for key, return null if not found. | |
iterator | begin () const |
iterator | end () const |
unsigned | size () const |
std::istream & | read (std::istream &is, int n=-1) |
Read n key=value pairs from istream, or until eof if n <0. | |
ConstValue | operator>> (const char *key) const |
Return a reference to the key=value pair with the given key. | |
void | substitute (std::istream &sin, std::ostream &sout, std::string(*f)(const std::string &)=0) const throw (std::invalid_argument) |
Recursively substitute variable occurrences in sin to yield sout. | |
void | substitute (const std::string &sin, std::string &sout, std::string(*f)(const std::string &)=0) const throw (std::invalid_argument) |
Recursively substitute variable occurrences in sin to yield sout. | |
std::string | substitute (const std::string &sin, std::string(*f)(const std::string &)=0) const throw (std::invalid_argument) |
Same as above but returns result std::string. | |
Props & | select (const std::string &scope, Props &target) const |
Insert selected subkey=value pairs of this object into the target. | |
Props & | merge (const Props &source, const std::string &scope="") throw (PropsException) |
Load all key-value pairs from another props object under a certain scope. | |
bool | operator== (const Props &) const |
Compare two Props objects. | |
bool | operator!= (const Props &p) const |
std::ostream & | send (std::ostream &os) const |
Send a props object over a stream. | |
std::istream & | receive (std::istream &is) |
Receive a props object from a stream. | |
Props (const Props &props) throw (PropsException) | |
Copy construction is allowed. | |
Props & | operator= (const Props &props) throw (PropsException) |
Assignment allowed. | |
ConstValue | operator[] (const std::string &key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
ConstValue | operator[] (int key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
ConstValue | operator[] (unsigned int key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
ConstValue | operator[] (long key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
ConstValue | operator[] (unsigned long key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
ConstValue | operator[] (short key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
ConstValue | operator[] (unsigned short key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
ConstValue | operator[] (const double &key) const throw (PropsException) |
Key-based ``r-value'' access to properties. | |
Value | operator[] (const std::string &k) |
Key-based l-value access to properties. | |
Value | operator[] (int k) |
Key-based l-value access to properties. | |
Value | operator[] (unsigned int k) |
Key-based l-value access to properties. | |
Value | operator[] (long k) |
Key-based l-value access to properties. | |
Value | operator[] (unsigned long k) |
Key-based l-value access to properties. | |
Value | operator[] (short k) |
Key-based l-value access to properties. | |
Value | operator[] (unsigned short k) |
Key-based l-value access to properties. | |
Value | operator[] (const double &k) |
Key-based l-value access to properties. | |
Private Member Functions | |
std::string * | found (const std::string &key) |
Private Attributes | |
propmap | props_ |
Friends | |
std::ostream & | operator<< (std::ostream &, const Props &) |
Write the Props object to the stream, in the format described above. | |
std::istream & | operator>> (std::istream &is, Props &props) |
Read key-value pairs from istream until the end of the stream is reached or a syntax error occurs. |
A Props object represents a mapping from key strings to value strings. Values can be accessed with Props::operator[], using both strings or integers as a key (the latter will first be converted to strings); the resulting value will be converted to string or int, as required. The result of Props::operator[]} can be assigned to, thus giving a simple way to update.
A Props objects can be read from and written to a stream, in a format that is illustrated below (| indicates the beginning of a line):
|database=my-database |query=select name, semester |>from course |host=mainserver |# a comment |age=99
Note that
Definition at line 81 of file props.h.
|
The underlying implementation type. |
|
Map iterator, *iterator is a pair<std::string,*std::string>. |
|
Default constructor. |
|
Reads value=key pairs from istream.
ifstream ifs("/usr/local/share/z.config"); Props config(ifs); try { int max = config["max"]; } catch (PropsException& e) { cerr << "Configuration file does not define 'max'" << endl; exit(1); }
|
|
Virtual destructor.
|
|
Copy construction is allowed.
|
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based ``r-value'' access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Key-based l-value access to properties.
props["name"] = "lisa"; props[0] = "zero"; props[10] = 11; props["age"] = 21; int age(props["age"]); std::string name(props["name"]); int n(props[10]); |
|
Erase any value that is associated with key.
|
|
Erase all key = value pairs from the property list.
References props_. |
|
Add a key = value pair. Use Props::operator[] for automatic type conversion to std::string.
|
|
Append to a value associated with a key. The value, preceded by the separator, is appended to the current value associated with key. If there is no current value, Props::append behaves like Props::add.
|
|
Try to find value for key, return null if not found.
Referenced by operator()(), and operator>>(). |
|
Try to find value for key, return null if not found.
References find(). |
|
|
|
|
|
References props_. |
|
Read n key=value pairs from istream, or until eof if n <0. Note that the Props object is not cleared before reading the key=value pairs, they are simply added or override existing values.
|
|
Return a reference to the key=value pair with the given key. This is an auxiliary function. It supports expressions such as the following.
int value; Props props; props >> "key" >> value;
References find(). |
|
Recursively substitute variable occurrences in sin to yield sout.
Undefined (in *this) variables are replaced by the empty std::string. Example: std::string query("select * from"); props.substitute("person where name = '${name}' and age = %{age}", query,MySql::escape); Syntax:
|
|
Recursively substitute variable occurrences in sin to yield sout.
Undefined (in *this) variables are replaced by the empty std::string. Syntax:
|
|
Same as above but returns result std::string.
|
|
Insert selected subkey=value pairs of this object into the target. The selected pairs are those for which the key starts with the scope std::string followed by '::'. The pairs will be inserted with a key consisting of the remainder of the original key, after removing the scope std::string and '::'. Example.
In the example, if The function returns a reference to its second first argument.
|
|
Load all key-value pairs from another props object under a certain scope.
All key-value pairs from source will be added to *this, where the key will be prefixed with Example usage:
If
|
|
Compare two Props objects.
|
|
|
Send a props object over a stream. The difference with e.g. ostream& operator<<(ostream&,const Props::Value&);
|
|
Receive a props object from a stream. The difference with e.g. Props(istream&);
|
|
Assignment allowed.
|
|
|
|
Write the Props object to the stream, in the format described above.
|
|
Read key-value pairs from istream until the end of the stream is reached or a syntax error occurs.
|
|
dvutil-0.13.15 | [30 December, 2004] |