class for config parser
More...
#include <config.h>
|
typedef std::pair< std::string, std::string > | ConfigEntry |
| type when extracting from iterator More...
|
|
|
| Config (bool multi_value=false) |
| create empty config More...
|
|
| Config (std::istream &is, bool multi_value=false) |
| create config and load content from the given stream More...
|
|
void | Clear (void) |
| clear all the values More...
|
|
void | LoadFromStream (std::istream &is) |
| load the contents from the stream More...
|
|
template<class T > |
void | SetParam (const std::string &key, const T &value, bool is_string=false) |
| set a key-value pair into the config; if the key already exists in the configure file, it will either replace the old value with the given one (in non-multi value mode) or store it directly (in multi-value mode); More...
|
|
const std::string & | GetParam (const std::string &key) const |
| get the config under the key; if multiple values exist for the same key, return the last inserted one. More...
|
|
bool | IsGenuineString (const std::string &key) const |
| check whether the configure value given by the key should be wrapped by quotes More...
|
|
std::string | ToProtoString (void) const |
| transform all the configuration into string recognizable to protobuf More...
|
|
ConfigIterator | begin () const |
| get begin iterator More...
|
|
ConfigIterator | end () const |
| get end iterator More...
|
|
class for config parser
Two modes are supported:
- non-multi value mode: if two same keys in the configure file, the later one will replace the ealier one; when using iterator, the order will be the "last effective insersion" order
- multi value mode: multiple values with the same key could co-exist; when using iterator, the order will be the insersion order.
[Basic usage]
Config cfg(file_input_stream); for(Config::ConfigIterator iter = cfg.begin(); iter != cfg.end(); ++iter) { ConfigEntry ent = *iter; std::string key = ent.first; std::string value = ent.second; do_something_with(key, value); }
◆ ConfigEntry
type when extracting from iterator
◆ Config() [1/2]
dmlc::Config::Config |
( |
bool |
multi_value = false | ) |
|
|
explicit |
create empty config
- Parameters
-
multi_value | whether the config supports multi value |
◆ Config() [2/2]
dmlc::Config::Config |
( |
std::istream & |
is, |
|
|
bool |
multi_value = false |
|
) |
| |
|
explicit |
create config and load content from the given stream
- Parameters
-
is | input stream |
multi_value | whether the config supports multi value |
◆ begin()
get begin iterator
- Returns
- begin iterator
◆ Clear()
void dmlc::Config::Clear |
( |
void |
| ) |
|
◆ end()
get end iterator
- Returns
- end iterator
◆ GetParam()
const std::string& dmlc::Config::GetParam |
( |
const std::string & |
key | ) |
const |
get the config under the key; if multiple values exist for the same key, return the last inserted one.
- Parameters
-
- Returns
- config value
◆ IsGenuineString()
bool dmlc::Config::IsGenuineString |
( |
const std::string & |
key | ) |
const |
check whether the configure value given by the key should be wrapped by quotes
- Parameters
-
- Returns
- whether the configure value is represented by string
◆ LoadFromStream()
void dmlc::Config::LoadFromStream |
( |
std::istream & |
is | ) |
|
load the contents from the stream
- Parameters
-
◆ SetParam()
template<class T >
void dmlc::Config::SetParam |
( |
const std::string & |
key, |
|
|
const T & |
value, |
|
|
bool |
is_string = false |
|
) |
| |
set a key-value pair into the config; if the key already exists in the configure file, it will either replace the old value with the given one (in non-multi value mode) or store it directly (in multi-value mode);
- Parameters
-
key | key |
value | value |
is_string | whether the value should be wrapped by quotes in proto string |
◆ ToProtoString()
std::string dmlc::Config::ToProtoString |
( |
void |
| ) |
const |
transform all the configuration into string recognizable to protobuf
- Returns
- string that could be parsed directly by protobuf
The documentation for this class was generated from the following file:
- /work/mxnet/3rdparty/dmlc-core/include/dmlc/config.h