mouse_m908/include/load_config.h

65 lines
1.7 KiB
C
Raw Normal View History

2020-04-08 07:39:30 -06:00
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#ifndef SIMPLE_INI_PARSER
#define SIMPLE_INI_PARSER
#include <iostream>
#include <fstream>
#include <regex>
#include <string>
#include <map>
2020-05-05 14:50:31 -06:00
/**
* This is a standalone .ini parser, written to replace boost property
* tree in the mouse_m908 project. It is not intended to be a general
* purpose replacement, however there is nothing preventing that except
* the very limited amount of features.
*
*/
2020-04-08 07:39:30 -06:00
class simple_ini_parser{
private:
2020-05-21 16:13:37 -06:00
/// Stores the key-value pairs
2020-04-08 07:39:30 -06:00
std::map< std::string, std::string > _ini_values;
public:
2020-05-05 14:50:31 -06:00
/**
* Read the specified .ini file. The already existing key-value
* pairs do not get cleared, only overwritten.
* \return 0 if succesful
*/
2020-04-08 07:39:30 -06:00
int read_ini( std::string path );
2020-05-05 14:50:31 -06:00
/**
* Get the value of the specified key.
* \return The value of the specified key, or the specified default
2020-05-21 16:13:37 -06:00
* value if the key is unkwnown
2020-05-05 14:50:31 -06:00
*/
2020-04-08 07:39:30 -06:00
std::string get( std::string key, std::string default_value );
2020-05-05 14:50:31 -06:00
/**
* Print all key-value pairs to stdout.
*/
2020-04-08 07:39:30 -06:00
int print_all();
};
#endif