6 #include "rrExporter.h"
7 #include "rrStringUtils.h"
8 #include "rrIniSection.h"
10 #include "rrFileName.h"
20 const int MAX_LINE_BUFFER_SIZE = 2048;
25 typedef std::vector<IniKey*> KeyList;
26 typedef std::vector<std::string> NonKeyList;
27 typedef std::vector<IniSection*> SectionList;
28 typedef SectionList::iterator SectionItor;
33 class RR_DECLSPEC IniFile
38 const int mAutoCreateSections;
42 const int mAutoCreateKeys;
44 std::string mCommentIndicators;
45 const std::string mEqualIndicator;
46 const std::string mWhiteSpace;
49 std::string GetNextWord(std::string& CommandLine);
50 std::string Trim(std::string& Str);
51 int WriteLine(std::fstream& stream,
const char* fmt, ...);
54 SectionList mSections;
55 FileName mIniFileName;
63 IniFile(
const std::string& fName =
"",
bool autoLoad =
false,
bool autoSave =
false);
66 size_t GetNumberOfSections() {
return mSections.size(); }
67 IniSection* GetSection(
int i) {
return mSections[i]; }
68 IniSection* GetSection(
size_t i) {
return mSections[i]; }
71 std::string GetFilePath() {
return mIniFileName.GetPath(); }
72 std::string GetFileName() {
return mIniFileName; }
73 std::string GetFullFileName() {
return mIniFileName.GetPathAndFileName(); }
74 bool SetFilePath(
const std::string& path);
75 bool Load(
const std::string& fName =
"");
76 IniSection* LoadSection(
const std::string& theSection);
77 bool Save(ios_base::openmode openMode = std::ios::out | std::ios::trunc);
78 bool UnLoad() {
return Save(); }
79 bool WasItFound() {
return mWasFound; }
80 bool SectionExists(
const std::string& section);
84 std::string ReadValue(
const std::string& Key,
const std::string& Section =
"");
85 std::string ReadString(
const std::string& Key,
const std::string& Section =
"",
const std::string& def_val =
"");
86 double ReadDouble(
const std::string& Key,
const std::string& Section =
"",
double def_value = 0);
87 float ReadFloat(
const std::string& Key,
const std::string& Section =
"",
double def_value = 0) {
return (
float)ReadDouble(Key, Section, def_value); }
88 int ReadInteger(
const std::string& Key,
const std::string& Section =
"",
int def_value = 0);
89 bool ReadBool(
const std::string& Key,
const std::string& Section =
"",
bool def_value =
false);
92 bool WriteValue(
const std::string& Key,
const std::string& Value,
const std::string& Comment =
"",
const std::string& Section =
"");
93 bool WriteFloat(
const std::string& Key,
double value,
const std::string& Comment =
"",
const std::string& Section =
"");
94 bool WriteInteger(
const std::string& Key,
int nValue,
const std::string& Comment =
"",
const std::string& Section =
"");
95 bool WriteBool(
const std::string& Key,
bool bValue,
const std::string& Comment =
"",
const std::string& Section =
"");
96 bool WriteString(
const std::string& Key,
const std::string& Value,
const std::string& Comment =
"",
const std::string& Section =
"") {
return WriteValue(Key, Value, Comment, Section); }
97 bool WriteNonKey(
const std::string& nonKey,
const std::string& Section =
"");
100 bool SetKeyComment(
const std::string& Key,
const std::string& Comment,
const std::string& Section =
"");
101 bool SetSectionComment(
const std::string& Section,
const std::string& Comment);
102 bool DeleteKey(
const std::string& Key,
const std::string& FromSection =
"");
103 bool DeleteSection(
const std::string& Section);
104 bool DeleteSectionsWithKeyValue(
const std::string& key,
const std::string& value);
105 bool CreateKey(
const std::string& Key,
const std::string& Value,
const std::string& Comment =
"",
const std::string& Section =
"");
108 bool CreateSection(
const std::string& Section,
const std::string& Comment =
"");
109 bool CreateSection(
const std::string& Section,
const std::string& Comment, KeyList Keys);
112 size_t SectionCount();
114 size_t KeyCount(
const std::string& section);
116 void SetFileName(
const std::string& fName);
117 std::string CommentStr(std::string& Comment);
118 IniKey* GetKey(
const std::string& Key,
const std::string& Section);
119 IniSection* GetSection(
const std::string& Section,
bool create =
false);
120 IniSection* GetSection(
const unsigned int secNr);
121 bool ClearSection(
const std::string& section);
122 bool IsModified() {
return mIsDirty; }