Created
June 27, 2011 16:22
-
-
Save FurryHead/1049206 to your computer and use it in GitHub Desktop.
ConfigParser header file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* configparser.hxx | |
* | |
* Copyright 2011 FurryHead <[email protected]> | |
* | |
* ConfigParser 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 2 of the License, or | |
* (at your option) any later version. | |
* | |
* ConfigParser 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 ConfigParser; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
* MA 02110-1301, USA. | |
* | |
* | |
*/ | |
#include <map> | |
#include <vector> | |
#include <string> | |
#include <fstream> | |
class Section { | |
std::map<std::string,std::string> values; | |
std::string s_name; | |
public: | |
Section(std::string section_name); | |
std::string name(); | |
const std::map<std::string,std::string>& items(); | |
std::vector<std::string> options(); | |
void remove_option(std::string option); | |
void set(std::string option, std::string value); | |
std::string get(std::string option); | |
bool has_option(std::string option) ; | |
}; | |
class ConfigParser { | |
std::vector<Section> _sections; | |
int current_line_no; | |
Section current_section; | |
protected: | |
Section* get_section(std::string section); | |
bool valid_key(std::string key); | |
std::string parse_line(std::string line); | |
std::string get_vars(std::string var); | |
public: | |
ConfigParser(std::string filename); | |
ConfigParser(); | |
void read(std::string filename); | |
void read(std::istream& file); | |
void write(std::string filename); | |
void write(std::ostream& file); | |
std::vector<std::string> sections(); | |
std::vector<std::string> options(std::string section); | |
std::string get(std::string section, std::string key); | |
std::string set(std::string section, std::string key, std::string value); | |
const std::map<std::string, std::string>& items(std::string section); | |
bool has_section(std::string section); | |
bool has_option(std::string section, std::string option); | |
void add_section(std::string section); | |
void remove_section(std::string section); | |
void remove_option(std::string section, std::string option); | |
}; | |
class SyntaxError { | |
std::string estr; | |
public: | |
SyntaxError(std::string error); | |
std::string what(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment