From a3e88f792d58a95f943f1bd0d82d1f522a8b6f8d Mon Sep 17 00:00:00 2001 From: peri4 Date: Wed, 20 Nov 2024 20:01:58 +0300 Subject: [PATCH] apply some code analyzer recommendations --- libs/core/cdutils_c.cpp | 2 +- libs/core/cdutils_core.cpp | 12 ++++++------ libs/core/cdutils_types.cpp | 12 ------------ libs/core/cdutils_types.h | 24 +++++++++++------------- libs/qt/qcd_core.cpp | 2 +- libs/qt/qcd_view.cpp | 2 +- utils/pult/cdgraphics.cpp | 6 +++--- utils/pult/cdpultwindow.cpp | 2 +- 8 files changed, 24 insertions(+), 38 deletions(-) diff --git a/libs/core/cdutils_c.cpp b/libs/core/cdutils_c.cpp index d15bfd4..0629fdb 100644 --- a/libs/core/cdutils_c.cpp +++ b/libs/core/cdutils_c.cpp @@ -31,7 +31,7 @@ void CInterface::autoConnect(PIObject * o, const PIString & prefix) { // piCout << "func" << it.value().func_name; } PIVector cl = C.root().children(); - piForeachC(CDType * c, cl) { + for (const auto * c: cl) { PIString cp = prefix + c->pathString().join("_"); if (cp.isEmpty()) continue; if (!eh_map.contains(cp)) continue; diff --git a/libs/core/cdutils_core.cpp b/libs/core/cdutils_core.cpp index 66261d6..afb4d04 100644 --- a/libs/core/cdutils_core.cpp +++ b/libs/core/cdutils_core.cpp @@ -112,7 +112,7 @@ void CDCore::cd_read(CDSection * cd, PIIODevice * d) { initRoot(cd); raiseChangedGlobal(cd->cd_type_); /*PIVector ds = connection.allDevices(); - piForeach(PIIODevice * d, ds) { + for (PIIODevice * d: ds) { if (d) piCoutObj << d->constructFullPath() << d->isOpened(); }*/ @@ -377,7 +377,7 @@ void CDCore::xTimerTick() { } else { ba = makeHeader(CD_XValues, 0); ba << x_selected; - piForeachC(PIDeque & p, x_selected) { + for (const auto & p: x_selected) { x_[p].writeX(ba); } // piCout << "x app" << x_selected.size(); @@ -471,7 +471,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) { ba >> x_selected; // piCout << "X req" << x_selected.size(); x_.setSelectedX(false); - piForeachC(PIDeque & p, x_selected) { + for (const auto & p: x_selected) { x_[p].x_enabled = true; } x_mutex.unlock(); @@ -481,7 +481,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) { PIVector> x_vals; ba >> x_vals; x_mutex.lock(); - piForeachC(PIDeque & p, x_vals) { + for (const auto & p: x_vals) { x_[p].readX(ba); } x_mutex.unlock(); @@ -558,7 +558,7 @@ PIString CDCore::pathToString(const PIDeque & p) { PIDeque CDCore::stringToPath(const PIString & p) { PIDeque ret; PIStringList sl = p.split("."); - piForeachC(PIString & s, sl) + for (const auto & s: sl) ret << s.toInt(); return ret; } @@ -568,7 +568,7 @@ void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & da // piCoutObj << "dataReceived" << from << data.size(); PIIODevice * d = connection.deviceByName("cd"); if (d && d == connection.deviceByFullPath(from)) { - if (data.size() >= sizeof(4)) { + if (data.size() >= sizeof(int)) { PIByteArray ba = data; uchar header = ba.take_front(); if (header == header_transfer) { diff --git a/libs/core/cdutils_types.cpp b/libs/core/cdutils_types.cpp index 7cea143..aae7163 100644 --- a/libs/core/cdutils_types.cpp +++ b/libs/core/cdutils_types.cpp @@ -3,24 +3,12 @@ #include "cdutils_core.h" #include "piconfig.h" #include "pievaluator.h" -#include "pifile.h" using namespace CDUtils; const int cd_x_history_max_size = 4000; -CDType::CDType() { - index_ = -1; - value_d = 0.; - value_i = 0; - value_b = calculated = x_enabled = false; - cd_type_ = cdNull; - parent = 0; - avg_size = 1; - mode_ = rmode_ = X_Current; -} - CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) { index_ = i; diff --git a/libs/core/cdutils_types.h b/libs/core/cdutils_types.h index 6850e5d..a9ebaa7 100644 --- a/libs/core/cdutils_types.h +++ b/libs/core/cdutils_types.h @@ -73,7 +73,7 @@ public: X_All_Avg }; - CDType(); + CDType() {} CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t); CDType & operator=(double x); @@ -113,19 +113,20 @@ public: protected: bool calculate(PIEvaluator * e, PIVector stack = PIVector()); PIVariantTypes::Enum parseEnumComment(PIString c); - cdT cd_type_; - int index_; + + cdT cd_type_ = cdNull; + int index_ = -1; PIString name_, type_; PIString value_s, formula_, comment_, error_; PIVariantTypes::Enum enum_values; - CDSection * parent; + CDSection * parent = nullptr; PIDeque path_; - double value_d; - int value_i; - bool value_b, calculated, x_enabled; + double value_d = 0.; + int value_i = 0; + bool value_b = false, calculated = false, x_enabled = false; PIVector avg_h; - int avg_size; - XMode mode_, rmode_; + int avg_size = 1; + XMode mode_ = X_Current, rmode_ = X_Current; }; @@ -163,10 +164,7 @@ public: PIString alias; protected: - CDSection(PIMap k_, PIMap s_) { - cd = k_; - s = s_; - } + CDSection(PIMap k_, PIMap s_): cd(k_), s(s_) {} CDType & getByName(const PIString & name_); CDType & getByPath(const PIDeque & path_); void write(PIIODevice * d, const PIString & prefix = PIString()); diff --git a/libs/qt/qcd_core.cpp b/libs/qt/qcd_core.cpp index d1e675d..aa15efa 100644 --- a/libs/qt/qcd_core.cpp +++ b/libs/qt/qcd_core.cpp @@ -140,7 +140,7 @@ bool QCDCore::bindWidget(QWidget * w) { return false; } PIVector ak = K.root().children(); - piForeachC(CDType * k, ak) { + for (const auto * k: ak) { if (!on.endsWith(PI2QString(k->pathString().join("_")))) continue; if (bindWidget(w, *k)) return true; } diff --git a/libs/qt/qcd_view.cpp b/libs/qt/qcd_view.cpp index 9f920ea..d9071c4 100644 --- a/libs/qt/qcd_view.cpp +++ b/libs/qt/qcd_view.cpp @@ -344,7 +344,7 @@ void CDView::cd_receivedX() { X.lock(); PIVector> xl = X.enabledList(); // piCout << "X" << xl.size(); - piForeachC(PIDeque & x, xl) { + for (const auto & x: xl) { CDType & t(X[x]); // piCout << t; // piCout << t.path(); diff --git a/utils/pult/cdgraphics.cpp b/utils/pult/cdgraphics.cpp index 726a30d..58c117b 100644 --- a/utils/pult/cdgraphics.cpp +++ b/utils/pult/cdgraphics.cpp @@ -21,7 +21,7 @@ using namespace CDUtils; QStringList CDUtils::getList(const PIVector> & x_list) { QStringList ret; - piForeachC(PIDeque & p, x_list) + for (const auto & p: x_list) ret << PI2QString(CDCore::pathToString(p)); return ret; } @@ -29,7 +29,7 @@ QStringList CDUtils::getList(const PIVector> & x_list) { PIVector> CDUtils::setList(const QStringList & l) { PIVector> ret; - foreach(QString s, l) + for (const auto & s: l) ret << CDCore::stringToPath(Q2PIString(s)); return ret; } @@ -294,7 +294,7 @@ void CDGraphics::receivedX() { X.lock(); PIVector> x_list = X.enabledList(); PIVector ch; - piForeachC(PIDeque & p, x_list) { + for (const auto & p: x_list) { CDType & t(X[p]); if (t.xmode_rec() == CDType::X_Current) ch.resize(1).fill(t.toDouble()); diff --git a/utils/pult/cdpultwindow.cpp b/utils/pult/cdpultwindow.cpp index 0baf04f..2b06f24 100644 --- a/utils/pult/cdpultwindow.cpp +++ b/utils/pult/cdpultwindow.cpp @@ -91,7 +91,7 @@ void CDPultWindow::apply(bool sessions) { X.lock(); PIVector> x_list = X.enabledList(); X.unlock(); - piForeachC(PIDeque & p, x_list) + for (const auto & p: x_list) X.enable(X[p]); ((CDItemModel *)widgetX->view->model())->updateModel(); widgetX->view->expandAll();