configparser

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
configparser [04.01.2006 15:07 (vor 21 Jahren)] cwachaconfigparser [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1
Zeile 1: Zeile 1:
-===== Configuration File Parser ===== 
- 
-=== Overview === 
-//cfg_parser// is a robus configuration file parser written in C++. It can read and write configuration files preserving any comments made inside the file. It supports escaped characters, quoted text and infinite line length (a whole line must fit into an STL string). 
- 
-=== Features === 
-  * keyword = value 
-  * [Sections] 
-  * # comments 
-  * [Sections] # with comments 
-  * keyword = value # pairs with comments 
-  * keyword = "values with spaces, newlines \n, embedded quotes \" and all other escape characters supported by printf" 
-  * sloppy parsing: keyword= value is accepted as well as keyword=value or     keyword        value (withouth =) 
-  * displays parsing errors in a human friendly format (including filename, linenumber and line contents in question) 
- 
-=== Download === 
-  * {{projects:cfg_parser-1.0.zip}} 
- 
-=== Code Example === 
- 
-<code cpp> 
-#include <iostream> 
-#include <string> 
- 
-#include "cfg_parser.h" 
- 
-using namespace std; 
- 
-int main(int argc, char *argv[]) { 
-    // First we need to initialize a new configuration 
-    ConfigParser cfg("test.cfg"); 
- 
-    // write everything into another config file 
-    cfg.writeFile("test2.cfg"); 
-  
-    // get value as integer of keyword 'hier' from the global section 
-    int i = cfg.getInt("hier"); 
-    cout << "global hier=" << i << endl; 
- 
-    // get value as integer of keyword 'hier' from section: mysection with default value = "" (which will be converted by atoi()) 
-    i = cfg.getInt("hier", "", "mysection"); 
-    cout << "section hier=" << i << endl; 
- 
-   return 0; 
-} 
-</code> 
- 
-=== Documentation === 
- 
-Only relevant members are shown! 
- 
-<code cpp> 
-class ConfigParser { 
-public: 
- ConfigParser(const std::string& in_file = ""); 
- ~ConfigParser(); 
- 
- // loads the given configuration file 
- int readFile(const std::string& in_file); 
- // writes the current configuration to the given file. I file not given, write back into the inputfile 
- int writeFile(const std::string& out_file = ""); 
- // returns filname of loaded file 
- void getFilename(std::string& in_file); 
- // empty lines in config file are written back to the out_file if value = 1. (default = 0) 
- void preserveEmptyLines(int value); 
-  
-  
- // return variable from configuration (if non-existent, value remains unchanged) 
- void getVar(const std::string& keyword, std::string& value, const std::string& section = ""); 
- // sets variable in configuration (section and/or variable are added if non-existent) 
- void setVar(const std::string& keyword, const std::string& value, const std::string& section = "", const std::string& comment = ""); 
- // deletes variable from configuration 
- void delVar(const std::string& keyword, const std::string& section = ""); 
- 
- // returns integer if found, supplied default_value else 
- int getInt(const std::string& keyword, const std::string& default_value = "", const std::string& section = ""); 
- // returns long if found, supplied default_value else 
- long getLong(const std::string& option, const std::string& default_value = "", const std::string& section = ""); 
- // returns float if found, supplied default_value else 
- float getFloat(const std::string& option, const std::string& default_value = "", const std::string& section = ""); 
- // returns double if found, supplied default_value else 
- double getDouble(const std::string& option, const std::string& default_value = "", const std::string& section = ""); 
- // returns string if found, supplied default_value else 
- std::string getString(const std::string& option, const std::string& default_value = "", const std::string& section = ""); 
- 
- 
- // adds a section to the configuration 
- void addSection(const std::string& section, const std::string& comment = ""); 
- // deletes a section 
- void delSection(const std::string& section); 
-  
- // displays current configuration content using cout 
- void debug(); 
-}; 
-</code> 
- 
  
  • configparser.1136383679.txt.gz
  • Zuletzt geändert: 16.11.2016 23:16 (vor 10 Jahren)
  • (Externe Bearbeitung)