Prusa MINI Firmware overview
INIReader Class Reference

#include <INIReader.h>

Public Member Functions

 INIReader (const std::string &filename)
 
 INIReader (const char *buffer, size_t buffer_size)
 
int ParseError () const
 
std::string Get (const std::string &section, const std::string &name, const std::string &default_value) const
 
std::string GetString (const std::string &section, const std::string &name, const std::string &default_value) const
 
long GetInteger (const std::string &section, const std::string &name, long default_value) const
 
double GetReal (const std::string &section, const std::string &name, double default_value) const
 
bool GetBoolean (const std::string &section, const std::string &name, bool default_value) const
 
bool HasSection (const std::string &section) const
 
bool HasValue (const std::string &section, const std::string &name) const
 

Constructor & Destructor Documentation

◆ INIReader() [1/2]

INIReader::INIReader ( const std::string &  filename)
explicit

◆ INIReader() [2/2]

INIReader::INIReader ( const char *  buffer,
size_t  buffer_size 
)
explicit
26 {
27  string content(buffer, buffer_size);
28  _error = ini_parse_string(content.c_str(), ValueHandler, this);
29 }
Here is the call graph for this function:

Member Function Documentation

◆ ParseError()

int INIReader::ParseError ( ) const
32 {
33  return _error;
34 }

◆ Get()

string INIReader::Get ( const std::string &  section,
const std::string &  name,
const std::string &  default_value 
) const
37 {
38  string key = MakeKey(section, name);
39  // Use _values.find() here instead of _values.at() to support pre C++11 compilers
40  return _values.count(key) ? _values.find(key)->second : default_value;
41 }
Here is the caller graph for this function:

◆ GetString()

string INIReader::GetString ( const std::string &  section,
const std::string &  name,
const std::string &  default_value 
) const
44 {
45  const string str = Get(section, name, "");
46  return str.empty() ? default_value : str;
47 }
Here is the call graph for this function:

◆ GetInteger()

long INIReader::GetInteger ( const std::string &  section,
const std::string &  name,
long  default_value 
) const
50 {
51  string valstr = Get(section, name, "");
52  const char* value = valstr.c_str();
53  char* end;
54  // This parses "1234" (decimal) and also "0x4D2" (hex)
55  long n = strtol(value, &end, 0);
56  return end > value ? n : default_value;
57 }
Here is the call graph for this function:

◆ GetReal()

double INIReader::GetReal ( const std::string &  section,
const std::string &  name,
double  default_value 
) const
60 {
61  string valstr = Get(section, name, "");
62  const char* value = valstr.c_str();
63  char* end;
64  double n = strtod(value, &end);
65  return end > value ? n : default_value;
66 }
Here is the call graph for this function:

◆ GetBoolean()

bool INIReader::GetBoolean ( const std::string &  section,
const std::string &  name,
bool  default_value 
) const
69 {
70  string valstr = Get(section, name, "");
71  // Convert to lower case to make string comparisons case-insensitive
72  std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower);
73  if (valstr == "true" || valstr == "yes" || valstr == "on" || valstr == "1")
74  return true;
75  else if (valstr == "false" || valstr == "no" || valstr == "off" || valstr == "0")
76  return false;
77  else
78  return default_value;
79 }
Here is the call graph for this function:

◆ HasSection()

bool INIReader::HasSection ( const std::string &  section) const
82 {
83  const string key = MakeKey(section, "");
84  std::map<string, string>::const_iterator pos = _values.lower_bound(key);
85  if (pos == _values.end())
86  return false;
87  // Does the key at the lower_bound pos start with "section"?
88  return pos->first.compare(0, key.length(), key) == 0;
89 }

◆ HasValue()

bool INIReader::HasValue ( const std::string &  section,
const std::string &  name 
) const
92 {
93  string key = MakeKey(section, name);
94  return _values.count(key);
95 }
ini_parse_string
int ini_parse_string(const char *string, ini_handler handler, void *user)
Definition: ini.c:277
createSpeedLookupTable.end
end
Definition: createSpeedLookupTable.py:33
INIReader::Get
std::string Get(const std::string &section, const std::string &name, const std::string &default_value) const
Definition: INIReader.cpp:36