simple-options.h
Go to the documentation of this file.
1 // util/simple-options.h
2 
3 // Copyright 2013 Tanel Alumae, Tallinn University of Technology
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_UTIL_SIMPLE_OPTIONS_H_
21 #define KALDI_UTIL_SIMPLE_OPTIONS_H_
22 
23 #include <map>
24 #include <string>
25 #include <vector>
26 
27 #include "base/kaldi-common.h"
28 #include "itf/options-itf.h"
29 
30 namespace kaldi {
31 
32 
38 class SimpleOptions : public OptionsItf {
39  public:
41  }
42 
43  virtual ~SimpleOptions() {
44  }
45 
46  // Methods from the interface
47  void Register(const std::string &name, bool *ptr, const std::string &doc);
48  void Register(const std::string &name, int32 *ptr, const std::string &doc);
49  void Register(const std::string &name, uint32 *ptr, const std::string &doc);
50  void Register(const std::string &name, float *ptr, const std::string &doc);
51  void Register(const std::string &name, double *ptr, const std::string &doc);
52  void Register(const std::string &name, std::string *ptr,
53  const std::string &doc);
54 
55  // set option with the specified key, return true if successful
56  bool SetOption(const std::string &key, const bool &value);
57  bool SetOption(const std::string &key, const int32 &value);
58  bool SetOption(const std::string &key, const uint32 &value);
59  bool SetOption(const std::string &key, const float &value);
60  bool SetOption(const std::string &key, const double &value);
61  bool SetOption(const std::string &key, const std::string &value);
62  bool SetOption(const std::string &key, const char* value);
63 
64  // get option with the specified key and put to 'value',
65  // return true if successful
66  bool GetOption(const std::string &key, bool *value);
67  bool GetOption(const std::string &key, int32 *value);
68  bool GetOption(const std::string &key, uint32 *value);
69  bool GetOption(const std::string &key, float *value);
70  bool GetOption(const std::string &key, double *value);
71  bool GetOption(const std::string &key, std::string *value);
72 
73  enum OptionType {
80  };
81 
82  struct OptionInfo {
83  OptionInfo(const std::string &doc, OptionType type) :
84  doc(doc), type(type) {
85  }
86  std::string doc;
88  };
89 
90  std::vector<std::pair<std::string, OptionInfo> > GetOptionInfoList();
91 
92  /*
93  * Puts the type of the option with name 'key' in the argument 'type'.
94  * Return true if such option is found, false otherwise.
95  */
96  bool GetOptionType(const std::string &key, OptionType *type);
97 
98  private:
99 
100  std::vector<std::pair<std::string, OptionInfo> > option_info_list_;
101 
102  // maps for option variables
103  std::map<std::string, bool*> bool_map_;
104  std::map<std::string, int32*> int_map_;
105  std::map<std::string, uint32*> uint_map_;
106  std::map<std::string, float*> float_map_;
107  std::map<std::string, double*> double_map_;
108  std::map<std::string, std::string*> string_map_;
109 };
110 
111 } // namespace kaldi
112 
113 #endif // KALDI_UTIL_SIMPLE_OPTIONS_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
The class SimpleOptions is an implementation of OptionsItf that allows setting and getting option val...
kaldi::int32 int32
std::map< std::string, bool * > bool_map_
bool GetOptionType(const std::string &key, OptionType *type)
void Register(const std::string &name, bool *ptr, const std::string &doc)
std::vector< std::pair< std::string, OptionInfo > > GetOptionInfoList()
std::map< std::string, int32 * > int_map_
std::map< std::string, uint32 * > uint_map_
std::map< std::string, float * > float_map_
bool SetOption(const std::string &key, const bool &value)
OptionInfo(const std::string &doc, OptionType type)
std::map< std::string, double * > double_map_
bool GetOption(const std::string &key, bool *value)
std::vector< std::pair< std::string, OptionInfo > > option_info_list_
std::map< std::string, std::string * > string_map_