SimpleOptions Class Reference

The class SimpleOptions is an implementation of OptionsItf that allows setting and getting option values programmatically, i.e., via getter and setter methods. More...

#include <simple-options.h>

Inheritance diagram for SimpleOptions:
Collaboration diagram for SimpleOptions:

Classes

struct  OptionInfo
 

Public Types

enum  OptionType {
  kBool, kInt32, kUint32, kFloat,
  kDouble, kString
}
 

Public Member Functions

 SimpleOptions ()
 
virtual ~SimpleOptions ()
 
void Register (const std::string &name, bool *ptr, const std::string &doc)
 
void Register (const std::string &name, int32 *ptr, const std::string &doc)
 
void Register (const std::string &name, uint32 *ptr, const std::string &doc)
 
void Register (const std::string &name, float *ptr, const std::string &doc)
 
void Register (const std::string &name, double *ptr, const std::string &doc)
 
void Register (const std::string &name, std::string *ptr, const std::string &doc)
 
bool SetOption (const std::string &key, const bool &value)
 
bool SetOption (const std::string &key, const int32 &value)
 
bool SetOption (const std::string &key, const uint32 &value)
 
bool SetOption (const std::string &key, const float &value)
 
bool SetOption (const std::string &key, const double &value)
 
bool SetOption (const std::string &key, const std::string &value)
 
bool SetOption (const std::string &key, const char *value)
 
bool GetOption (const std::string &key, bool *value)
 
bool GetOption (const std::string &key, int32 *value)
 
bool GetOption (const std::string &key, uint32 *value)
 
bool GetOption (const std::string &key, float *value)
 
bool GetOption (const std::string &key, double *value)
 
bool GetOption (const std::string &key, std::string *value)
 
std::vector< std::pair< std::string, OptionInfo > > GetOptionInfoList ()
 
bool GetOptionType (const std::string &key, OptionType *type)
 
- Public Member Functions inherited from OptionsItf
virtual ~OptionsItf ()
 

Private Attributes

std::vector< std::pair< std::string, OptionInfo > > option_info_list_
 
std::map< std::string, bool * > bool_map_
 
std::map< std::string, int32 * > int_map_
 
std::map< std::string, uint32 * > uint_map_
 
std::map< std::string, float * > float_map_
 
std::map< std::string, double * > double_map_
 
std::map< std::string, std::string * > string_map_
 

Detailed Description

The class SimpleOptions is an implementation of OptionsItf that allows setting and getting option values programmatically, i.e., via getter and setter methods.

It doesn't provide any command line parsing functionality. The class ParseOptions should be used for command-line options.

Definition at line 38 of file simple-options.h.

Member Enumeration Documentation

◆ OptionType

enum OptionType
Enumerator
kBool 
kInt32 
kUint32 
kFloat 
kDouble 
kString 

Definition at line 73 of file simple-options.h.

Constructor & Destructor Documentation

◆ SimpleOptions()

SimpleOptions ( )
inline

Definition at line 40 of file simple-options.h.

40  {
41  }

◆ ~SimpleOptions()

virtual ~SimpleOptions ( )
inlinevirtual

Definition at line 43 of file simple-options.h.

References SimpleOptions::GetOption(), SimpleOptions::Register(), and SimpleOptions::SetOption().

43  {
44  }

Member Function Documentation

◆ GetOption() [1/6]

bool GetOption ( const std::string &  key,
bool value 
)

Definition at line 140 of file simple-options.cc.

References SimpleOptions::bool_map_, and kaldi::GetOptionImpl().

Referenced by SimpleOptions::~SimpleOptions().

140  {
141  return GetOptionImpl(key, value, bool_map_);
142 }
std::map< std::string, bool * > bool_map_
static bool GetOptionImpl(const std::string &key, T *value, std::map< std::string, T *> &some_map)

◆ GetOption() [2/6]

bool GetOption ( const std::string &  key,
int32 value 
)

