git-svn-id: svn://db.shs.com.ru/libs@161 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2017-02-02 08:52:24 +00:00
parent dfb021c228
commit 0932e6ecf4
20 changed files with 663 additions and 432 deletions

View File

@@ -24,6 +24,16 @@ bool KInterface::test(int v) {
}
CDType & KInterface::operator [](const PIDeque<int> & path_) {
return core->k_[path_];
}
CDType & KInterface::operator [](const PIString & name_) {
return core->k_[name_];
}
CDType & KInterface::operator [](int v) {
return core->k_[v];
}

View File

@@ -19,6 +19,10 @@ public:
bool test(int v);
CDType & operator [](int v);
const CDType operator [](int v) const;
CDType & operator [](const PIString & name_);
const CDType operator [](const PIString & name_) const {return (*this)[name_];}
CDType & operator [](const PIDeque<int> & path_);
const CDType operator [](const PIDeque<int> & path_) const {return (*this)[path_];}
CDSection & section(int v);
const CDSection section(int v) const;
CDSection & section(const PIDeque<int> &path);

View File

@@ -160,6 +160,16 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
parseEnumLine(line, &cev, &type, &comment);
//piCout << line << "=" << cev << "//" << type << comment;
ck = CDType(cev, line, type, "", "", comment, et);
if (type == "e") {
if (comment.startsWith("${")) {
comment.cutLeft(1);
PIString en = comment.inBrackets('{', '}');
comment.cutLeft(en.size_s() + 2).trim();
ck.setEnumValues(sections.value(en).enumValues());
ck.setComment(comment);
piCout << "enum" << en << ck.enumValues();
}
}
cs[cev] = ck;
//cevalues[line] = cev;
enum_values[line] = cev;

View File

