SBB Host
Host communication with the self balancing bike.
Loading...
Searching...
No Matches
IniReader Class Reference

A class for configuration-file reading. More...

#include <IniReader.h>

Public Member Functions

 IniReader (const char *name)
 Constructor. More...
 
 ~IniReader ()
 Desctructor. More...
 
bool getInt (const char *key, int *val)
 Get integer variable. More...
 
bool getDouble (const char *key, double *val)
 Get double variable. More...
 
bool getHex (const char *key, unsigned int *val)
 Get an hex number. More...
 
bool getString (const char *key, std::string *val)
 Get string variable. More...
 
bool getStringArray (const char *key, std::vector< std::string > *str_array)
 Get a string vector. More...
 
bool getDoubleArray (const char *key, std::vector< double > *double_array)
 Get a double vector. More...
 
bool isOpen ()
 Check if open correctly. More...
 

Private Attributes

Filep_file
 Poinnter to the File object. More...
 
std::string _name
 Name of the configuration file. More...
 

Detailed Description

A class for configuration-file reading.

Class for reading and parsing of configuration files (e.g. with *.ini extension). File format used is the following

# Example config file.
# Use hash for comments.
# Comments can be also put after the semicolon in the variable assignment.
# Be careful to use two white spaces around '=', quotes around values and semicolon at the end of the statements.
var0 = 'helloworld'; a varialbe var0 with value 'helloworld'
var1 = '1'; a variable var1 with value '1'
list0 = 'hello, ciao, salut, hola'; a
list1 = '0, 1, 2, 3'; a list of integers
Author
Stefano Lovato
Date
2022

Constructor & Destructor Documentation

◆ IniReader()

IniReader::IniReader ( const char *  name)

Constructor.

Default constructor for the file class.

Parameters
nameThe name of the configuration file to use. File is not open.

◆ ~IniReader()

IniReader::~IniReader ( )

Desctructor.

Default destructor.

Member Function Documentation

◆ getDouble()

bool IniReader::getDouble ( const char *  key,
double *  val 
)

Get double variable.

Function to get a double variable. The configuration file is open and closed at the end of the operation.

Parameters
keyName of the variable.
valPointer to the double variable to store the value.
Returns
true if success, false otherwise.

◆ getDoubleArray()

bool IniReader::getDoubleArray ( const char *  key,
std::vector< double > *  double_array 
)

Get a double vector.

Function to get a vector of double. The configuration file is open and closed at the end of the operation.

Parameters
keyName of the list.
double_arrayPointer to the std::vector<std::double> variable to store the values.
Returns
true if success, false otherwise.

◆ getHex()

bool IniReader::getHex ( const char *  key,
unsigned int *  val 
)

Get an hex number.

Function to get a hex number as an unsigned int variable. The configuration file is open and closed at the end of the operation.

Parameters
keyName of the variable.
valPointer to the unsigned int variable to store the hex value.
Returns
true if success, false otherwise.

◆ getInt()

bool IniReader::getInt ( const char *  key,
int *  val 
)

Get integer variable.

Function to get an integer variable. The configuration file is open and closed at the end of the operation.

Parameters
keyName of the variable.
valPointer to the int variable to store the value.
Returns
true if success, false otherwise.

◆ getString()

bool IniReader::getString ( const char *  key,
std::string *  val 
)

Get string variable.

Function to get a string variable. The configuration file is open and closed at the end of the operation.

Parameters
keyName of the variable.
valPointer to the std::string variable to store the string.
Returns
true if success, false otherwise.

◆ getStringArray()

bool IniReader::getStringArray ( const char *  key,
std::vector< std::string > *  str_array 
)

Get a string vector.

Function to get a vector of strings. The configuration file is open and closed at the end of the operation.

Parameters
keyName of the list.
str_arrayPointer to the std::vector<std::string> variable to store the strings.
Returns
true if success, false otherwise.

◆ isOpen()

bool IniReader::isOpen ( )

Check if open correctly.

Function check if the file is open correctly.

Returns
true if success, false otherwise.

Member Data Documentation

◆ _name

std::string IniReader::_name
private

Name of the configuration file.

◆ p_file

File* IniReader::p_file
private

Poinnter to the File object.