From 6e11617ce85e6de539b33a79a9087b2588469a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Tue, 9 Aug 2022 15:55:14 +0300 Subject: [PATCH] pimap iterators --- libs/core/cdutils_c.cpp | 3 +- libs/core/cdutils_types.cpp | 198 ++++++++++-------------------------- 2 files changed, 56 insertions(+), 145 deletions(-) diff --git a/libs/core/cdutils_c.cpp b/libs/core/cdutils_c.cpp index 6ff28ac..22914e4 100644 --- a/libs/core/cdutils_c.cpp +++ b/libs/core/cdutils_c.cpp @@ -26,8 +26,7 @@ void CInterface::autoConnect(PIObject * o, const PIString & prefix) { if (!PIObject::__meta_data().contains(cid)) return; PIMap eh_map; PIObject::__MetaData & md(PIObject::__meta_data()[cid]); - PIMap::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; } diff --git a/libs/core/cdutils_types.cpp b/libs/core/cdutils_types.cpp index c937044..47bc890 100644 --- a/libs/core/cdutils_types.cpp +++ b/libs/core/cdutils_types.cpp @@ -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 path) const { int CDSection::count(bool recursive) const { int ret = cd.size_s(); if (recursive) { - PIMap::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 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 prev_cd_f_bi; PIMap prev_cd_f_bn; - PIMap::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 prev_s_bi; PIMap prev_s_bn; - PIMap::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 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::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 cd_ids; - PIMap::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::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::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::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::iterator i; - for (i = cd.begin(); i != cd.end(); ++i) + for (auto i = cd.begin(); i != cd.end(); ++i) { i.value().calculate(e); - PIMap::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::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::iterator j; - for (j = s.begin(); j != s.end(); ++j) + } + for (auto j = s.begin(); j != s.end(); ++j) { j.value().setSelectedX(yes); + } } PIVector > CDSection::collectX() const { PIVector > ret; - PIMap::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::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 p) { PIDeque tp; - PIMap::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::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 p) { PIVector CDSection::children(bool recursive) const { PIVector ret; - PIMap::const_iterator i; - for (i = cd.begin(); i != cd.end(); ++i) + for (auto i = cd.begin(); i != cd.end(); ++i) { ret << const_cast(&(i.value())); + } if (!recursive) return ret; - PIMap::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::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; }