Definition at line 144 of file simple-options.cc.

References kaldi::GetOptionImpl(), and SimpleOptions::int_map_.

144  {
145  return GetOptionImpl(key, value, int_map_);
146 }
std::map< std::string, int32 * > int_map_
static bool GetOptionImpl(const std::string &key, T *value, std::map< std::string, T *> &some_map)

◆ GetOption() [3/6]

bool GetOption ( const std::string &  key,
uint32 *  value 
)

Definition at line 148 of file simple-options.cc.

References kaldi::GetOptionImpl(), and SimpleOptions::uint_map_.

148  {
149  return GetOptionImpl(key, value, uint_map_);
150 }
std::map< std::string, uint32 * > uint_map_
static bool GetOptionImpl(const std::string &key, T *value, std::map< std::string, T *> &some_map)

◆ GetOption() [4/6]

bool GetOption ( const std::string &  key,
float value 
)

Definition at line 152 of file simple-options.cc.

References SimpleOptions::float_map_, and kaldi::GetOptionImpl().

152  {
153  return GetOptionImpl(key, value, float_map_);
154 }
std::map< std::string, float * > float_map_
static bool GetOptionImpl(const std::string &key, T *value, std::map< std::string, T *> &some_map)

◆ GetOption() [5/6]

bool GetOption ( const std::string &  key,
double *  value 
)

Definition at line 156 of file simple-options.cc.

References SimpleOptions::double_map_, and kaldi::GetOptionImpl().

156  {
157  return GetOptionImpl(key, value, double_map_);
158 }
static bool GetOptionImpl(const std::string &key, T *value, std::map< std::string, T *> &some_map)
std::map< std::string, double * > double_map_

◆ GetOption() [6/6]

bool GetOption ( const std::string &  key,
std::string *  value 
)

Definition at line 160 of file simple-options.cc.

References kaldi::GetOptionImpl(), and SimpleOptions::string_map_.

160  {
161  return GetOptionImpl(key, value, string_map_);
162 }
static bool GetOptionImpl(const std::string &key, T *value, std::map< std::string, T *> &some_map)
std::map< std::string, std::string * > string_map_

◆ GetOptionInfoList()

std::vector< std::pair< std::string, SimpleOptions::OptionInfo > > GetOptionInfoList ( )

Definition at line 165 of file simple-options.cc.

References SimpleOptions::option_info_list_.

165  {
166  return option_info_list_;
167 }
std::vector< std::pair< std::string, OptionInfo > > option_info_list_

◆ GetOptionType()

bool GetOptionType ( const std::string &  key,
OptionType type 
)

Definition at line 169 of file simple-options.cc.

References SimpleOptions::option_info_list_.

Referenced by kaldi::UnitTestSimpleOptions().

169  {
170  for (std::vector <std::pair<std::string,
171  OptionInfo> >::iterator dx = option_info_list_.begin();
172  dx != option_info_list_.end(); dx++) {
173  std::pair<std::string, SimpleOptions::OptionInfo> info_pair = (*dx);
174  if (info_pair.first == key) {
175  *type = info_pair.second.type;
176  return true;
177  }
178  }
179  return false;
180 }
std::vector< std::pair< std::string, OptionInfo > > option_info_list_

◆ Register() [1/6]

void Register ( const std::string &  name,
bool ptr,
const std::string &  doc 
)
virtual

Implements OptionsItf.

Definition at line 26 of file simple-options.cc.

References SimpleOptions::bool_map_, SimpleOptions::kBool, and SimpleOptions::option_info_list_.

Referenced by kaldi::UnitTestSimpleOptions(), and SimpleOptions::~SimpleOptions().

28  {
29  bool_map_[name] = value;
30  option_info_list_.push_back(std::make_pair(name, OptionInfo(doc, kBool)));
31 }
std::map< std::string, bool * > bool_map_
std::vector< std::pair< std::string, OptionInfo > > option_info_list_

