Almetare  1.15
Alle meine Taschenrechner - Eine C++-Bibliothek zur Entwicklung von Taschenrechnern
confg.h
gehe zur Dokumentation dieser Datei
1 //******************************************************************************
2 // Copyright (c) 2002-2004 by Friedemann Seebass, Germany.
3 // Dieses Programm ist freie Software. Siehe GNU GPL Notiz in Datei main.cpp.
4 // This program is free software. See the GNU GPL notice in file main.cpp.
5 // Projekt: Almetare - Alle meine Taschenrechner
6 //******************************************************************************
11 //******************************************************************************
12 // Wann Wer Was
13 // ---------- -------- ---------------------------------------------------------
14 // 26.08.2003 fse anderer Default-Konstruktor
15 // 22.08.2003 fse Anpassungen fuer MM1
16 // 11.05.2003 fse Datei von config.h in confg.h umbenannt
17 // 01.03.2003 fse neue Funktion remove()
18 // 18.11.2001 fse Schreiben von Parametern
19 // 18.02.2001 fse erzeugt
20 //******************************************************************************
21 
22 #ifndef CONFG_H
23 #define CONFG_H
24 
25 #ifndef __cplusplus
26 #error confg.h is only for C++!
27 #endif
28 
29 //******************************************************************************
30 
31 #include <string>
32 #include <fstream>
33 #include <vector>
34 
35 using namespace std;
36 
37 //******************************************************************************
38 // Kofigurations-Klasse
39 //******************************************************************************
40 
87 // fse, 18.04.02
88 // fse, 01.03.03: neue Funktion remove();
89 // fse, 26.08.03: Default-Konstruktor
90 // Config(const string& fileName = "default.ini") { (void)init(fileName); }
91 // durch
92 // Config() {}
93 // ersetzt, damit man ein Config-Objekt erzeugen kann, ohne
94 // sofort den Dateinamen zu wissen.
95 
96 class Config
97 {
98 public:
99  enum Err { OK = 0, FILE_NOT_FOUND, SECTION_NOT_FOUND, PAR_NOT_FOUND, NO_FURTHER_PAR };
100  Config() {};
101  Config(const string& fileName, Err& err) { err = init(fileName); }
102  ~Config() { (void)flush(); mFile.close(); }
103  Err init(const string& fileName);
104  Err getErr() const { return mErr; }
105  string errToStr() const;
106  Err seekSection(const string& section);
107  Err readParameter(const string& par, string& val, const string& section = "", bool isStripSpc = true);
108  Err nextParameter(string& par, string& val);
109  Err writeParameter(const string& par, const string& val, const string& section = "");
110  Err flush();
111  void remove() { mFile.close(); ::remove(mFileName.c_str()); }
112 private:
113  char mCs;
114  string mAssigns;
115  string mCsAndEol;
116  string mFileName;
117  string mSection;
118  string mParName;
119  fstream mFile;
120  bool mIsFileRead;
121  Err mErr;
122  vector<string> mLines;
123 
124  void splitLine(string line,
125  string& space,
126  string& sectionName,
127  string& parName,
128  string& assignOp,
129  string& value,
130  string& comment);
131  void readFile();
132  Err setParameter(const string& setPar, const string& setVal, unsigned int& i);
133 };
134 
135 //******************************************************************************
136 
137 #endif // !CONFG_H
string mFileName
Name der Konfigurationsdatei.
Definition: confg.h:116
fstream mFile
zu oeffnende Konfigurationsdatei
Definition: confg.h:119
string mParName
Name des Parameters.
Definition: confg.h:118
Err mErr
Fehlercode.
Definition: confg.h:121
vector< string > mLines
gepufferte Datei
Definition: confg.h:122
char mCs
Kommentarsymbol.
Definition: confg.h:113
bool mIsFileRead
Flag, ob Datei schon gelesen.
Definition: confg.h:120
Klasse zum Einlesen/Schreiben von Windows-Ini-Dateien.
Definition: confg.h:96
string mCsAndEol
String mit Kommentar und EOL-Symbol.
Definition: confg.h:115
string mAssigns
Liste von Zuweisungszeichen.
Definition: confg.h:114
string mSection
Name der Sektion.
Definition: confg.h:117