pimap iterators

This commit is contained in:
Бычков Андрей
2022-08-09 15:55:14 +03:00
parent c5824795e6
commit 6e11617ce8
2 changed files with 56 additions and 145 deletions

View File

@@ -26,8 +26,7 @@ void CInterface::autoConnect(PIObject * o, const PIString & prefix) {
if (!PIObject::__meta_data().contains(cid)) return;
PIMap<PIString, Handler> eh_map;
PIObject::__MetaData & md(PIObject::__meta_data()[cid]);
PIMap<const void * , __MetaFunc>::const_iterator it;
for (it = md.eh_func.constBegin(); it != md.eh_func.constEnd(); ++it) {
for (auto it = md.eh_func.begin(); it != md.eh_func.end(); ++it) {
eh_map[it.value().func_name] = (Handler)it.value().addr;
//piCout << "func" << it.value().func_name;
}

View File

@@ -6,7 +6,6 @@
using namespace CDUtils;
//int cdtype_debug_cnt = 1;
const int cd_x_history_max_size = 4000;
@@ -19,9 +18,6 @@ CDType::CDType() {
parent = 0;
avg_size = 1;
mode_ = rmode_ = X_Current;
// debug_cnt = cdtype_debug_cnt;
// cdtype_debug_cnt++;
// piCout << "[CDType]" << "create Null" << debug_cnt;
}
@@ -49,8 +45,6 @@ CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v
// piCout << type_.size() << type_.toUTF8();
// piCout << formula_.size() << formula_.toUTF8();
// piCout << comment_.size() << comment_.toUTF8();
// debug_cnt = cdtype_debug_cnt;
// cdtype_debug_cnt++;
// piCout << "[CDType] create" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
}
@@ -63,12 +57,14 @@ CDType & CDType::operator =(double x) {
avg_h << x;
double val = 0;
if (avg_h.size_s() >= avg_size) {
for (int i = 0; i < avg_h.size_s(); i++)
for (int i = 0; i < avg_h.size_s(); i++) {
val += avg_h[i];
}
val /= avg_h.size();
avg_h.clear();
if (history.size() < cd_x_history_max_size)
if (history.size() < cd_x_history_max_size) {
history << val;
}
}
}
return *this;
@@ -250,7 +246,7 @@ PIVariantTypes::Enum CDType::parseEnumComment(PIString c) {
if (type_ == "e") {
PIStringList sl = c.inBrackets('{', '}').split(",");
int cval = 0;
piForeach (PIString & s, sl) {
for (PIString & s : sl) {
s.trim();
if (s.isEmpty()) continue;
if (s[0].isDigit()) {
@@ -269,46 +265,6 @@ PIVariantTypes::Enum CDType::parseEnumComment(PIString c) {
}
//CDType::CDType(const CDType &cdt) {
// index_ = cdt.index_;
// name_ = cdt.name_;
// type_ = cdt.type_;
// value_s = cdt.value_s;
// formula_ = cdt.formula_;
// comment_ = cdt.comment_;
// value_d = cdt.value_d;
// value_i = cdt.value_i;
// value_b = cdt.value_b;
// cd_type_ = cdt.cd_type_;
// debug_cnt = cdtype_debug_cnt;
// cdtype_debug_cnt++;
// piCout << "[CDType] copy" << debug_cnt << "->" << cdt.debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
//}
//CDType &CDType::operator =(const CDType &cdt) {
// index_ = cdt.index_;
// name_ = cdt.name_;
// type_ = cdt.type_;
// value_s = cdt.value_s;
// formula_ = cdt.formula_;
// comment_ = cdt.comment_;
// value_d = cdt.value_d;
// value_i = cdt.value_i;
// value_b = cdt.value_b;
// cd_type_ = cdt.cd_type_;
// piCout << "[CDType] assign" << debug_cnt << "=" << cdt.debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
// //debug_cnt = cdt.debug_cnt;
// return *this;
//}
//CDType::~CDType() {
// piCout << "[CDType] delete" << debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
//}
CDSection::CDSection(CDType::cdT type_) {
cd_type_ = type_;
null.cd_type_ = type_;
@@ -342,9 +298,9 @@ bool CDSection::exists(PIDeque<int> path) const {
int CDSection::count(bool recursive) const {
int ret = cd.size_s();
if (recursive) {
PIMap<int, CDSection>::const_iterator i;
for (i = s.constBegin(); i != s.constEnd(); ++i)
for (auto i = s.begin(); i != s.end(); ++i) {
ret += i.value().count(recursive);
}
}
return ret;
}
@@ -459,7 +415,6 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
d->write(l.toUTF8());
if (!ck.enumValues().enum_list.isEmpty()) {
l = PIString::fromNumber(ck.index()) + ".ev = {";
//PIVector<CDType::Enumerator> el = ck.enumValues();
for (const PIVariantTypes::Enumerator & e : ck.enumValues().enum_list) {
l += PIString::fromNumber(e.value) + " - " + e.name + ", ";
}
@@ -516,8 +471,6 @@ void CDSection::read(const void * ep) {
bool ok = false;
int id = e->name().toInt(-1, &ok);
// piCout << "[read]" << ke->name() << ke->value() << ok;
// PIString n = ke->getValue("v").comment();
// PIString t = n.takeLeft(1);
if (ok) {
CDType c;
PIString ev;
@@ -565,174 +518,133 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
PIMap<int, PIString> prev_cd_f_bi;
PIMap<PIString, PIString> prev_cd_f_bn;
PIMap<int, CDType>::iterator i;
if (mode[SaveByIndex]) {
for (i = cd.begin(); i != cd.end(); ++i)
for (auto i = cd.begin(); i != cd.end(); ++i) {
prev_cd_f_bi[i.key()] = i.value().formula();
}
}
if (mode[SaveByName]) {
for (i = cd.begin(); i != cd.end(); ++i)
for (auto i = cd.begin(); i != cd.end(); ++i) {
prev_cd_f_bn[i.value().name_] = i.value().formula();
}
}
if (!mode[Merge])
cd.clear();
for (i = v.cd.begin(); i != v.cd.end(); ++i) {
if (!mode[Merge]) cd.clear();
for (auto i = v.cd.begin(); i != v.cd.end(); ++i) {
int id = i.key();
PIString n = i.value().name();
cd[id] = i.value();
if (mode[SaveByIndex]) {
if (prev_cd_f_bi.contains(id))
if (prev_cd_f_bi.contains(id)) {
cd[id].setFormula(prev_cd_f_bi[id]);
}
}
if (mode[SaveByName]) {
if (prev_cd_f_bn.contains(n))
if (prev_cd_f_bn.contains(n)) {
cd[id].setFormula(prev_cd_f_bn[n]);
}
}
}
PIMap<int, CDSection> prev_s_bi;
PIMap<PIString, CDSection> prev_s_bn;
PIMap<int, CDSection>::iterator j;
if (mode[SaveByIndex]) {
for (j = s.begin(); j != s.end(); ++j)
for (auto j = s.begin(); j != s.end(); ++j) {
prev_s_bi[j.key()] = j.value();
}
}
if (mode[SaveByName]) {
for (j = s.begin(); j != s.end(); ++j)
for (auto j = s.begin(); j != s.end(); ++j) {
prev_s_bn[j.value().alias] = j.value();
}
}
if (!mode[Merge])
s.clear();
for (j = v.s.begin(); j != v.s.end(); ++j) {
if (!mode[Merge]) s.clear();
for (auto j = v.s.begin(); j != v.s.end(); ++j) {
int id = j.key();
PIString n = j.value().alias;
s[id] = j.value();
if (mode[SaveByIndex]) {
if (prev_s_bi.contains(id))
s[id] = prev_s_bi[id];
if (prev_s_bi.contains(id)) s[id] = prev_s_bi[id];
}
if (mode[SaveByName]) {
if (prev_s_bn.contains(n))
s[id] = prev_s_bn[n];
if (prev_s_bn.contains(n)) s[id] = prev_s_bn[n];
}
s[id].update(j.value(), mode);
}
/*PISet<int> used;
for (i = k.begin(); i != k.end(); ++i) {
if (v.k.contains(i.key())) {
PIString f = k[i.key()].formula_;
CDType & cdt = v.k[i.key()];
cdt.formula_ = f;
k[i.key()] = cdt;
used << i.key();
}
if (mode) {
CDType & ck(k[i.key()]);
if (prev_k_f_bn.contains(ck.name_))
ck.setFormula(prev_k_f_bn[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();
CDType & ck(k[i.key()]);
ck.setFormula(prev_k_f_bn.value(ck.name_));
}
used.clear();
PIMap<int, CDSection>::iterator j;
for (j = s.begin(); j != s.end(); ++j) {
if (v.s.contains(j.key()))
j.value().update(v.s[j.key()], mode);
used << j.key();
}
for (j = v.s.begin(); j != v.s.end(); ++j) {
if (!used.contains(j.key()))
s[j.key()] = j.value();
}*/
// piCout << "[CDSection] update end";
}
bool CDSection::isSameStructure(CDSection & v) {
PIMap<PIString, int> cd_ids;
PIMap<int, CDType>::iterator i;
for (i = cd.begin(); i != cd.end(); ++i)
for (auto i = cd.begin(); i != cd.end(); ++i) {
cd_ids[i.value().name()] = i.key();
for (i = v.cd.begin(); i != v.cd.end(); ++i) {
}
for (auto i = v.cd.begin(); i != v.cd.end(); ++i) {
if (!cd_ids.contains(i.value().name())) continue;
//piCout << i.key() << k[i.key()].name() << i.value().name();
if (cd[cd_ids[i.value().name()]].index() != i.key())
return false;
if (cd[cd_ids[i.value().name()]].index() != i.key()) return false;
}
PIMap<int, CDSection>::iterator j;
for (j = v.s.begin(); j != v.s.end(); ++j) {
for (auto j = v.s.begin(); j != v.s.end(); ++j) {
if (!s.contains(j.key())) continue;
if (!s[j.key()].isSameStructure(j.value()))
return false;
if (!s[j.key()].isSameStructure(j.value())) return false;
}
return true;
}
void CDSection::prepareCalculate() {
PIMap<int, CDType>::iterator i;
for (i = cd.begin(); i != cd.end(); ++i) {
for (auto i = cd.begin(); i != cd.end(); ++i) {
i.value().parent = this;
i.value().calculated = false;
}
PIMap<int, CDSection>::iterator j;
for (j = s.begin(); j != s.end(); ++j)
for (auto j = s.begin(); j != s.end(); ++j) {
j.value().prepareCalculate();
}
}
void CDSection::calculateRecursive(PIEvaluator * e) {
PIMap<int, CDType>::iterator i;
for (i = cd.begin(); i != cd.end(); ++i)
for (auto i = cd.begin(); i != cd.end(); ++i) {
i.value().calculate(e);
PIMap<int, CDSection>::iterator j;
for (j = s.begin(); j != s.end(); ++j)
}
for (auto j = s.begin(); j != s.end(); ++j) {
j.value().calculateRecursive(e);
}
}
void CDSection::setSelectedX(bool yes) {
PIMap<int, CDType>::iterator i;
for (i = cd.begin(); i != cd.end(); ++i)
for (auto i = cd.begin(); i != cd.end(); ++i) {
i.value().x_enabled = yes;
PIMap<int, CDSection>::iterator j;
for (j = s.begin(); j != s.end(); ++j)
}
for (auto j = s.begin(); j != s.end(); ++j) {
j.value().setSelectedX(yes);
}
}
PIVector<PIDeque<int> > CDSection::collectX() const {
PIVector<PIDeque<int> > ret;
PIMap<int, CDType>::const_iterator i;
for (i = cd.begin(); i != cd.end(); ++i) {
if (i.value().x_enabled)
for (auto i = cd.begin(); i != cd.end(); ++i) {
if (i.value().x_enabled) {
ret << i.value().path();
}
}
PIMap<int, CDSection>::const_iterator j;
for (j = s.constBegin(); j != s.constEnd(); ++j)
for (auto j = s.begin(); j != s.end(); ++j) {
ret << j.value().collectX();
}
return ret;
}
void CDSection::makePath(PIDeque<int> p) {
PIDeque<int> tp;
PIMap<int, CDType>::iterator i;
for (i = cd.begin(); i != cd.end(); ++i) {
for (auto i = cd.begin(); i != cd.end(); ++i) {
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) {
for (auto j = s.begin(); j != s.end(); ++j) {
tp = p;
tp << j.key();
j.value().makePath(tp);
@@ -742,22 +654,22 @@ void CDSection::makePath(PIDeque<int> p) {
PIVector<CDType * > CDSection::children(bool recursive) const {
PIVector<CDType * > ret;
PIMap<int, CDType>::const_iterator i;
for (i = cd.begin(); i != cd.end(); ++i)
for (auto i = cd.begin(); i != cd.end(); ++i) {
ret << const_cast<CDType * >(&(i.value()));
}
if (!recursive) return ret;
PIMap<int, CDSection>::const_iterator j;
for (j = s.constBegin(); j != s.constEnd(); ++j)
for (auto j = s.begin(); j != s.end(); ++j) {
ret << j.value().children(true);
}
return ret;
}
PIVariantTypes::Enum CDSection::enumValues() const {
PIVariantTypes::Enum ret;
PIMap<int, CDType>::const_iterator i;
for (i = cd.constBegin(); i != cd.constEnd(); ++i)
for (auto i = cd.begin(); i != cd.end(); ++i) {
ret << PIVariantTypes::Enumerator(i.key(), i.value().name());
}
return ret;
}