15.04.2014 - Version 0.3.8_beta, last version of 0.3.8 branch. Too much added and fixed...

This commit is contained in:
peri4
2014-04-15 13:19:07 +04:00
parent f50891b376
commit 77abb0bbea
46 changed files with 4538 additions and 2515 deletions

View File

@@ -61,7 +61,7 @@ public:
//! Contructs and read configuration file at path "path" in mode "mode"
PIConfig(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
~PIConfig() {/*piForeach (Entry * i, root._children) deleteEntry(i); close();*/}
~PIConfig() {root.deleteBranch(); close();}
class Entry;
@@ -70,6 +70,7 @@ public:
friend class PIConfig;
friend class Entry;
friend std::ostream & operator <<(std::ostream & s, const Branch & v);
friend PICout operator <<(PICout s, const Branch & v);
public:
Branch() {;}
@@ -85,12 +86,13 @@ public:
bool isEntryExists(const PIString & name) const {piForeachC (Entry * i, *this) if (entryExists(i, name)) return true; return false;}
int indexOf(const Entry * e) {for (int i = 0; i < size_s(); ++i) if (at(i) == e) return i; return -1;}
void clear() {piForeach (Entry * i, *this) delete i; PIVector<Entry * >::clear();}
//void clear() {piForeach (Entry * i, *this) delete i; PIVector<Entry * >::clear();}
private:
bool entryExists(const Entry * e, const PIString & name) const;
void allLeaves(Branch & b, Entry * e) {piForeach (Entry * i, e->_children) {if (i->isLeaf()) b << i; else allLeaves(b, i);}}
void coutt(std::ostream & s, const PIString & p) const {piForeachC (Entry * i, *this) i->coutt(s, p);}
void piCoutt(PICout s, const PIString & p) const {piForeachC (Entry * i, *this) i->piCoutt(s, p);}
static Entry _empty;
PIString delim;
@@ -296,6 +298,8 @@ public:
void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;}
void clear() {_children.clear(); _name = _value = _type = _comment = _all = PIString(); _line = 0; _parent = 0;}
void coutt(std::ostream & s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << endl; else cout << p << _name << endl; piForeachC (Entry * i, _children) i->coutt(s, nl);}
void piCoutt(PICout s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << NewLine; else cout << p << _name << endl; piForeachC (Entry * i, _children) i->piCoutt(s, nl);}
void deleteBranch() {piForeach (Entry * i, _children) {i->deleteBranch(); delete i;}}
static Entry _empty;
Entry * _parent;
@@ -432,6 +436,8 @@ public:
void removeEntry(const PIString & name, bool write = true);
void removeEntry(uint number, bool write = true);
//! Remove all tree and file content
void clear() {PIFile::clear(); parse();}
//! Parse file and build internal tree
void readAll();
@@ -454,6 +460,7 @@ private:
Entry & entryByIndex(const int index) {Branch b = allLeaves(); if (index < 0 || index >= b.size_s()) return empty; return *(b[index]);}
void removeEntry(Branch & b, Entry * e);
void deleteEntry(Entry * e) {piForeach (Entry * i, e->_children) deleteEntry(i); delete e;}
PIString getPrefixFromLine(PIString line, bool * exists);
void parse();
int centry;
@@ -467,6 +474,8 @@ private:
inline std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v) {v.coutt(s, ""); return s;}
inline std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v) {s << v.value(); return s;}
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {s << v.value(); return s;}
/** \relatesalso PIConfig \relatesalso PIIODevice