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

@@ -29,6 +29,22 @@
* some values and write new.
* \image html piconfig.png
*
* %PIConfig supports also INI-style files with sections "[section]".
* In this case line with section name interpret as prefix to the next
* lines. For example, these configs are equal:
* \code
* ser.device = /dev/ttyS0
* ser.speed = 115200
* debug = true
* \endcode
* \code
* [ser]
* device = /dev/ttyS0
* speed = 115200
* []
* debug = true
* \endcode
*
* \section PIConfig_sec1 Concepts
* Each node of internal tree has type PIConfig::Entry. %PIConfig
* has one root element \a rootEntry(). Any entry of configuration file is a
@@ -422,13 +438,30 @@ void PIConfig::removeEntry(Branch & b, PIConfig::Entry * e) {
}
PIString PIConfig::getPrefixFromLine(PIString line, bool * exists) {
line.trim();
if (line.left(1) == "#") {if (exists) *exists = false; return PIString();}
int ci = line.find("#");
if (ci >= 0) line.cutRight(line.size() - ci);
if (line.find("=") >= 0) {if (exists) *exists = false; return PIString();}
if (line.find("[") >= 0 && line.find("]") >= 0) {
if (exists) *exists = true;
return line.takeRange('[', ']').trim();
}
if (exists) *exists = false;
return PIString();
}
void PIConfig::writeAll() {
//cout << this << " write < " << size() << endl;
clear();
PIFile::clear();
//*this << "1234567894132456798\n"; return;
//writeEntry(&root);
buildFullNames(&root);
Branch b = allLeaves();
PIString prefix, tprefix;
bool isPrefix;
//for (int i = 0; i < b.size_s(); ++i)
// cout << b[i]->_name << " = " << b[i]->_value << endl;
int j = 0;
@@ -437,16 +470,28 @@ void PIConfig::writeAll() {
if (j >= 0 && j < b.size_s()) {
if (b[j]->_line == i) {
b[j]->buildLine();
*this << b[j]->_all << '\n';
*this << (b[j]->_all).cutLeft(prefix.size()) << '\n';
//cout << this << " " << b[j]->_all << endl;
++j;
} else {
*this << other[i];
tprefix = getPrefixFromLine(other[i], &isPrefix);
if (isPrefix) {
prefix = tprefix;
if (!prefix.isEmpty())
prefix += delim;
}
if (i < other.size_s() - 1) *this << '\n';
//cout << this << " " << other[i] << endl;
}
} else {
*this << other[i];
tprefix = getPrefixFromLine(other[i], &isPrefix);
if (isPrefix) {
prefix = tprefix;
if (!prefix.isEmpty())
prefix += delim;
}
if (i < other.size_s() - 1) *this << '\n';
//cout << this << " " << other[i] << endl;
}
@@ -458,6 +503,7 @@ void PIConfig::writeAll() {
void PIConfig::readAll() {
root.deleteBranch();
root.clear();
parse();
}
@@ -475,11 +521,11 @@ bool PIConfig::entryExists(const Entry * e, const PIString & name) const {
void PIConfig::parse() {
PIString src, str, tab, comm, all, name, type;
PIString src, str, tab, comm, all, name, type, prefix, tprefix;
PIStringList tree;
Entry * entry, * te, * ce;
int ind, sind;
bool isNew;
bool isNew, isPrefix;
if (!isOpened()) return;
seekToBegin();
other.clear();
@@ -487,6 +533,12 @@ void PIConfig::parse() {
while (!isEnd()) {
other.push_back(PIString());
src = str = readLine();
tprefix = getPrefixFromLine(src, &isPrefix);
if (isPrefix) {
prefix = tprefix;
if (!prefix.isEmpty())
prefix += delim;
}
tab = str.left(str.find(str.trimmed().left(1)));
str.trim();
//cout << endl << str << endl << endl;
@@ -505,7 +557,7 @@ void PIConfig::parse() {
comm = "";
}
//name = str.left(ind).trimmed();
tree = str.left(ind).trimmed().split(delim);
tree = (prefix + str.left(ind).trimmed()).split(delim);
name = tree.back();
tree.pop_back();
entry = &root;