◆ Register() [2/6]

void Register ( const std::string &  name,
int32 ptr,
const std::string &  doc 
)
virtual

Implements OptionsItf.

Definition at line 33 of file simple-options.cc.

References SimpleOptions::int_map_, SimpleOptions::kInt32, and SimpleOptions::option_info_list_.

35  {
36  int_map_[name] = value;
37  option_info_list_.push_back(std::make_pair(name, OptionInfo(doc, kInt32)));
38 }
std::map< std::string, int32 * > int_map_
std::vector< std::pair< std::string, OptionInfo > > option_info_list_

◆ Register() [3/6]

void Register ( const std::string &  name,
uint32 *  ptr,
const std::string &  doc 
)
virtual

Implements OptionsItf.

Definition at line 40 of file simple-options.cc.

References SimpleOptions::kUint32, SimpleOptions::option_info_list_, and SimpleOptions::uint_map_.

42  {
43  uint_map_[name] = value;
44  option_info_list_.push_back(std::make_pair(name, OptionInfo(doc, kUint32)));
45 }
std::map< std::string, uint32 * > uint_map_
std::vector< std::pair< std::string, OptionInfo > > option_info_list_

◆ Register() [4/6]

void Register ( const std::string &  name,
float ptr,
const std::string &  doc 
)
virtual

Implements OptionsItf.

Definition at line 47 of file simple-options.cc.

References SimpleOptions::float_map_, SimpleOptions::kFloat, and SimpleOptions::option_info_list_.

49  {
50  float_map_[name] = value;
51  option_info_list_.push_back(std::make_pair(name, OptionInfo(doc, kFloat)));
52 }
std::map< std::string, float * > float_map_
std::vector< std::pair< std::string, OptionInfo > > option_info_list_

◆ Register() [5/6]

void Register ( const std::string &  name,
double *  ptr,
const std::string &  doc 
)
virtual

Implements OptionsItf.

Definition at line 54 of file simple-options.cc.

References SimpleOptions::double_map_, SimpleOptions::kDouble, and SimpleOptions::option_info_list_.

56  {
57  double_map_[name] = value;
58  option_info_list_.push_back(std::make_pair(name, OptionInfo(doc, kDouble)));
59 }
std::map< std::string, double * > double_map_
std::vector< std::pair< std::string, OptionInfo > > option_info_list_

◆ Register() [6/6]

void Register ( const std::string &  name,
std::string *  ptr,
const std::string &  doc 
)
virtual

Implements OptionsItf.

Definition at line 61 of file simple-options.cc.

References SimpleOptions::kString, SimpleOptions::option_info_list_, and SimpleOptions::string_map_.

63  {
64  string_map_[name] = value;
65  option_info_list_.push_back(std::make_pair(name, OptionInfo(doc, kString)));
66 }
std::vector< std::pair< std::string, OptionInfo > > option_info_list_
std::map< std::string, std::string * > string_map_

◆ SetOption() [1/7]

bool SetOption ( const std::string &  key,
const bool value 
)

Definition at line 78 of file simple-options.cc.

References SimpleOptions::bool_map_, and kaldi::SetOptionImpl().

Referenced by kaldi::UnitTestSimpleOptions(), and SimpleOptions::~SimpleOptions().

78  {
79  return SetOptionImpl(key, value, bool_map_);
80 }
std::map< std::string, bool * > bool_map_
static bool SetOptionImpl(const std::string &key, const T &value, std::map< std::string, T *> &some_map)

◆ SetOption() [2/7]

bool SetOption ( const std::string &  key,
const int32 value 
)

Definition at line 82 of file simple-options.cc.

References SimpleOptions::int_map_, kaldi::SetOptionImpl(), and SimpleOptions::uint_map_.

