10 string comment,
string sectionStartTag,
string sectionEndTag,
string sentry)
11 : myDelimiter(delimiter), myComment(comment), mySectionStartTag(sectionStartTag), mySectionEndTag(sectionEndTag), mySentry(sentry) {
13 if (filepath.length() > 0 && filepath.at(filepath.length() - 1) !=
'/') {
16 filepath.append(filename);
19 if (filepath.substr(filepath.length() - 4, 4) !=
".cfg")
20 filepath.append(
".cfg");
27 std::ifstream in(filepath.c_str());
51 std::cout <<
"Size: " <<
myContents.size() << endl;
99 static const char whitespace[] =
" \n\t\v\r\f";
100 s.erase(0, s.find_first_not_of(whitespace));
101 s.erase(s.find_last_not_of(whitespace) + 1U);
106 for (
unsigned int i = 0; i < cf.
mySortVector.size(); i++) {
109 string currentSector = currentTreeVector.
getKey();
116 os <<
"[" << sp->first <<
"]" << endl;
120 std::vector<string> contentVector = currentTreeVector.
getVector();
121 for (
unsigned int j = 0; j < contentVector.size(); j++) {
122 string currentKey = contentVector.at(j);
129 os << p->second << std::endl;
141 typedef string::size_type pos;
147 const pos skip = delim.length();
151 string nextline =
"";
152 string sectHeader =
"";
153 std::vector<string> currentVector;
156 while (is || nextline.length() > 0) {
160 if (nextline.length() > 0) {
164 std::getline(is, line);
168 line = line.substr(0, line.find(comm));
170 string lncopy = line;
173 if (lncopy.substr(0, 1) == startTag && lncopy.substr(lncopy.length() - 1, 1) == endTag) {
175 sectHeader = lncopy.substr(1, lncopy.length() - 2);
182 if (currentVector.size() > 0) {
198 if (sentry !=
"" && line.find(sentry) != string::npos)
return is;
201 pos delimPos = line.find(delim);
202 if (delimPos < string::npos) {
204 string key = line.substr(0, delimPos);
205 line.replace(0, delimPos + skip,
"");
210 bool terminate =
false;
211 while (!terminate && is) {
212 std::getline(is, nextline);
215 string nlcopy = nextline;
217 if (nlcopy ==
"")
continue;
219 nextline = nextline.substr(0, nextline.find(comm));
220 if (nextline.find(delim) != string::npos)
222 if (sentry !=
"" && nextline.find(sentry) != string::npos)
227 if (nlcopy !=
"") line +=
"\n";
236 currentVector.push_back(key);
243 if (currentVector.size() > 0) {
void setKey(const string &sKey)
std::map< string, std::map< string, string > > mySectionRelatedContents
static void trim(string &s)
void remove(const string &key)
Reads and writes a configuration file.
std::vector< SortTreeVector > mySortVector
bool sectionExists(const string §ionKey)
std::map< string, string >::const_iterator mapci
Keep track of sortorder from original configfile.
File not found exception.
std::vector< string > getVector() const
bool keyExists(const string &key) const
SortTreeVector * mySortVectorObj
Key in configuration file not found exception.
friend std::ostream & operator<<(std::ostream &os, ConfigFile &cf)
std::map< string, string > myContents
void setVector(const std::vector< string > &vVector)
std::map< string, string >::iterator mapi
std::map< string, map< string, string > >::const_iterator mapciSect
friend std::istream & operator>>(std::istream &is, ConfigFile &cf)