|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #ifndef CONFIGFILE_HPP_ 00023 #define CONFIGFILE_HPP_ 00024 00025 #include <stdio.h> 00026 #include <string> 00027 #include <map> 00028 using namespace std; 00029 00030 struct config_option_t; 00031 00032 typedef void (*config_parser_t)(const char* opt, config_option_t* option); 00033 00034 00035 00036 typedef struct config_option_t { 00037 const char* section; 00038 const char* name; 00039 void* pointer; 00040 string default_value_str; 00041 config_parser_t parser; 00042 const char* option; 00043 string original_value_str; 00044 string resolved_value_str; 00045 00046 /*config_option_t() { 00047 section = NULL; 00048 name = NULL; 00049 pointer = NULL; 00050 default_value_str = ""; 00051 parser = NULL; 00052 option = NULL; 00053 original_value_str = ""; 00054 resolved_value_str = ""; 00055 }*/ 00056 } config_option_t; 00057 00058 class ConfigParser { 00059 public: 00060 ConfigParser(config_option_t* options); 00061 virtual ~ConfigParser(); 00062 00063 void parseLine(const char* line); 00064 void printFile(FILE* file, const bool resolve = false); 00065 00066 static string resolve_env(string in); 00067 00068 static void parse_int (const char* value, config_option_t* option); 00069 static void parse_int_min (const char* value, config_option_t* option); 00070 static void parse_int_max (const char* value, config_option_t* option); 00071 static void parse_int_range(const char* value, config_option_t* option); 00072 static void parse_int_enum (const char* value, config_option_t* option); 00073 static void parse_longlong_size(const char* value, config_option_t* option); 00074 static void parse_bool (const char* value, config_option_t* option); 00075 static void parse_path (const char* value, config_option_t* option); 00076 00077 private: 00078 map<string, map<string, config_option_t*> > options; 00079 char section[512]; 00080 00081 void tokenize(const char* line, char* param, char* value); 00082 void parseValue(const char* section, const char* param, const char* value); 00083 }; 00084 00085 #endif /* CONFIGFILE_HPP_ */
1.7.6.1