@@ -37,8 +37,7 @@ CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v
calculated = false;
parent = 0;
if (type_ == "e") {
enum_values << comment_.inBrackets('{', '}').split(",");
piForeach(PIString &s, enum_values) s.trim();
enum_values = parseEnumComment(comment_);
// piCout << enum_values.size() << enum_values;
}
// piCout << type_.size() << type_.toUTF8();
@@ -63,14 +62,6 @@ PIString CDType::value() const {
}
void CDType::setFormula(const PIString & f) {
formula_ = f;
calculated = false;
//PIEvaluator e;
//calculate(&e);
}
void CDType::setValue(const PIString & value_) {
formula_ = value_;
value_d = formula_.toDouble();
@@ -79,6 +70,14 @@ void CDType::setValue(const PIString & value_) {
}
void CDType::setFormula(const PIString & f) {
formula_ = f;
calculated = false;
//PIEvaluator e;
//calculate(&e);
}
bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
if (stack.contains(this)) {
error_ = "Circular dependencies: ";
@@ -142,6 +141,31 @@ bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
}
PIVector<CDType::Enumerator> CDType::parseEnumComment(PIString c) {
PIVector<CDType::Enumerator> ret;
if (c.isEmpty()) return ret;
if (type_ == "e") {
PIStringList sl = c.inBrackets('{', '}').split(",");
int cval = 0;
piForeach (PIString & s, sl) {
s.trim();
if (s.isEmpty()) continue;
if (s[0].isDigit()) {
int ind = s.find("-");
if (ind > 0) {
cval = s.left(ind).toInt();
s.cutLeft(ind + 1).trim();
}
}
ret << CDType::Enumerator(cval, s);
++cval;
}
}
piCout << c << "=" << ret;
return ret;
}
//CDType::CDType(const CDType &cdt) {
// index_ = cdt.index_;
// name_ = cdt.name_;
@@ -233,10 +257,11 @@ CDType & CDSection::operator [](const PIString & name_) {
CDType & CDSection::operator [](const PIDeque<int> & path_) {
if (path_.isEmpty()) return null;
CDSection & s(*this);
CDSection * s = this;
for (int i = 0; i < path_.size_s() - 1; ++i)
s = s.section(path_[i]);
return s[path_.back()];
s = &(s->section(path_[i]));
if (!s) return null;
return (*s)[path_.back()];
}
int CDSection::count(bool recursive) const {
@@ -288,12 +313,19 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
PIMap<int, CDType>::iterator i;
for (i = k.begin(); i != k.end(); ++i) {
CDType & ck(i.value());
//l.clear();
l = PIString::fromNumber(ck.index()) + ".f = " + ck.formula() + " #s " + ck.comment() + " \n";
l.clear(); l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << " \n";
d->write(l.toUTF8());
l.clear();
l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << " \n";
l.clear(); l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << " \n";
d->write(l.toUTF8());
if (!ck.enumValues().isEmpty()) {
l.clear(); l << ck.index() << ".ev = {";
//PIVector<CDType::Enumerator> el = ck.enumValues();
piForeachC (CDType::Enumerator & e, ck.enumValues())
l << e.first << " - " << e.second << ", ";
l.cutRight(2);
l << "} \n";
d->write(l.toUTF8());
}
}
}
if (!s.isEmpty()) {
@@ -327,7 +359,13 @@ void CDSection::read(const void * ep) {
// piCout << "[read]" << ke->name() << ke->value() << ok;
// PIString n = ke->getValue("v").comment();
// PIString t = n.takeLeft(1);
if (ok) k[kid] = CDType(kid, ke->getValue("v").comment(), ke->getValue("v").type(), ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment(), CDType::cdK);
if (ok) {
CDType ck = CDType(kid, ke->getValue("v").comment(), ke->getValue("v").type(), ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment(), CDType::cdK);
PIString ev = ke->getValue("ev", "");
if (!ev.isEmpty())
ck.enum_values = ck.parseEnumComment(ev);
k[kid] = ck;
}
}
PIConfig::Entry & sl = e.getValue("s");
for (int i = 0; i < sl.childCount(); ++i) {
@@ -344,6 +382,7 @@ void CDSection::update(CDSection & v, bool keep_names) {
PIMap<PIString, PIString> prev_k_f;
PISet<int> used;
PIMap<int, CDType>::iterator i;
//piCout << "before" << k.size() << v.k.size();
if (keep_names) {
for (i = k.begin(); i != k.end(); ++i)
prev_k_f[i.value().name_] = i.value().formula();
@@ -362,6 +401,7 @@ void CDSection::update(CDSection & v, bool keep_names) {
ck.setFormula(prev_k_f[ck.name_]);
}
}
//piCout << " after" << k.size();
for (i = v.k.begin(); i != v.k.end(); ++i) {
if (!used.contains(i.key()))
k[i.key()] = i.value();
@@ -433,6 +473,7 @@ void CDSection::makePath(PIDeque<int> p) {
tp = p;
tp << i.key();
i.value().path_ = tp;
//piCout << "path for" << i.value().name() << tp;
}
PIMap<int, CDSection>::iterator j;
for (j = s.begin(); j != s.end(); ++j) {
@@ -456,3 +497,12 @@ PIVector<CDType * > CDSection::children(bool recursive) const {
}
PIVector<CDType::Enumerator> CDSection::enumValues() const {
PIVector<CDType::Enumerator> ret;
PIMap<int, CDType>::const_iterator i;
for (i = k.begin(); i != k.end(); ++i)
ret << CDType::Enumerator(i.key(), i.value().name());
return ret;
}

View File

@@ -18,6 +18,7 @@ class CDType {
friend class CDSection;
public:
enum cdT {cdNull, cdK, cdX, cdC};
typedef PIPair<int, PIString> Enumerator;
CDType();
CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t);
int index() const {return index_;}
@@ -30,20 +31,23 @@ public:
int toInt() const {return value_i;}
bool toBool() const {return value_b;}
cdT cd_type() const {return cd_type_;}
void setFormula(const PIString & formula);
void setValue(const PIString & value_);
void setFormula(const PIString & formula);
void setComment(const PIString & comment) {comment_ = comment;}
operator double() const {return value_d;}
const PIStringList & enumValues() const {return enum_values;}
const PIVector<CDType::Enumerator> & enumValues() const {return enum_values;}
void setEnumValues(const PIVector<CDType::Enumerator> & ev) {enum_values = ev;}
const PIString & errorString() const {return error_;}
PIDeque<int> path() const {return path_;}
protected:
bool calculate(PIEvaluator * e, PIVector<const CDType * > stack = PIVector<const CDType * >());
PIVector<CDType::Enumerator> parseEnumComment(PIString c);
cdT cd_type_;
int index_;
PIString name_, type_;
PIString value_s, formula_, comment_, error_;
PIStringList enum_values;
PIVector<CDType::Enumerator> enum_values;
CDSection * parent;
PIDeque<int> path_;
double value_d;
@@ -81,6 +85,7 @@ public:
void calculate();
void makePath(PIDeque<int> p = PIDeque<int>());
PIVector<CDType * > children(bool recursive = true) const;
PIVector<CDType::Enumerator> enumValues() const;
PIString name;
PIString alias;