82  {
83  if (!SetOptionImpl(key, value, int_map_)) {
84  if (!SetOptionImpl(key, static_cast<uint32>(value), uint_map_)) {
85  return false;
86  }
87  }
88  return true;
89 }
std::map< std::string, int32 * > int_map_
static bool SetOptionImpl(const std::string &key, const T &value, std::map< std::string, T *> &some_map)
std::map< std::string, uint32 * > uint_map_

◆ SetOption() [3/7]

bool SetOption ( const std::string &  key,
const uint32 &  value 
)

Definition at line 91 of file simple-options.cc.

References SimpleOptions::int_map_, kaldi::SetOptionImpl(), and SimpleOptions::uint_map_.

91  {
92  if (!SetOptionImpl(key, value, uint_map_)) {
93  if (!SetOptionImpl(key, static_cast<int32>(value), int_map_)) {
94  return false;
95  }
96  }
97  return true;
98 }
std::map< std::string, int32 * > int_map_
static bool SetOptionImpl(const std::string &key, const T &value, std::map< std::string, T *> &some_map)
std::map< std::string, uint32 * > uint_map_

◆ SetOption() [4/7]

bool SetOption ( const std::string &  key,
const float value 
)

Definition at line 100 of file simple-options.cc.

References SimpleOptions::double_map_, SimpleOptions::float_map_, and kaldi::SetOptionImpl().

100  {
101  if (!SetOptionImpl(key, value, float_map_)) {
102  if (!SetOptionImpl(key, static_cast<double>(value), double_map_)) {
103  return false;
104  }
105  }
106  return true;
107 }
static bool SetOptionImpl(const std::string &key, const T &value, std::map< std::string, T *> &some_map)
std::map< std::string, float * > float_map_
std::map< std::string, double * > double_map_

◆ SetOption() [5/7]

bool SetOption ( const std::string &  key,
const double &  value 
)

Definition at line 109 of file simple-options.cc.

References SimpleOptions::double_map_, SimpleOptions::float_map_, and kaldi::SetOptionImpl().

109  {
110  if (!SetOptionImpl(key, value, double_map_)) {
111  if (!SetOptionImpl(key, static_cast<float>(value), float_map_)) {
112  return false;
113  }
114  }
115  return true;
116 }
static bool SetOptionImpl(const std::string &key, const T &value, std::map< std::string, T *> &some_map)
std::map< std::string, float * > float_map_
std::map< std::string, double * > double_map_

◆ SetOption() [6/7]

bool SetOption ( const std::string &  key,
const std::string &  value 
)

Definition at line 118 of file simple-options.cc.

References kaldi::SetOptionImpl(), and SimpleOptions::string_map_.

119  {
120  return SetOptionImpl(key, value, string_map_);
121 }
static bool SetOptionImpl(const std::string &key, const T &value, std::map< std::string, T *> &some_map)
std::map< std::string, std::string * > string_map_

◆ SetOption() [7/7]

bool SetOption ( const std::string &  key,
const char *  value 
)

Definition at line 123 of file simple-options.cc.

References kaldi::SetOptionImpl(), and SimpleOptions::string_map_.

123  {
124  std::string str_value = std::string(value);
125  return SetOptionImpl(key, str_value, string_map_);
126 }
static bool SetOptionImpl(const std::string &key, const T &value, std::map< std::string, T *> &some_map)
std::map< std::string, std::string * > string_map_

Member Data Documentation

◆ bool_map_

std::map<std::string, bool*> bool_map_
private

◆ double_map_

std::map<std::string, double*> double_map_
private

◆ float_map_

std::map<std::string, float*> float_map_
private

◆ int_map_

std::map<std::string, int32*> int_map_
private

◆ option_info_list_

std::vector<std::pair<std::string, OptionInfo> > option_info_list_
private

◆ string_map_

std::map<std::string, std::string*> string_map_
private

◆ uint_map_

std::map<std::string, uint32*> uint_map_
private

The documentation for this class was generated from the following files: