mxnet
Classes | Public Types | Public Member Functions | List of all members
dmlc::Config Class Reference

class for config parser More...

#include <config.h>

Collaboration diagram for dmlc::Config:
Collaboration graph

Classes

class  ConfigIterator
 iterator class More...
 

Public Types

typedef std::pair< std::string, std::string > ConfigEntry
 type when extracting from iterator More...
 

Public Member Functions

 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...
 

Detailed Description

class for config parser

Two modes are supported:

  1. 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
  2. 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); }

Member Typedef Documentation

typedef std::pair<std::string, std::string> dmlc::Config::ConfigEntry

type when extracting from iterator

Constructor & Destructor Documentation

dmlc::Config::Config ( bool  multi_value = false)
explicit

create empty config

Parameters
multi_valuewhether the config supports multi value
dmlc::Config::Config ( std::istream &  is,
bool  multi_value = false 
)
explicit

create config and load content from the given stream

Parameters
isinput stream
multi_valuewhether the config supports multi value

Member Function Documentation

ConfigIterator dmlc::Config::begin ( ) const

get begin iterator

Returns
begin iterator
void dmlc::Config::Clear ( void  )

clear all the values

ConfigIterator dmlc::Config::end ( ) const

get end iterator

Returns
end iterator
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
keykey
Returns
config value
bool dmlc::Config::IsGenuineString ( const std::string &  key) const

check whether the configure value given by the key should be wrapped by quotes

Parameters
keykey
Returns
whether the configure value is represented by string
void dmlc::Config::LoadFromStream ( std::istream &  is)

load the contents from the stream

Parameters
isthe stream as input
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
keykey
valuevalue
is_stringwhether the value should be wrapped by quotes in proto string
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: