Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
INIReader.h
Go to the documentation of this file.
1 // Read an INI file into easy-to-access name/value pairs.
2 
3 // inih and INIReader are released under the New BSD license (see LICENSE.txt).
4 // Go to the project home page for more info:
5 //
6 // https://github.com/benhoyt/inih
7 
8 #ifndef __INIREADER_H__
9 #define __INIREADER_H__
10 
11 #include <map>
12 #include <string>
13 
14 // Read an INI file into easy-to-access name/value pairs. (Note that I've gone
15 // for simplicity here rather than speed, but it should be pretty decent.)
16 class INIReader
17 {
18 public:
19  // Construct INIReader and parse given filename. See ini.h for more info
20  // about the parsing.
21  INIReader(const std::string& filename);
22 
23  // Return the result of ini_parse(), i.e., 0 on success, line number of
24  // first error on parse error, or -1 on file open error.
25  int ParseError() const;
26 
27  // Get a string value from INI file, returning default_value if not found.
28  std::string Get(const std::string& section, const std::string& name,
29  const std::string& default_value) const;
30 
31  // Get an integer (long) value from INI file, returning default_value if
32  // not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
33  long GetInteger(const std::string& section, const std::string& name, long default_value) const;
34 
35  // Get an unsigned integer (unsigned long) value from INI file, returning default_value if
36  // not found or not a valid integer (decimal "1234", or hex "0x4d2").
37  unsigned long GetUnsignedInteger(const std::string& section, const std::string& name, unsigned long default_value) const;
38 
39  // Get a real (floating point double) value from INI file, returning
40  // default_value if not found or not a valid floating point value
41  // according to strtod().
42  double GetReal(const std::string& section, const std::string& name, double default_value) const;
43 
44  // Get a boolean value from INI file, returning default_value if not found or if
45  // not a valid true/false value. Valid true values are "true", "yes", "on", "1",
46  // and valid false values are "false", "no", "off", "0" (not case sensitive).
47  bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const;
48 
49 private:
50  int _error;
51  std::map<std::string, std::string> _values;
52  static std::string MakeKey(const std::string& section, const std::string& name);
53  static int ValueHandler(void* user, const char* section, const char* name,
54  const char* value);
55 };
56 
57 #endif // __INIREADER_H__
INIReader::GetInteger
long GetInteger(const std::string &section, const std::string &name, long default_value) const
Definition: INIReader.cpp:33
INIReader::GetReal
double GetReal(const std::string &section, const std::string &name, double default_value) const
Definition: INIReader.cpp:53
INIReader::GetBoolean
bool GetBoolean(const std::string &section, const std::string &name, bool default_value) const
Definition: INIReader.cpp:62
INIReader::ParseError
int ParseError() const
Definition: INIReader.cpp:21
INIReader
Definition: INIReader.h:16
INIReader::GetUnsignedInteger
unsigned long GetUnsignedInteger(const std::string &section, const std::string &name, unsigned long default_value) const
Definition: INIReader.cpp:43
INIReader::INIReader
INIReader(const std::string &filename)
Definition: INIReader.cpp:16
INIReader::Get
std::string Get(const std::string &section, const std::string &name, const std::string &default_value) const
Definition: INIReader.cpp:26