get rid of piForeach
apply some code analyzer recommendations ICU flag now check if libicu exists prepare for more accurate growth of containers (limited PoT, then constantly increase size)
This commit is contained in:
@@ -286,9 +286,14 @@ endif()
|
||||
# Check if ICU used for PIString and PIChar
|
||||
set(PIP_ICU "no")
|
||||
if(ICU)
|
||||
pip_find_lib(icuuc)
|
||||
if (icuuc_FOUND)
|
||||
set(PIP_ICU "yes")
|
||||
add_definitions(-DPIP_ICU)
|
||||
list(APPEND LIBS_MAIN icuuc)
|
||||
else()
|
||||
message(STATUS "Warning: ICU requested, but not found. Build without ICU")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -707,6 +712,7 @@ macro(expand_to_length _out _str _len)
|
||||
endmacro()
|
||||
|
||||
list(REMOVE_ITEM LIBS_STATUS ${PIP_MODULES})
|
||||
list(REMOVE_DUPLICATES LIBS_STATUS)
|
||||
message("----------PIP----------")
|
||||
message(" Version: ${PIP_VERSION} ")
|
||||
message(" Linkage: ${PIP_LIB_TYPE_MSG}")
|
||||
|
||||
@@ -505,7 +505,7 @@ void PIScreen::wheel_event(PIKbdListener::WheelEvent we) {
|
||||
|
||||
bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
|
||||
PIVector<PIScreenTile *> vtl = rt->children(true), ftl;
|
||||
piForeach(PIScreenTile * t, vtl) {
|
||||
for (PIScreenTile * t: vtl) {
|
||||
if (t->focus_flags[CanHasFocus]) ftl << t;
|
||||
}
|
||||
int ind = -1;
|
||||
@@ -535,7 +535,7 @@ bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
|
||||
// piCout << ftl.size() << ind << next;
|
||||
if (next != 0) {
|
||||
PIVector<PIScreenTile *> tl = rt->children();
|
||||
piForeach(PIScreenTile * t, tl)
|
||||
for (PIScreenTile * t: tl)
|
||||
t->has_focus = false;
|
||||
if (!ftl.isEmpty()) {
|
||||
ind += next;
|
||||
@@ -565,7 +565,7 @@ void PIScreen::tileSetFocusInternal(PIScreenTile * t) {
|
||||
PIScreenTile * rt = rootTile();
|
||||
if (tile_dialog) rt = tile_dialog;
|
||||
PIVector<PIScreenTile *> tl = rt->children(), ftl;
|
||||
piForeach(PIScreenTile * i, tl)
|
||||
for (PIScreenTile * i: tl)
|
||||
i->has_focus = false;
|
||||
tile_focus = t;
|
||||
if (!tile_focus) return;
|
||||
@@ -651,7 +651,7 @@ void PIScreen::end() {
|
||||
|
||||
PIScreenTile * PIScreen::tileByName(const PIString & name) {
|
||||
PIVector<PIScreenTile *> tl(tiles());
|
||||
piForeach(PIScreenTile * t, tl)
|
||||
for (PIScreenTile * t: tl)
|
||||
if (t->name() == name) return t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -78,14 +78,14 @@ void PIScreenTile::removeTile(PIScreenTile * t) {
|
||||
|
||||
PIVector<PIScreenTile *> PIScreenTile::children(bool only_visible) {
|
||||
PIVector<PIScreenTile *> ret;
|
||||
piForeach(PIScreenTile * t, tiles)
|
||||
for (auto * t: tiles)
|
||||
if (t->visible || !only_visible) ret << t << t->children(only_visible);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIScreenTile * PIScreenTile::childUnderMouse(int x, int y) {
|
||||
piForeach(PIScreenTile * t, tiles) {
|
||||
for (auto * t: tiles) {
|
||||
if (!t->visible) continue;
|
||||
if (x >= t->x_ && (x - t->x_) < t->width_ && y >= t->y_ && (y - t->y_) < t->height_) {
|
||||
return t;
|
||||
@@ -103,13 +103,13 @@ void PIScreenTile::raiseEvent(TileEvent e) {
|
||||
|
||||
void PIScreenTile::setScreen(PIScreenBase * s) {
|
||||
screen = s;
|
||||
piForeach(PIScreenTile * t, tiles)
|
||||
for (auto * t: tiles)
|
||||
t->setScreen(s);
|
||||
}
|
||||
|
||||
|
||||
void PIScreenTile::deleteChildren() {
|
||||
piForeach(PIScreenTile * t, tiles) {
|
||||
for (auto * t: tiles) {
|
||||
t->parent = 0;
|
||||
delete t;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ void PIScreenTile::drawEventInternal(PIScreenDrawer * d) {
|
||||
(Color)back_format.color_back,
|
||||
back_format.flags);
|
||||
drawEvent(d);
|
||||
piForeach(PIScreenTile * t, tiles)
|
||||
for (auto * t: tiles)
|
||||
t->drawEventInternal(d);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ void PIScreenTile::sizeHint(int & w, int & h) const {
|
||||
w += sl;
|
||||
else
|
||||
h += sl;
|
||||
piForeachC(PIScreenTile * t, tiles) {
|
||||
for (const auto * t: tiles) {
|
||||
if (!t->visible) continue;
|
||||
int cw(0), ch(0);
|
||||
t->sizeHint(cw, ch);
|
||||
|
||||
@@ -38,7 +38,7 @@ TileSimple::TileSimple(const TileSimple::Row & r): PIScreenTile() {
|
||||
|
||||
void TileSimple::sizeHint(int & w, int & h) const {
|
||||
w = h = 0;
|
||||
piForeachC(Row & r, content)
|
||||
for (const auto & r: content)
|
||||
w = piMaxi(w, r.first.size_s());
|
||||
h = content.size_s();
|
||||
}
|
||||
@@ -139,7 +139,7 @@ TileList::TileList(const PIString & n, SelectionMode sm): PIScreenTile(n) {
|
||||
|
||||
void TileList::sizeHint(int & w, int & h) const {
|
||||
w = h = 0;
|
||||
piForeachC(Row & r, content)
|
||||
for (const auto & r: content)
|
||||
w = piMaxi(w, r.first.size_s());
|
||||
h = 3;
|
||||
}
|
||||
@@ -361,12 +361,12 @@ TileButtons::TileButtons(const PIString & n): PIScreenTile(n) {
|
||||
void TileButtons::sizeHint(int & w, int & h) const {
|
||||
w = h = 0;
|
||||
if (direction == Horizontal) {
|
||||
piForeachC(Button & b, content)
|
||||
for (const auto & b: content)
|
||||
w += b.first.size_s() + 4;
|
||||
w += piMaxi(0, content.size_s() - 1) * 2;
|
||||
h += 1;
|
||||
} else {
|
||||
piForeachC(Button & b, content)
|
||||
for (const auto & b: content)
|
||||
w = piMaxi(w, b.first.size_s() + 4);
|
||||
h += content.size_s();
|
||||
h += piMaxi(0, content.size_s() - 1);
|
||||
@@ -539,7 +539,7 @@ void TilePICout::drawEvent(PIScreenDrawer * d) {
|
||||
if (!out.isEmpty()) {
|
||||
PIStringList l = out.split("\n");
|
||||
bool scroll = (cur == content.size_s() - 1) || !has_focus;
|
||||
piForeachC(PIString & s, l)
|
||||
for (const auto & s: l)
|
||||
content << TileList::Row(s.trimmed(), format);
|
||||
if (content.size_s() > max_lines) content.remove(0, content.size_s() - max_lines);
|
||||
if (scroll) {
|
||||
|
||||
@@ -518,7 +518,7 @@ void PITerminal::applyEscSeq(PIString es) {
|
||||
return;
|
||||
}
|
||||
PIStringList args = es.split(";");
|
||||
piForeachC(PIString & a, args) {
|
||||
for (const auto & a: args) {
|
||||
int av = a.toInt();
|
||||
switch (av) {
|
||||
case 0: PRIVATE->cur_format = PIScreenTypes::CellFormat(); break;
|
||||
@@ -862,7 +862,7 @@ bool PITerminal::initialize() {
|
||||
ws.ws_col = dsize_x;
|
||||
ws.ws_row = dsize_y;
|
||||
PIStringList env = PIProcess::currentEnvironment();
|
||||
piForeachC(PIString & e, env)
|
||||
for (const auto & e: env)
|
||||
if (e.startsWith("TERM=")) {
|
||||
PRIVATE->term_type = termType(e.mid(5).trim().toLowerCase());
|
||||
// piCout << PRIVATE->term_type;
|
||||
|
||||
@@ -181,14 +181,14 @@ void PISystemMonitor::run() {
|
||||
__PIThreadCollection * pitc = __PIThreadCollection::instance();
|
||||
pitc->lock();
|
||||
PIVector<PIThread *> tv = pitc->threads();
|
||||
piForeach(PIThread * t, tv)
|
||||
for (auto * t: tv)
|
||||
if (t->isPIObject()) tbid[t->tid()] = t->name();
|
||||
pitc->unlock();
|
||||
// piCout << tbid.keys().toType<uint>();
|
||||
ProcessStats tstat;
|
||||
tstat.ID = pID_;
|
||||
#ifdef MICRO_PIP
|
||||
piForeach(PIThread * t, tv)
|
||||
for (auto * t: tv)
|
||||
if (t->isPIObject()) gatherThread(t->tid());
|
||||
#else
|
||||
# ifndef WINDOWS
|
||||
@@ -260,7 +260,7 @@ void PISystemMonitor::run() {
|
||||
tstat.physical_memsize = tstat.resident_memsize - tstat.share_memsize;
|
||||
|
||||
PIVector<PIFile::FileInfo> tld = PIDir(PRIVATE->proc_dir + "task").entries();
|
||||
piForeachC(PIFile::FileInfo & i, tld) {
|
||||
for (const auto & i: tld) {
|
||||
if (i.flags[PIFile::FileInfo::Dot] || i.flags[PIFile::FileInfo::DotDot]) continue;
|
||||
gatherThread(i.name().toInt());
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
|
||||
|
||||
PIString PICodeInfo::EnumInfo::memberName(int value_) const {
|
||||
piForeachC(PICodeInfo::EnumeratorInfo & e, members)
|
||||
for (const auto & e: members)
|
||||
if (e.value == value_) return e.name.toString();
|
||||
return PIString();
|
||||
}
|
||||
|
||||
|
||||
int PICodeInfo::EnumInfo::memberValue(const PIString & name_) const {
|
||||
piForeachC(PICodeInfo::EnumeratorInfo & e, members)
|
||||
for (const auto & e: members)
|
||||
if (e.name.toString() == name_) return e.value;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -86,55 +86,55 @@ void PICodeParser::parseFile(const PIString & file, bool follow_includes) {
|
||||
clear();
|
||||
parseFileInternal(file, follow_includes);
|
||||
/*piCout << "\n\n";
|
||||
piForeachC (Entity * c, entities) {
|
||||
for (const auto * c: entities) {
|
||||
piCout << "";
|
||||
piCout << c->type << c->name << c->parent_scope << c->parents << c->children << c->meta;
|
||||
if (c->parent_scope)
|
||||
piCout << "parent" << c->parent_scope->name;
|
||||
piCout << "Functions:";
|
||||
piForeachC (Member & m, c->functions)
|
||||
for (const auto & m: c->functions)
|
||||
piCout << m.type << m.name << m.meta;
|
||||
piCout << "Members:";
|
||||
piForeachC (Member & m, c->members)
|
||||
for (const auto & m: c->members)
|
||||
piCout << m.type << m.name << m.meta;
|
||||
}
|
||||
piCout << "\n\nDefines:";
|
||||
piForeachC (Define & m, defines)
|
||||
for (const auto & m: defines)
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << "\n\nMacros:";
|
||||
piForeachC (Macro & m, macros)
|
||||
for (const auto & m: macros)
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "\n\nClasses:";
|
||||
piCout << "\n\nEnums:";
|
||||
piForeachC (Enum & c, enums) {
|
||||
for (const auto & c: enums) {
|
||||
piCout << PIStringAscii("enum") << c.name << c.meta;
|
||||
piForeachC (EnumeratorInfo & e, c.members)
|
||||
for (const auto & e: c.members)
|
||||
piCout << " " << e.name << '=' << e.value << e.meta;
|
||||
}
|
||||
piCout << "\n\nTypedefs:";
|
||||
piForeachC (Typedef & c, typedefs)
|
||||
for (const auto & c: typedefs)
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
}
|
||||
|
||||
|
||||
void PICodeParser::parseFiles(const PIStringList & files, bool follow_includes) {
|
||||
clear();
|
||||
piForeachC(PIString & f, files)
|
||||
for (const auto & f: files)
|
||||
parseFileInternal(f, follow_includes);
|
||||
/*piCout << "\n\nDefines:";
|
||||
piForeachC (Define & m, defines)
|
||||
for (const auto & m: defines)
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << "\n\nMacros:";
|
||||
piForeachC (Macro & m, macros)
|
||||
for (const auto & m: macros)
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "\n\nClasses:";
|
||||
piForeachC (Entity * c, entities)
|
||||
for (const auto * c: entities)
|
||||
piCout << PIStringAscii("class") << c->name << c->parents;
|
||||
piCout << "\n\nEnums:";
|
||||
piForeachC (Enum & c, enums)
|
||||
for (const auto & c: enums)
|
||||
piCout << PIStringAscii("enum") << c.name << c.members;
|
||||
piCout << "\n\nTypedefs:";
|
||||
piForeachC (Typedef & c, typedefs)
|
||||
for (const auto & c: typedefs)
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ void PICodeParser::parseFileContent(PIString fc) {
|
||||
|
||||
|
||||
bool PICodeParser::isEnum(const PIString & name) {
|
||||
piForeachC(Enum & e, enums)
|
||||
for (const auto & e: enums)
|
||||
if (e.name == name) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ bool PICodeParser::parseFileInternal(const PIString & file, bool follow_includes
|
||||
|
||||
|
||||
void PICodeParser::clear() {
|
||||
piForeach(Entity * i, entities)
|
||||
for (auto * i: entities)
|
||||
delete i;
|
||||
defines.clear();
|
||||
macros.clear();
|
||||
@@ -193,7 +193,7 @@ void PICodeParser::clear() {
|
||||
cur_def_vis = Global;
|
||||
anon_num = 0;
|
||||
PIStringList defs = PIStringAscii(PICODE_DEFINES).split(",");
|
||||
piForeachC(PIString & d, defs)
|
||||
for (const auto & d: defs)
|
||||
defines << Define(d, "");
|
||||
defines << Define(PIStringAscii("PICODE"), "") << custom_defines;
|
||||
macros << Macro(PIStringAscii("PIOBJECT"), "", PIStringList() << "name")
|
||||
@@ -406,7 +406,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
}
|
||||
replaced_cnt++;
|
||||
replaced = false;
|
||||
piForeachC(Define & d, defines) {
|
||||
for (const auto & d: defines) {
|
||||
int ind(-1);
|
||||
while ((ind = pfc.find(d.first, ind + 1)) >= 0) {
|
||||
PIChar pc, nc;
|
||||
@@ -418,7 +418,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
replaced = true;
|
||||
}
|
||||
}
|
||||
piForeachC(Macro & m, macros) {
|
||||
for (const auto & m: macros) {
|
||||
int ind(-1);
|
||||
while ((ind = pfc.find(m.name, ind + 1)) >= 0) {
|
||||
PIChar pc, nc;
|
||||
@@ -550,7 +550,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
||||
PIStringList pl = cd.takeMid(ind + 1).trim().split(',');
|
||||
cd.cutRight(1);
|
||||
Entity * pe = 0;
|
||||
piForeachC(PIString & p, pl) {
|
||||
for (const auto & p: pl) {
|
||||
if (p.contains(' '))
|
||||
pn = p.mid(p.find(' ') + 1);
|
||||
else
|
||||
@@ -717,7 +717,7 @@ PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) {
|
||||
PICodeParser::MetaMap ret;
|
||||
if (fc.isEmpty()) return ret;
|
||||
PIStringList ml = fc.split(',');
|
||||
piForeachC(PIString & m, ml) {
|
||||
for (const auto & m: ml) {
|
||||
int i = m.find('=');
|
||||
if (i < 0) {
|
||||
ret[m.trimmed()] = PIString();
|
||||
@@ -742,7 +742,7 @@ bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc
|
||||
PIStringList vl(fc.split(','));
|
||||
PIString vn;
|
||||
int cv = -1, ind = 0;
|
||||
piForeach(PIString & v, vl) {
|
||||
for (auto & v: vl) {
|
||||
MetaMap meta;
|
||||
int mi = v.find(s_M);
|
||||
if (mi >= 0) {
|
||||
@@ -872,7 +872,7 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
normalizeEntityNamespace(me.type);
|
||||
int i = 0;
|
||||
// piCout << me.arguments_full;
|
||||
piForeach(PIString & a, me.arguments_full)
|
||||
for (auto & a: me.arguments_full)
|
||||
if ((i = a.find('=')) > 0) a.cutRight(a.size_s() - i).trim();
|
||||
for (int j = 0; j < me.arguments_full.size_s(); ++j)
|
||||
if (me.arguments_full[j] == s_void) {
|
||||
@@ -880,7 +880,7 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
--j;
|
||||
}
|
||||
me.arguments_type = me.arguments_full;
|
||||
piForeach(PIString & a, me.arguments_type) {
|
||||
for (auto & a: me.arguments_type) {
|
||||
crepl.clear();
|
||||
if (a.contains('[')) crepl = a.takeMid(a.find('['), a.findLast(']') - a.find('[') + 1);
|
||||
for (ts = a.size_s() - 1; ts >= 0; --ts)
|
||||
@@ -902,7 +902,7 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
// piCout << "member" << fc << tl;
|
||||
// piCout << "member after eb" << fc << ", bits =" << bits;
|
||||
if (tl.isEmpty()) return true;
|
||||
piForeach(PIString & v, tl)
|
||||
for (auto & v: tl)
|
||||
removeAssignment(v);
|
||||
bool vn = true;
|
||||
ctemp = tl.front().trim();
|
||||
@@ -947,7 +947,7 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
normalizeEntityNamespace(type);
|
||||
tl[0] = ctemp.trim();
|
||||
// piCout << "vars" << tl;
|
||||
piForeachC(PIString & v, tl) {
|
||||
for (const auto & v: tl) {
|
||||
crepl.clear();
|
||||
|
||||
me.name = v.trimmed();
|
||||
@@ -1025,7 +1025,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
}
|
||||
n.trim();
|
||||
int f = 0;
|
||||
piForeachC(Entity * e, entities) {
|
||||
for (const auto * e: entities) {
|
||||
if (e->name == n) {
|
||||
n = (pref + n + suff).trim();
|
||||
return;
|
||||
@@ -1037,7 +1037,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
piForeachC(Enum & e, enums) {
|
||||
for (const auto & e: enums) {
|
||||
if ((f = e.name.find(n)) >= 0)
|
||||
if (e.name.at(f - 1) == PIChar(':'))
|
||||
if (e.name.find(cur_namespace) >= 0) {
|
||||
@@ -1046,7 +1046,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
piForeachC(Typedef & e, typedefs) {
|
||||
for (const auto & e: typedefs) {
|
||||
if ((f = e.first.find(n)) >= 0)
|
||||
if (e.first.at(f - 1) == PIChar(':'))
|
||||
if (e.first.find(cur_namespace) >= 0) {
|
||||
@@ -1062,11 +1062,11 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
void PICodeParser::restoreTmpTemp(Member * e) {
|
||||
static const PIString s_T = PIStringAscii("$T");
|
||||
int i = 0;
|
||||
piForeach(PIString & a, e->arguments_full) {
|
||||
for (auto & a: e->arguments_full) {
|
||||
while ((i = a.find(s_T)) >= 0)
|
||||
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
|
||||
}
|
||||
piForeach(PIString & a, e->arguments_type) {
|
||||
for (auto & a: e->arguments_type) {
|
||||
while ((i = a.find(s_T)) >= 0)
|
||||
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
|
||||
}
|
||||
@@ -1167,7 +1167,7 @@ double PICodeParser::procMacrosCond(PIString fc) {
|
||||
|
||||
|
||||
bool PICodeParser::isDefineExists(const PIString & dn) {
|
||||
piForeachC(Define & d, defines) {
|
||||
for (const auto & d: defines) {
|
||||
if (d.first == dn) return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1175,7 +1175,7 @@ bool PICodeParser::isDefineExists(const PIString & dn) {
|
||||
|
||||
|
||||
double PICodeParser::defineValue(const PIString & dn) {
|
||||
piForeachC(Define & d, defines) {
|
||||
for (const auto & d: defines) {
|
||||
if (d.first == dn) return d.second.isEmpty() ? 1. : d.second.toDouble();
|
||||
}
|
||||
return dn.toDouble();
|
||||
@@ -1203,7 +1203,7 @@ void PICodeParser::replaceMeta(PIString & dn) {
|
||||
|
||||
|
||||
PICodeParser::Entity * PICodeParser::findEntityByName(const PIString & en) {
|
||||
piForeach(Entity * e, entities)
|
||||
for (auto * e: entities)
|
||||
if (e->name == en) return e;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
|
||||
#include "picontainers.h"
|
||||
|
||||
#include "piliterals_bytes.h"
|
||||
|
||||
|
||||
const size_t minAlloc = 64;
|
||||
const size_t maxPoTAlloc = 4_MiB;
|
||||
|
||||
|
||||
size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) {
|
||||
@@ -33,3 +36,13 @@ size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) {
|
||||
// printf("calcMinCount sizeof = %d, min_count = %d, pot = %d\n", szof, elc, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
size_t _PIContainerConstantsBase::calcMaxCountForPoT(size_t szof) {
|
||||
return maxPoTAlloc / szof;
|
||||
}
|
||||
|
||||
|
||||
size_t _PIContainerConstantsBase::calcStepAfterPoT(size_t szof) {
|
||||
return calcMaxCountForPoT(szof);
|
||||
}
|
||||
|
||||
@@ -67,15 +67,28 @@ private:
|
||||
class PIP_EXPORT _PIContainerConstantsBase {
|
||||
public:
|
||||
static size_t calcMinCountPoT(size_t szof);
|
||||
static size_t calcMaxCountForPoT(size_t szof);
|
||||
static size_t calcStepAfterPoT(size_t szof);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class _PIContainerConstants {
|
||||
public:
|
||||
// minimum elements for container
|
||||
static size_t minCountPoT() {
|
||||
static const size_t ret = _PIContainerConstantsBase::calcMinCountPoT(sizeof(T));
|
||||
return ret;
|
||||
}
|
||||
// maximum elements for 2^n growth
|
||||
static size_t maxCountForPoT() {
|
||||
static const size_t ret = _PIContainerConstantsBase::calcMaxCountForPoT(sizeof(T));
|
||||
return ret;
|
||||
}
|
||||
// add elements after 2^n growth
|
||||
static size_t stepAfterPoT() {
|
||||
static const size_t ret = _PIContainerConstantsBase::calcStepAfterPoT(sizeof(T));
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
PIStringList PICollection::groups() {
|
||||
PIStringList sl;
|
||||
PIVector<PICollection::Group> & cg(_groups());
|
||||
piForeachC(Group & g, cg)
|
||||
for (const auto & g: cg)
|
||||
sl << g.name;
|
||||
return sl;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ PIStringList PICollection::groups() {
|
||||
|
||||
PIVector<const PIObject *> PICollection::groupElements(const PIString & group) {
|
||||
PIVector<PICollection::Group> & cg(_groups());
|
||||
piForeachC(Group & g, cg)
|
||||
for (const auto & g: cg)
|
||||
if (g.name == group) return g.elements;
|
||||
return PIVector<const PIObject *>();
|
||||
}
|
||||
@@ -58,7 +58,7 @@ bool PICollection::addToGroup(const PIString & group, const PIObject * element)
|
||||
// piCout << "add to" << group << element;
|
||||
PIString n = PIStringAscii(element->className());
|
||||
PIVector<PICollection::Group> & cg(_groups());
|
||||
piForeach(Group & g, cg)
|
||||
for (auto & g: cg)
|
||||
if (g.name == group) {
|
||||
for (int i = 0; i < g.elements.size_s(); ++i)
|
||||
if (PIString(g.elements[i]->className()) == n) return false;
|
||||
|
||||
@@ -177,7 +177,9 @@ public:
|
||||
|
||||
private:
|
||||
Notifier();
|
||||
PIObject * o;
|
||||
NO_COPY_CLASS(Notifier)
|
||||
|
||||
PIObject * o = nullptr;
|
||||
std::atomic_int new_id = {1};
|
||||
};
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ PIInit::PIInit() {
|
||||
PIStringList ifpathes;
|
||||
ifpathes << PIStringAscii("/bin/ifconfig") << PIStringAscii("/sbin/ifconfig") << PIStringAscii("/usr/bin/ifconfig")
|
||||
<< PIStringAscii("/usr/sbin/ifconfig");
|
||||
piForeachC(PIString & i, ifpathes) {
|
||||
for (const auto & i: ifpathes) {
|
||||
if (fileExists(i)) {
|
||||
sinfo->ifconfigPath = i;
|
||||
break;
|
||||
|
||||
@@ -360,9 +360,9 @@ PIObject::Connection PIObject::piConnectU(PIObject * src,
|
||||
void *addr_src(0), *addr_dest(0);
|
||||
int args(0);
|
||||
bool que = (performer != 0);
|
||||
piForeachC(__MetaFunc & fs, m_src) {
|
||||
for (const auto & fs: m_src) {
|
||||
if (addr_src != 0) break;
|
||||
piForeachC(__MetaFunc & fd, m_dest) {
|
||||
for (const auto & fd: m_dest) {
|
||||
if (addr_src != 0) break;
|
||||
if (fs.canConnectTo(fd, args)) {
|
||||
addr_src = fs.addr;
|
||||
@@ -477,7 +477,7 @@ void PIObject::piDisconnectAll() {
|
||||
PIMutexLocker _ml(mutex_connect);
|
||||
PIVector<PIObject *> cv = connectors.toVector();
|
||||
// piCout << "disconnect connectors =" << connectors.size();
|
||||
piForeach(PIObject * o, cv) {
|
||||
for (auto * o: cv) {
|
||||
// piCout << "disconnect"<< src << o;
|
||||
if (!o || (o == this)) continue;
|
||||
if (!o->isPIObject()) continue;
|
||||
@@ -496,7 +496,7 @@ void PIObject::piDisconnectAll() {
|
||||
}
|
||||
}
|
||||
// piCout << "disconnect connections =" << connections.size();
|
||||
piForeachC(PIObject::Connection & c, connections) {
|
||||
for (const auto & c: connections) {
|
||||
if (c.functor) continue;
|
||||
if (!c.dest_o) continue;
|
||||
if (!c.dest_o->isPIObject()) continue;
|
||||
@@ -512,10 +512,10 @@ void PIObject::updateConnectors() {
|
||||
// piCout << "*** updateConnectors" << this;
|
||||
connectors.clear();
|
||||
PIMutexLocker _ml(mutexObjects());
|
||||
piForeach(PIObject * o, objects()) {
|
||||
for (auto * o: objects()) {
|
||||
if (o == this) continue;
|
||||
PIVector<Connection> & oc(o->connections);
|
||||
piForeach(Connection & c, oc)
|
||||
for (auto & c: oc)
|
||||
if (c.dest == this) connectors << o;
|
||||
}
|
||||
}
|
||||
@@ -551,7 +551,7 @@ void PIObject::callQueuedEvents() {
|
||||
PIVector<__QueuedEvent> qe = events_queue;
|
||||
events_queue.clear();
|
||||
mutex_queue.unlock();
|
||||
piForeachC(__QueuedEvent & e, qe) {
|
||||
for (const auto & e: qe) {
|
||||
if (e.dest_o->thread_safe_) e.dest_o->mutex_.lock();
|
||||
e.dest_o->emitter_ = e.src;
|
||||
callAddrV(e.slot, e.dest, e.values.size_s(), e.values);
|
||||
|
||||
@@ -510,7 +510,7 @@ public:
|
||||
//! Returns PIObject* with name "name" or 0, if there is no object found
|
||||
static PIObject * findByName(const PIString & name) {
|
||||
PIMutexLocker _ml(mutexObjects());
|
||||
piForeach(PIObject * i, PIObject::objects()) {
|
||||
for (auto * i: PIObject::objects()) {
|
||||
if (i->name() != name) continue;
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ bool PIBinaryLog::openDevice() {
|
||||
PIDir ld(logDir());
|
||||
if (ld.isExists()) {
|
||||
PIVector<PIFile::FileInfo> es = ld.allEntries();
|
||||
piForeachC(PIFile::FileInfo & i, es) {
|
||||
for (const auto & i: es) {
|
||||
if (i.extension() == "binlog" && i.isFile() && i.baseName().startsWith(filePrefix())) {
|
||||
setPath(i.path);
|
||||
break;
|
||||
|
||||
@@ -107,7 +107,7 @@ PIConfig::Entry PIConfig::Entry::_empty;
|
||||
PIConfig::Branch PIConfig::Branch::allLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
piForeach(Entry * i, *this) {
|
||||
for (auto * i: *this) {
|
||||
if (i->isLeaf())
|
||||
b << i;
|
||||
else
|
||||
@@ -128,7 +128,7 @@ PIConfig::Entry & PIConfig::Branch::getValue(const PIString & vname, const PIStr
|
||||
PIString name = tree.front();
|
||||
tree.pop_front();
|
||||
Entry * ce = 0;
|
||||
piForeach(Entry * i, *this)
|
||||
for (auto * i: *this)
|
||||
if (i->_name == name) {
|
||||
ce = i;
|
||||
break;
|
||||
@@ -140,7 +140,7 @@ PIConfig::Entry & PIConfig::Branch::getValue(const PIString & vname, const PIStr
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
piForeach(PIString & i, tree) {
|
||||
for (auto & i: tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
@@ -158,11 +158,11 @@ PIConfig::Entry & PIConfig::Branch::getValue(const PIString & vname, const PIStr
|
||||
PIConfig::Branch PIConfig::Branch::getValues(const PIString & name) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
piForeach(Entry * i, *this) {
|
||||
for (auto * i: *this) {
|
||||
if (i->isLeaf()) {
|
||||
if (i->_name.find(name) >= 0) b << i;
|
||||
} else {
|
||||
piForeach(Entry * j, i->_children)
|
||||
for (auto * j: i->_children)
|
||||
if (j->_name.find(name) >= 0) b << j;
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ PIConfig::Branch PIConfig::Branch::getValues(const PIString & name) {
|
||||
PIConfig::Branch PIConfig::Branch::getLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
piForeach(Entry * i, *this)
|
||||
for (auto * i: *this)
|
||||
if (i->isLeaf()) b << i;
|
||||
return b;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ PIConfig::Branch PIConfig::Branch::getLeaves() {
|
||||
PIConfig::Branch PIConfig::Branch::getBranches() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
piForeach(Entry * i, *this)
|
||||
for (auto * i: *this)
|
||||
if (!i->isLeaf()) b << i;
|
||||
return b;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ bool PIConfig::Branch::entryExists(const Entry * e, const PIString & name) const
|
||||
if (e->_children.isEmpty()) {
|
||||
return (e->_name == name);
|
||||
}
|
||||
piForeachC(Entry * i, e->_children)
|
||||
for (const auto * i: e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ bool PIConfig::Branch::entryExists(const Entry * e, const PIString & name) const
|
||||
PIConfig::Entry & PIConfig::Entry::getValue(const PIString & vname, const PIString & def, bool * exist) {
|
||||
PIStringList tree = vname.split(delim);
|
||||
Entry * ce = this;
|
||||
piForeach(PIString & i, tree) {
|
||||
for (auto & i: tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
@@ -230,7 +230,7 @@ PIConfig::Entry & PIConfig::Entry::getValue(const PIString & vname, const PIStri
|
||||
PIConfig::Branch PIConfig::Entry::getValues(const PIString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
piForeach(Entry * i, _children)
|
||||
for (auto * i: _children)
|
||||
if (i->_name.find(vname) >= 0) b << i;
|
||||
return b;
|
||||
}
|
||||
@@ -240,7 +240,7 @@ bool PIConfig::Entry::entryExists(const Entry * e, const PIString & name) const
|
||||
if (e->_children.isEmpty()) {
|
||||
return (e->_name == name);
|
||||
}
|
||||
piForeachC(Entry * i, e->_children)
|
||||
for (const auto * i: e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const {
|
||||
s << p << _name << " = " << _value << std::endl;
|
||||
else
|
||||
std::cout << p << _name << std::endl;
|
||||
piForeachC(Entry * i, _children)
|
||||
for (const auto * i: _children)
|
||||
i->coutt(s, nl);
|
||||
}
|
||||
#endif
|
||||
@@ -265,7 +265,7 @@ void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
|
||||
s << p << _name << " = " << _value << " (" << _type << " " << _comment << ")" << PICoutManipulators::NewLine;
|
||||
else
|
||||
s << p << _name << PICoutManipulators::NewLine;
|
||||
piForeachC(Entry * i, _children)
|
||||
for (const auto * i: _children)
|
||||
i->piCoutt(s, nl);
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ void PIConfig::_destroy() {
|
||||
piDeleteSafety(stream);
|
||||
if (own_dev && dev) delete dev;
|
||||
dev = nullptr;
|
||||
piForeach(PIConfig * c, inc_devs)
|
||||
for (auto * c: inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
}
|
||||
@@ -445,7 +445,7 @@ bool PIConfig::isOpened() const {
|
||||
PIConfig::Entry & PIConfig::getValue(const PIString & vname, const PIString & def, bool * exist) {
|
||||
PIStringList tree = vname.split(delim);
|
||||
Entry * ce = &root;
|
||||
piForeach(PIString & i, tree) {
|
||||
for (auto & i: tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
if (exist != 0) *exist = false;
|
||||
@@ -463,7 +463,7 @@ PIConfig::Entry & PIConfig::getValue(const PIString & vname, const PIString & de
|
||||
PIConfig::Branch PIConfig::getValues(const PIString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
piForeach(Entry * i, root._children)
|
||||
for (auto * i: root._children)
|
||||
if (i->_name.find(vname) >= 0) b << i;
|
||||
return b;
|
||||
};
|
||||
@@ -477,7 +477,7 @@ void PIConfig::addEntry(const PIString & name, const PIString & value, const PIS
|
||||
tree.pop_back();
|
||||
Entry *te, *ce, *entry = &root;
|
||||
if (tree.isEmpty()) toRoot = true;
|
||||
piForeach(PIString & i, tree) {
|
||||
for (auto & i: tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
@@ -550,7 +550,7 @@ void PIConfig::setValue(const PIString & name, const PIString & value, const PIS
|
||||
int PIConfig::entryIndex(const PIString & name) {
|
||||
PIStringList tree = name.split(delim);
|
||||
Entry * ce = &root;
|
||||
piForeach(PIString & i, tree) {
|
||||
for (auto & i: tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) return -1;
|
||||
}
|
||||
@@ -716,7 +716,7 @@ bool PIConfig::entryExists(const Entry * e, const PIString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
return (e->_name == name);
|
||||
}
|
||||
piForeachC(Entry * i, e->_children)
|
||||
for (const auto * i: e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -725,7 +725,7 @@ bool PIConfig::entryExists(const Entry * e, const PIString & name) const {
|
||||
void PIConfig::updateIncludes() {
|
||||
if (internal) return;
|
||||
all_includes.clear();
|
||||
piForeach(PIConfig * c, includes)
|
||||
for (auto * c: includes)
|
||||
all_includes << c->allLeaves();
|
||||
}
|
||||
|
||||
@@ -744,7 +744,7 @@ PIString PIConfig::parseLine(PIString v) {
|
||||
if (ex) {
|
||||
r = me._value;
|
||||
} else {
|
||||
piForeachC(PIConfig::Entry * e, all_includes)
|
||||
for (const auto * e: all_includes)
|
||||
if (e->_full_name == w) {
|
||||
r = e->_value;
|
||||
break;
|
||||
@@ -763,9 +763,7 @@ void PIConfig::parse() {
|
||||
Entry *entry = 0, *te = 0, *ce = 0;
|
||||
int ind, sind;
|
||||
bool isNew = false, isPrefix = false, wasMultiline = false, isMultiline = false;
|
||||
piForeach(PIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
piDeleteAllAndClear(inc_devs);
|
||||
includes.clear();
|
||||
if (!isOpened()) return;
|
||||
_seekToBeginDev();
|
||||
@@ -835,7 +833,7 @@ void PIConfig::parse() {
|
||||
name = tree.back();
|
||||
tree.pop_back();
|
||||
entry = &root;
|
||||
piForeachC(PIString & i, tree) {
|
||||
for (const auto & i: tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
Branch getBranches();
|
||||
Branch & filter(const PIString & f);
|
||||
bool isEntryExists(const PIString & name) const {
|
||||
piForeachC(Entry * i, *this)
|
||||
for (const auto * i: *this)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
private:
|
||||
bool entryExists(const Entry * e, const PIString & name) const;
|
||||
void allLeaves(Branch & b, Entry * e) {
|
||||
piForeach(Entry * i, e->_children) {
|
||||
for (auto * i: e->_children) {
|
||||
if (i->isLeaf())
|
||||
b << i;
|
||||
else
|
||||
@@ -124,12 +124,12 @@ public:
|
||||
}
|
||||
#ifdef PIP_STD_IOSTREAM
|
||||
void coutt(std::ostream & s, const PIString & p) const {
|
||||
piForeachC(Entry * i, *this)
|
||||
for (const auto * i: *this)
|
||||
i->coutt(s, p);
|
||||
}
|
||||
#endif
|
||||
void piCoutt(PICout s, const PIString & p) const {
|
||||
piForeachC(Entry * i, *this)
|
||||
for (const auto * i: *this)
|
||||
i->piCoutt(s, p);
|
||||
}
|
||||
|
||||
@@ -165,14 +165,14 @@ public:
|
||||
|
||||
//! Returns first child with name "name"
|
||||
Entry * findChild(const PIString & name) {
|
||||
piForeach(Entry * i, _children)
|
||||
for (auto * i: _children)
|
||||
if (i->_name == name) return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! Returns first child with name "name"
|
||||
const Entry * findChild(const PIString & name) const {
|
||||
piForeachC(Entry * i, _children)
|
||||
for (const auto * i: _children)
|
||||
if (i->_name == name) return i;
|
||||
return 0;
|
||||
}
|
||||
@@ -425,7 +425,7 @@ public:
|
||||
#endif
|
||||
void piCoutt(PICout s, const PIString & p) const;
|
||||
void deleteBranch() {
|
||||
piForeach(Entry * i, _children) {
|
||||
for (auto * i: _children) {
|
||||
i->deleteBranch();
|
||||
delete i;
|
||||
}
|
||||
@@ -573,7 +573,7 @@ public:
|
||||
//! Returns all top-level entries
|
||||
Branch allTree() {
|
||||
Branch b;
|
||||
piForeach(Entry * i, root._children)
|
||||
for (auto * i: root._children)
|
||||
b << i;
|
||||
b.delim = delim;
|
||||
return b;
|
||||
@@ -636,14 +636,14 @@ private:
|
||||
void _writeDev(const PIString & l);
|
||||
int childCount(const Entry * e) const {
|
||||
int c = 0;
|
||||
piForeachC(Entry * i, e->_children)
|
||||
for (const auto * i: e->_children)
|
||||
c += childCount(i);
|
||||
c += e->_children.size_s();
|
||||
return c;
|
||||
}
|
||||
bool entryExists(const Entry * e, const PIString & name) const;
|
||||
void buildFullNames(Entry * e) {
|
||||
piForeach(Entry * i, e->_children) {
|
||||
for (auto * i: e->_children) {
|
||||
if (e != &root)
|
||||
i->_full_name = e->_full_name + delim + i->_name;
|
||||
else
|
||||
@@ -652,13 +652,13 @@ private:
|
||||
}
|
||||
}
|
||||
void allLeaves(Branch & b, Entry * e) {
|
||||
piForeach(Entry * i, e->_children) {
|
||||
for (auto * i: e->_children) {
|
||||
if ((!i->_value.isEmpty() && !i->isLeaf()) || i->isLeaf()) b << i;
|
||||
allLeaves(b, i);
|
||||
}
|
||||
}
|
||||
void setEntryDelim(Entry * e, const PIString & d) {
|
||||
piForeach(Entry * i, e->_children)
|
||||
for (auto * i: e->_children)
|
||||
setEntryDelim(i, d);
|
||||
e->delim = d;
|
||||
}
|
||||
@@ -669,7 +669,7 @@ private:
|
||||
}
|
||||
void removeEntry(Branch & b, Entry * e);
|
||||
void deleteEntry(Entry * e) {
|
||||
piForeach(Entry * i, e->_children)
|
||||
for (auto * i: e->_children)
|
||||
deleteEntry(i);
|
||||
delete e;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ bool PIDir::make(bool withParents) {
|
||||
l.removeAll("");
|
||||
// piCout << l;
|
||||
PIString cdp;
|
||||
piForeachC(PIString & i, l) {
|
||||
for (const auto & i: l) {
|
||||
if (!cdp.isEmpty()
|
||||
#ifndef WINDOWS
|
||||
|| is_abs
|
||||
@@ -400,10 +400,10 @@ PIVector<PIFile::FileInfo> PIDir::allEntries() {
|
||||
PIStringList cdirs, ndirs;
|
||||
cdirs << path();
|
||||
while (!cdirs.isEmpty()) {
|
||||
piForeachC(PIString & d, cdirs) {
|
||||
for (const auto & d: cdirs) {
|
||||
scan_ = d;
|
||||
PIVector<PIFile::FileInfo> el = PIDir(d).entries();
|
||||
piForeachC(PIFile::FileInfo & de, el) {
|
||||
for (const auto & de: el) {
|
||||
if (de.name() == "." || de.name() == "..") continue;
|
||||
if (de.isSymbolicLink()) continue; /// TODO: resolve symlinks
|
||||
if (de.isDir()) {
|
||||
|
||||
@@ -229,7 +229,7 @@ PIString PIEthernet::macFromBytes(const PIByteArray & mac) {
|
||||
PIByteArray PIEthernet::macToBytes(const PIString & mac) {
|
||||
PIByteArray r;
|
||||
PIStringList sl = mac.split(PIStringAscii(":"));
|
||||
piForeachC(PIString & i, sl)
|
||||
for (const auto & i: sl)
|
||||
r << uchar(i.toInt(16));
|
||||
return r;
|
||||
}
|
||||
@@ -997,7 +997,7 @@ PIString PIEthernet::constructFullPathDevice() const {
|
||||
ret += ":" + readIP() + ":" + PIString::fromNumber(readPort());
|
||||
if (type() == PIEthernet::UDP) {
|
||||
ret += ":" + sendIP() + ":" + PIString::fromNumber(sendPort());
|
||||
piForeachC(PIString & m, multicastGroups())
|
||||
for (const auto & m: multicastGroups())
|
||||
ret += ":mcast:" + m;
|
||||
}
|
||||
return ret;
|
||||
@@ -1067,7 +1067,7 @@ void PIEthernet::configureFromVariantDevice(const PIPropertyStorage & d) {
|
||||
setSendIP(d.propertyValueByName("send IP").toString());
|
||||
setSendPort(d.propertyValueByName("send port").toInt());
|
||||
PIStringList mcgl = d.propertyValueByName("multicast").toStringList();
|
||||
piForeachC(PIString & g, mcgl) {
|
||||
for (const auto & g: mcgl) {
|
||||
joinMulticastGroup(g);
|
||||
}
|
||||
}
|
||||
@@ -1260,8 +1260,8 @@ PIVector<PINetworkAddress> PIEthernet::allAddresses() {
|
||||
PIEthernet::InterfaceList il = interfaces();
|
||||
PIVector<PINetworkAddress> ret;
|
||||
bool has_127 = false;
|
||||
piForeachC(PIEthernet::Interface & i, il) {
|
||||
if (i.address == "127.0.0.1") has_127 = true;
|
||||
for (const auto & i: il) {
|
||||
if (i.address.startsWith("127.0.0.")) has_127 = true;
|
||||
PINetworkAddress a(i.address);
|
||||
if (a.ip() == 0) continue;
|
||||
ret << a;
|
||||
|
||||
@@ -130,7 +130,7 @@ PIPeer::PeerInfo::PeerAddress::PeerAddress(const PINetworkAddress & a, const PIN
|
||||
|
||||
int PIPeer::PeerInfo::ping() const {
|
||||
int ret = -1;
|
||||
piForeachC(PeerAddress & a, addresses)
|
||||
for (const auto & a: addresses)
|
||||
if (a.ping > 0.) {
|
||||
if (ret < 0)
|
||||
ret = piRoundd(a.ping);
|
||||
@@ -155,7 +155,7 @@ void PIPeer::PeerInfo::destroy() {
|
||||
PINetworkAddress PIPeer::PeerInfo::fastestAddress() const {
|
||||
double mp = -1.;
|
||||
PINetworkAddress ret;
|
||||
piForeachC(PeerAddress & a, addresses) {
|
||||
for (const auto & a: addresses) {
|
||||
if (a.ping <= 0.) continue;
|
||||
if ((mp < 0) || (mp > a.ping)) {
|
||||
mp = a.ping;
|
||||
@@ -166,6 +166,27 @@ PINetworkAddress PIPeer::PeerInfo::fastestAddress() const {
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::PeerInfo::addNeighbour(const PIString & n) {
|
||||
if (!neighbours.contains(n)) neighbours << n;
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::PeerInfo::addNeighbours(const PIStringList & l) {
|
||||
for (const auto & n: l)
|
||||
if (!neighbours.contains(n)) neighbours << n;
|
||||
}
|
||||
|
||||
void PIPeer::PeerInfo::removeNeighbour(const PIString & n) {
|
||||
neighbours.removeAll(n);
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::PeerInfo::resetPing() {
|
||||
for (auto & a: addresses)
|
||||
a.ping = -1;
|
||||
}
|
||||
|
||||
|
||||
REGISTER_DEVICE(PIPeer)
|
||||
|
||||
PIPeer::PIPeer(const PIString & n)
|
||||
@@ -226,7 +247,7 @@ void PIPeer::initEths(PIStringList al) {
|
||||
// piCoutObj << "initEths start";
|
||||
PIEthernet * ce;
|
||||
const PIEthernet::Interface * cint = 0;
|
||||
piForeachC(PIString & a, al) {
|
||||
for (const auto & a: al) {
|
||||
ce = new PIEthernet();
|
||||
ce->setDebug(false);
|
||||
ce->setName("_S.PIPeer.traf_rec_" + a);
|
||||
@@ -261,7 +282,7 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
PIString nm;
|
||||
al << _PIPEER_MULTICAST_IP;
|
||||
// piCoutObj << "initMBcasts start" << al;
|
||||
piForeachC(PIString & a, al) {
|
||||
for (const auto & a: al) {
|
||||
// piCout << "mcast try" << a;
|
||||
ce = new PIEthernet();
|
||||
ce->setDebug(false);
|
||||
@@ -282,7 +303,7 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
}
|
||||
}
|
||||
al.removeAll(_PIPEER_MULTICAST_IP);
|
||||
piForeachC(PIString & a, al) {
|
||||
for (const auto & a: al) {
|
||||
ce = new PIEthernet();
|
||||
ce->setDebug(false);
|
||||
ce->setName("_S.PIPeer.bcast_" + a);
|
||||
@@ -429,6 +450,42 @@ bool PIPeer::send(const PIString & to, const void * data, int size) {
|
||||
}
|
||||
|
||||
|
||||
bool PIPeer::send(const PeerInfo * to, const PIByteArray & data) {
|
||||
if (!to) return false;
|
||||
return send(to->name, data.data(), data.size_s());
|
||||
}
|
||||
|
||||
|
||||
bool PIPeer::send(const PeerInfo * to, const PIString & data) {
|
||||
if (!to) return false;
|
||||
return send(to->name, data.data(), data.size_s());
|
||||
}
|
||||
|
||||
|
||||
bool PIPeer::send(const PeerInfo * to, const void * data, int size) {
|
||||
if (!to) return false;
|
||||
return send(to->name, data, size);
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::sendToAll(const PIByteArray & data) {
|
||||
for (const auto & i: peers)
|
||||
send(i.name, data.data(), data.size_s());
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::sendToAll(const PIString & data) {
|
||||
for (const auto & i: peers)
|
||||
send(i.name, data.data(), data.size_s());
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::sendToAll(const void * data, int size) {
|
||||
for (const auto & i: peers)
|
||||
send(i.name, data, size);
|
||||
}
|
||||
|
||||
|
||||
bool PIPeer::sendInternal(const PIString & to, const PIByteArray & data) {
|
||||
PIMutexLocker mlocker(peers_mutex);
|
||||
PeerInfo * dp = quickestPeer(to);
|
||||
@@ -484,7 +541,7 @@ bool PIPeer::dataRead(const uchar * readed, ssize_t size) {
|
||||
sba << int(6) << to << from << addr << time;
|
||||
// piCout << " ping from" << from << addr << ", send back to" << pi->name;
|
||||
send_mutex.lock();
|
||||
piForeachC(PeerInfo::PeerAddress & a, pi->addresses) {
|
||||
for (const auto & a: pi->addresses) {
|
||||
if (eth_send.send(a.address, sba)) diag_s.received(sba.size_s());
|
||||
}
|
||||
send_mutex.unlock();
|
||||
@@ -501,10 +558,10 @@ bool PIPeer::dataRead(const uchar * readed, ssize_t size) {
|
||||
// piCout << "ping reply" << to << from << addr;
|
||||
PIMutexLocker plocker(peers_mutex);
|
||||
if (to == self_info.name) { // ping echo
|
||||
piForeach(PeerInfo & p, peers) {
|
||||
for (auto & p: peers) {
|
||||
if (!p.isNeighbour()) continue;
|
||||
if (p.name != from) continue;
|
||||
piForeach(PeerInfo::PeerAddress & a, p.addresses) {
|
||||
for (auto & a: p.addresses) {
|
||||
if (a.address != addr) continue;
|
||||
if (a.last_ping >= time) break;
|
||||
ptime = ctime - time;
|
||||
@@ -662,11 +719,11 @@ bool PIPeer::mbcastRead(const uchar * data, ssize_t size) {
|
||||
}
|
||||
ch = true;
|
||||
}
|
||||
piForeach(PeerInfo & rpeer, rpeers) {
|
||||
for (auto & rpeer: rpeers) {
|
||||
// piCout << " to sync " << rpeer.name;
|
||||
if (rpeer.name == self_info.name) continue;
|
||||
bool exist = false;
|
||||
piForeach(PeerInfo & peer, peers) {
|
||||
for (auto & peer: peers) {
|
||||
if (peer.name == rpeer.name) {
|
||||
exist = true;
|
||||
if (isPeerRecent(peer, rpeer)) {
|
||||
@@ -706,7 +763,7 @@ bool PIPeer::mbcastRead(const uchar * data, ssize_t size) {
|
||||
}
|
||||
// piCout << "***";
|
||||
// piCout << self_info.name << self_info.neighbours;
|
||||
piForeach(PeerInfo & i, peers) {
|
||||
for (auto & i: peers) {
|
||||
if (i.dist == 0) {
|
||||
self_info.addNeighbour(i.name);
|
||||
i.addNeighbour(self_info.name);
|
||||
@@ -737,11 +794,11 @@ bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
|
||||
void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
send_mc_mutex.lock();
|
||||
// piCout << "sendMBcast" << ba.size() << "bytes ...";
|
||||
piForeach(PIEthernet * e, eths_mcast) {
|
||||
for (auto * e: eths_mcast) {
|
||||
if (e->isOpened())
|
||||
if (e->send(ba)) diag_s.sended(ba.size_s());
|
||||
}
|
||||
piForeach(PIEthernet * e, eths_bcast) {
|
||||
for (auto * e: eths_bcast) {
|
||||
if (e->isOpened())
|
||||
if (e->send(ba)) diag_s.sended(ba.size_s());
|
||||
}
|
||||
@@ -750,7 +807,7 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
if (eth_lo.send(ba)) diag_s.sended(ba.size_s());
|
||||
}
|
||||
PIVector<PIEthernet *> cl = eth_tcp_srv.clients();
|
||||
piForeach(PIEthernet * e, cl) {
|
||||
for (auto * e: cl) {
|
||||
if (e->isOpened() && e->isConnected())
|
||||
if (e->send(ba)) diag_s.sended(ba.size_s());
|
||||
}
|
||||
@@ -763,7 +820,7 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
|
||||
|
||||
void PIPeer::removeNeighbour(const PIString & name) {
|
||||
piForeach(PeerInfo & p, peers)
|
||||
for (auto & p: peers)
|
||||
p.neighbours.removeOne(name);
|
||||
self_info.removeNeighbour(name);
|
||||
}
|
||||
@@ -809,11 +866,11 @@ void PIPeer::pingNeighbours() {
|
||||
PIByteArray ba, sba;
|
||||
ba << int(5) << self_info.name;
|
||||
// piCoutObj << "*** pingNeighbours" << peers.size() << "...";
|
||||
piForeach(PeerInfo & p, peers) {
|
||||
for (auto & p: peers) {
|
||||
if (!p.isNeighbour()) continue;
|
||||
// piCout << " ping neighbour" << p.name << p.ping();
|
||||
send_mutex.lock();
|
||||
piForeach(PeerInfo::PeerAddress & a, p.addresses) {
|
||||
for (auto & a: p.addresses) {
|
||||
// piCout << " address" << a.address << a.wait_ping;
|
||||
if (a.wait_ping) {
|
||||
if ((PISystemTime::current(true) - a.last_ping).abs().toSeconds() <= _PIPEER_PING_TIMEOUT) continue;
|
||||
@@ -891,7 +948,7 @@ void PIPeer::syncPeers() {
|
||||
ba << int(3) << self_info.name << self_info << peers;
|
||||
peers_mutex.unlock();
|
||||
sendMBcast(ba);
|
||||
piForeachC(PIString & p, dpeers) {
|
||||
for (const auto & p: dpeers) {
|
||||
peerDisconnected(p);
|
||||
peerDisconnectedEvent(p);
|
||||
}
|
||||
@@ -930,6 +987,12 @@ void PIPeer::changeName(const PIString & new_name) {
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::setTcpServerIP(const PIString & ip) {
|
||||
server_ip = ip;
|
||||
tcpClientReconnect();
|
||||
}
|
||||
|
||||
|
||||
ssize_t PIPeer::bytesAvailable() const {
|
||||
ssize_t ret = 0;
|
||||
read_buffer_mutex.lock();
|
||||
@@ -1054,7 +1117,7 @@ void PIPeer::buildMap() {
|
||||
// piCout << "[PIPeer \"" + name_ + "\"] buildMap";
|
||||
peers_map.clear();
|
||||
addresses_map.clear();
|
||||
piForeach(PeerInfo & i, peers) {
|
||||
for (auto & i: peers) {
|
||||
i.trace = -1;
|
||||
peers_map[i.name] = &i;
|
||||
}
|
||||
@@ -1065,8 +1128,8 @@ void PIPeer::buildMap() {
|
||||
while (!cwave.isEmpty()) {
|
||||
nwave.clear();
|
||||
++cwi;
|
||||
piForeachC(PeerInfo * p, cwave) {
|
||||
piForeachC(PIString & nn, p->neighbours) {
|
||||
for (const auto * p: cwave) {
|
||||
for (const auto & nn: p->neighbours) {
|
||||
PeerInfo * np = peers_map.value(nn);
|
||||
if (!np) continue;
|
||||
if (np->trace >= 0) continue;
|
||||
@@ -1077,14 +1140,14 @@ void PIPeer::buildMap() {
|
||||
cwave = nwave;
|
||||
}
|
||||
PIVector<PeerInfo *> cpath;
|
||||
piForeach(PeerInfo & c, peers) {
|
||||
for (auto & c: peers) {
|
||||
cpath.clear();
|
||||
cpath << &c;
|
||||
cwave << &c;
|
||||
for (int w = c.trace - 1; w >= 0; --w) {
|
||||
nwave.clear();
|
||||
piForeachC(PeerInfo * p, cwave) {
|
||||
piForeachC(PIString & nn, p->neighbours) {
|
||||
for (const auto * p: cwave) {
|
||||
for (const auto & nn: p->neighbours) {
|
||||
PeerInfo * np = peers_map.value(nn);
|
||||
if (!np) continue;
|
||||
if (np->trace != w) continue;
|
||||
@@ -1103,3 +1166,10 @@ void PIPeer::buildMap() {
|
||||
void PIPeer::tcpClientReconnect() {
|
||||
eth_tcp_cli.connect(server_ip, _PIPEER_TCP_PORT);
|
||||
}
|
||||
|
||||
|
||||
bool PIPeer::hasPeer(const PIString & name) {
|
||||
for (const auto & i: peers)
|
||||
if (i.name == name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -72,18 +72,10 @@ public:
|
||||
PINetworkAddress fastestAddress() const;
|
||||
|
||||
protected:
|
||||
void addNeighbour(const PIString & n) {
|
||||
if (!neighbours.contains(n)) neighbours << n;
|
||||
}
|
||||
void addNeighbours(const PIStringList & l) {
|
||||
piForeachC(PIString & n, l)
|
||||
if (!neighbours.contains(n)) neighbours << n;
|
||||
}
|
||||
void removeNeighbour(const PIString & n) { neighbours.removeAll(n); }
|
||||
void resetPing() {
|
||||
for (int i = 0; i < addresses.size_s(); ++i)
|
||||
addresses[i].ping = -1;
|
||||
}
|
||||
void addNeighbour(const PIString & n);
|
||||
void addNeighbours(const PIStringList & l);
|
||||
void removeNeighbour(const PIString & n);
|
||||
void resetPing();
|
||||
void init();
|
||||
void destroy();
|
||||
|
||||
@@ -101,30 +93,12 @@ public:
|
||||
bool send(const PeerInfo & to, const PIByteArray & data) { return send(to.name, data.data(), data.size_s()); }
|
||||
bool send(const PeerInfo & to, const PIString & data) { return send(to.name, data.data(), data.size_s()); }
|
||||
bool send(const PeerInfo & to, const void * data, int size) { return send(to.name, data, size); }
|
||||
bool send(const PeerInfo * to, const PIByteArray & data) {
|
||||
if (to == 0) return false;
|
||||
return send(to->name, data.data(), data.size_s());
|
||||
}
|
||||
bool send(const PeerInfo * to, const PIString & data) {
|
||||
if (to == 0) return false;
|
||||
return send(to->name, data.data(), data.size_s());
|
||||
}
|
||||
bool send(const PeerInfo * to, const void * data, int size) {
|
||||
if (to == 0) return false;
|
||||
return send(to->name, data, size);
|
||||
}
|
||||
void sendToAll(const PIByteArray & data) {
|
||||
piForeachC(PeerInfo & i, peers)
|
||||
send(i.name, data.data(), data.size_s());
|
||||
}
|
||||
void sendToAll(const PIString & data) {
|
||||
piForeachC(PeerInfo & i, peers)
|
||||
send(i.name, data.data(), data.size_s());
|
||||
}
|
||||
void sendToAll(const void * data, int size) {
|
||||
piForeachC(PeerInfo & i, peers)
|
||||
send(i.name, data, size);
|
||||
}
|
||||
bool send(const PeerInfo * to, const PIByteArray & data);
|
||||
bool send(const PeerInfo * to, const PIString & data);
|
||||
bool send(const PeerInfo * to, const void * data, int size);
|
||||
void sendToAll(const PIByteArray & data);
|
||||
void sendToAll(const PIString & data);
|
||||
void sendToAll(const void * data, int size);
|
||||
|
||||
bool isMulticastReceive() const { return !eths_mcast.isEmpty(); }
|
||||
bool isBroadcastReceive() const { return !eths_bcast.isEmpty(); }
|
||||
@@ -145,10 +119,7 @@ public:
|
||||
void changeName(const PIString & new_name);
|
||||
const PIString & trustPeerName() const { return trust_peer; }
|
||||
void setTrustPeerName(const PIString & peer_name) { trust_peer = peer_name; }
|
||||
void setTcpServerIP(const PIString & ip) {
|
||||
server_ip = ip;
|
||||
tcpClientReconnect();
|
||||
}
|
||||
void setTcpServerIP(const PIString & ip);
|
||||
|
||||
ssize_t bytesAvailable() const override;
|
||||
|
||||
@@ -180,11 +151,7 @@ private:
|
||||
EVENT_HANDLER1(void, newTcpClient, PIEthernet *, client);
|
||||
EVENT_HANDLER(void, tcpClientReconnect);
|
||||
|
||||
bool hasPeer(const PIString & name) {
|
||||
piForeachC(PeerInfo & i, peers)
|
||||
if (i.name == name) return true;
|
||||
return false;
|
||||
}
|
||||
bool hasPeer(const PIString & name);
|
||||
bool removePeer(const PIString & name);
|
||||
void removeNeighbour(const PIString & name);
|
||||
void addPeer(const PeerInfo & pd);
|
||||
|
||||
@@ -685,7 +685,7 @@ bool PISerial::openDevice() {
|
||||
if (!pl.startsWith("/") && !pl.startsWith("com")) {
|
||||
p.clear();
|
||||
PIVector<DeviceInfo> devs = availableDevicesInfo();
|
||||
piForeachC(DeviceInfo & d, devs) {
|
||||
for (const auto & d: devs) {
|
||||
if (d.id() == pl) {
|
||||
p = d.path;
|
||||
break;
|
||||
@@ -1011,7 +1011,7 @@ PIPropertyStorage PISerial::constructVariantDevice() const {
|
||||
PIVariantTypes::Enum e;
|
||||
|
||||
PIVector<int> as = availableSpeeds();
|
||||
piForeachC(int s, as) {
|
||||
for (const auto s: as) {
|
||||
e << PIVariantTypes::Enumerator(s, PIString::fromNumber(s));
|
||||
}
|
||||
e.selectValue((int)inSpeed());
|
||||
@@ -1073,7 +1073,7 @@ PIVector<int> PISerial::availableSpeeds() {
|
||||
PIStringList PISerial::availableDevices(bool test) {
|
||||
PIVector<DeviceInfo> devs = availableDevicesInfo(test);
|
||||
PIStringList ret;
|
||||
piForeachC(DeviceInfo & d, devs)
|
||||
for (const auto & d: devs)
|
||||
ret << d.path;
|
||||
return ret;
|
||||
}
|
||||
@@ -1232,8 +1232,8 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
|
||||
# ifdef LINUX
|
||||
char linkbuf[1024];
|
||||
# endif
|
||||
piForeachC(PIFile::FileInfo & e, de) { // TODO changes in FileInfo
|
||||
piForeachC(PIString & p, prefixes) {
|
||||
for (const auto & e: de) { // TODO changes in FileInfo
|
||||
for (const auto & p: prefixes) {
|
||||
if (e.name().startsWith(p)) {
|
||||
di = DeviceInfo();
|
||||
di.path = e.path;
|
||||
|
||||
@@ -53,7 +53,7 @@ bool PIFileTransfer::send(const PIString & file) {
|
||||
|
||||
bool PIFileTransfer::send(const PIStringList & files) {
|
||||
PIVector<PIFile::FileInfo> fil;
|
||||
piForeachC(PIString & file, files)
|
||||
for (const auto & file: files)
|
||||
fil << PIFile::fileInfo(file);
|
||||
return send(fil);
|
||||
}
|
||||
@@ -305,7 +305,7 @@ void PIFileTransfer::receive_finished(bool ok) {
|
||||
desc >> files_;
|
||||
// piCoutObj << files_;
|
||||
PIStringList files;
|
||||
piForeachC(PFTFileInfo & fi, files_)
|
||||
for (const auto & fi: files_)
|
||||
files << fi.dest_path;
|
||||
pause();
|
||||
receiveFilesRequest(files, bytesAll(), &user_ok);
|
||||
|
||||
@@ -633,7 +633,7 @@ public:
|
||||
//! \~russian
|
||||
//! \brief Транспонирование матрицы.
|
||||
//! \details Работает только с квадратными матрицами.
|
||||
//! \return копия транспонированной матрицы.
|
||||
//! \return Копия транспонированной матрицы.
|
||||
PIMathMatrixT<Cols, Rows, Type> transposed() const {
|
||||
PIMathMatrixT<Cols, Rows, Type> tm;
|
||||
PIMM_FOR tm[c][r] = m[r][c];
|
||||
@@ -647,8 +647,8 @@ public:
|
||||
//! \~russian
|
||||
//! \brief Операция поворота матрицы.
|
||||
//! \details Работает только с матрицами 2x2.
|
||||
//! \return повернутая матрица.
|
||||
PIMathMatrixT<Rows, Cols, Type> rotate(Type angle) {
|
||||
//! \return Эта повернутая матрица.
|
||||
PIMathMatrixT<Rows, Cols, Type> & rotate(Type angle) {
|
||||
static_assert(Rows == 2 && Cols == 2, "Works only with 2x2 matrix");
|
||||
Type c = std::cos(angle);
|
||||
Type s = std::sin(angle);
|
||||
@@ -667,8 +667,8 @@ public:
|
||||
//! \~russian
|
||||
//! \brief Операция поворота матрицы.
|
||||
//! \details Работает только с матрицами 2x2.
|
||||
//! \return копия повернутой матрицы.
|
||||
PIMathMatrixT<Rows, Cols, Type> & rotated(Type angle) {
|
||||
//! \return Копия повернутой матрицы.
|
||||
PIMathMatrixT<Rows, Cols, Type> rotated(Type angle) {
|
||||
static_assert(Rows == 2 && Cols == 2, "Works only with 2x2 matrix");
|
||||
PIMathMatrixT<Cols, Rows, Type> outm;
|
||||
Type c = std::cos(angle);
|
||||
|
||||
@@ -34,6 +34,11 @@ const char PIMathSolver::methods_desc[] = "b{Methods:}\
|
||||
PIMathSolver::Method PIMathSolver::method_global = PIMathSolver::Eyler_2;
|
||||
|
||||
|
||||
PIMathSolver::PIMathSolver() {
|
||||
times.resize(4);
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::solve(double u, double h) {
|
||||
switch (method) {
|
||||
case Global:
|
||||
@@ -128,6 +133,12 @@ void PIMathSolver::fromTF(const TransferFunction & TF) {
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::setTime(double time) {
|
||||
times.pop_back();
|
||||
times.push_front(time);
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::solveEyler1(double u, double h) {
|
||||
F[0] = A * X + d * u;
|
||||
X += F[0] * h;
|
||||
@@ -258,3 +269,41 @@ void PIMathSolver::solvePA(double u, double h, uint deg) {
|
||||
}
|
||||
moveF();
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::solvePA2(double u, double h) {
|
||||
if (step > 0)
|
||||
solvePA(u, h, 2);
|
||||
else
|
||||
solveEyler1(u, h);
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::solvePA3(double u, double h) {
|
||||
if (step > 1)
|
||||
solvePA(u, h, 3);
|
||||
else
|
||||
solvePA2(u, h);
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::solvePA4(double u, double h) {
|
||||
if (step > 2)
|
||||
solvePA(u, h, 4);
|
||||
else
|
||||
solvePA3(u, h);
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::solvePA5(double u, double h) {
|
||||
if (step > 3)
|
||||
solvePA(u, h, 5);
|
||||
else
|
||||
solvePA4(u, h);
|
||||
}
|
||||
|
||||
|
||||
void PIMathSolver::moveF() {
|
||||
for (uint i = F.size() - 1; i > 0; --i)
|
||||
F[i] = F[i - 1];
|
||||
}
|
||||
|
||||
@@ -48,18 +48,12 @@ public:
|
||||
PolynomialApproximation_5 = 35
|
||||
};
|
||||
|
||||
PIMathSolver() {
|
||||
times.resize(4);
|
||||
step = 0;
|
||||
}
|
||||
PIMathSolver();
|
||||
|
||||
void solve(double u, double h);
|
||||
void fromTF(const TransferFunction & TF);
|
||||
void setMethod(Method m) { method = m; }
|
||||
void setTime(double time) {
|
||||
times.pop_back();
|
||||
times.push_front(time);
|
||||
}
|
||||
void setTime(double time);
|
||||
|
||||
void solveEyler1(double u, double h);
|
||||
void solveEyler2(double u, double h);
|
||||
@@ -68,40 +62,17 @@ public:
|
||||
void solveABM3(double u, double h);
|
||||
void solveABM4(double u, double h);
|
||||
void solvePA(double u, double h, uint deg);
|
||||
void solvePA2(double u, double h) {
|
||||
if (step > 0)
|
||||
solvePA(u, h, 2);
|
||||
else
|
||||
solveEyler1(u, h);
|
||||
}
|
||||
void solvePA3(double u, double h) {
|
||||
if (step > 1)
|
||||
solvePA(u, h, 3);
|
||||
else
|
||||
solvePA2(u, h);
|
||||
}
|
||||
void solvePA4(double u, double h) {
|
||||
if (step > 2)
|
||||
solvePA(u, h, 4);
|
||||
else
|
||||
solvePA3(u, h);
|
||||
}
|
||||
void solvePA5(double u, double h) {
|
||||
if (step > 3)
|
||||
solvePA(u, h, 5);
|
||||
else
|
||||
solvePA4(u, h);
|
||||
}
|
||||
void solvePA2(double u, double h);
|
||||
void solvePA3(double u, double h);
|
||||
void solvePA4(double u, double h);
|
||||
void solvePA5(double u, double h);
|
||||
|
||||
PIMathVectord X;
|
||||
static Method method_global;
|
||||
static const char methods_desc[];
|
||||
|
||||
private:
|
||||
void moveF() {
|
||||
for (uint i = F.size() - 1; i > 0; --i)
|
||||
F[i] = F[i - 1];
|
||||
}
|
||||
void moveF();
|
||||
|
||||
PIMathMatrixd A, M;
|
||||
PIMathVectord d, a1, b1;
|
||||
@@ -109,10 +80,10 @@ private:
|
||||
PIMathVectord XX, Y, pY;
|
||||
PIVector<PIMathVectord> F;
|
||||
PIVector<double> times;
|
||||
uint size, step;
|
||||
Method method;
|
||||
double sum, td, ct, lp, dh, t, x1, x0;
|
||||
bool ok;
|
||||
uint size = 0, step = 0;
|
||||
Method method = Global;
|
||||
double sum = 0., td = 0., ct = 0., lp = 0., dh = 0., t = 0., x1 = 0., x0 = 0.;
|
||||
bool ok = false;
|
||||
};
|
||||
|
||||
#endif // PIMATHSOLVER_H
|
||||
|
||||
@@ -457,7 +457,7 @@ void PIPluginLoader::mergeStatic() {
|
||||
PIStringList PIPluginLoader::pluginsDirectories(const PIString & name) {
|
||||
static PIStringList dl({".", "./plugins", "../PlugIns"});
|
||||
PIString ret;
|
||||
piForeachC(PIString d, dl) {
|
||||
for (const auto & d: dl) {
|
||||
PIString dp = d + "/" + name;
|
||||
if (PIDir::isExists(dp)) ret += dp;
|
||||
}
|
||||
@@ -470,8 +470,8 @@ PIString PIPluginLoader::findLibrary(const PIString & path) {
|
||||
static const PIStringList suffixes({"", libExtension()});
|
||||
PIFile::FileInfo fi(path);
|
||||
PIString dir = fi.dir(), name = fi.name();
|
||||
piForeachC(PIString & p, prefixes) {
|
||||
piForeachC(PIString & s, suffixes) {
|
||||
for (const auto & p: prefixes) {
|
||||
for (const auto & s: suffixes) {
|
||||
PIString fn = dir + p + name + s;
|
||||
if (PIFile::isExists(fn)) return fn;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo(bool ignore_cache) {
|
||||
}
|
||||
if (l_df.size_s() < 2) return ret;
|
||||
l_df.pop_front();
|
||||
piForeachC(PIString & s, l_df) {
|
||||
for (const auto & s: l_df) {
|
||||
PIStringList ml(s.replacedAll(" ", " ").split(" "));
|
||||
if (ml.size_s() < 2) continue;
|
||||
if (ml.front() == "none") continue;
|
||||
@@ -234,17 +234,10 @@ PIString PISystemInfo::machineKey() {
|
||||
PISystemInfo * si = instance();
|
||||
PIByteArray salt;
|
||||
PIString conf = confDir() + "/.pip_machine_salt";
|
||||
if (PIFile::isExists(conf)) {
|
||||
PIFile f(conf, PIIODevice::ReadOnly);
|
||||
f.open();
|
||||
salt = f.readAll();
|
||||
}
|
||||
if (PIFile::isExists(conf)) salt = PIFile::readAll(conf, false);
|
||||
if (salt.size_s() != SALT_SIZE) {
|
||||
salt = generateSalt();
|
||||
PIFile f(conf, PIIODevice::ReadWrite);
|
||||
f.open();
|
||||
f.clear();
|
||||
f.write(salt);
|
||||
PIFile::writeAll(conf, salt);
|
||||
}
|
||||
ret = si->OS_name + "_" + si->architecture + "_" + si->hostname + "_" + salt.toHex();
|
||||
}
|
||||
|
||||
@@ -1515,6 +1515,7 @@ PIString PIString::takeNumber() {
|
||||
}
|
||||
phase = 9;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
if (phase == 6) {
|
||||
if (c == 'f' || c == 's' || c == 'u' || c == 'l' || c == 'L')
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
private:
|
||||
PIVector<PIThread *> threads;
|
||||
std::function<void(int)> func;
|
||||
std::atomic_int counter;
|
||||
std::atomic_int counter = {0};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ int PIPropertyStorage::removePropertiesByFlag(int flag) {
|
||||
//! \~russian "flag_ignore" - битовое поле для исключения свойств из процесса слияния
|
||||
void PIPropertyStorage::updateProperties(const PIVector<PIPropertyStorage::Property> & properties_, int flag_ignore) {
|
||||
PIMap<PIString, PIVariant> values;
|
||||
piForeachC(Property & p, props)
|
||||
for (const auto & p: props)
|
||||
if (((p.flags & flag_ignore) != flag_ignore) || (flag_ignore == 0)) values[p.name] = p.value;
|
||||
props = properties_;
|
||||
for (uint i = 0; i < props.size(); ++i) {
|
||||
@@ -135,14 +135,14 @@ void PIPropertyStorage::updateProperties(const PIVector<PIPropertyStorage::Prope
|
||||
|
||||
|
||||
PIPropertyStorage::Property PIPropertyStorage::propertyByName(const PIString & name) const {
|
||||
piForeachC(Property & p, props)
|
||||
for (const auto & p: props)
|
||||
if (p.name == name) return p;
|
||||
return Property();
|
||||
}
|
||||
|
||||
|
||||
PIVariant PIPropertyStorage::propertyValueByName(const PIString & name) const {
|
||||
piForeachC(Property & p, props)
|
||||
for (const auto & p: props)
|
||||
if (p.name == name) return p.value;
|
||||
return PIVariant();
|
||||
}
|
||||
@@ -182,7 +182,7 @@ bool PIPropertyStorage::setPropertyFlags(const PIString & name, int flags) {
|
||||
|
||||
|
||||
PIPropertyStorage::Property & PIPropertyStorage::operator[](const PIString & name) {
|
||||
piForeach(Property & p, props)
|
||||
for (auto & p: props)
|
||||
if (p.name == name) return p;
|
||||
addProperty(name, "");
|
||||
return props.back();
|
||||
@@ -190,7 +190,7 @@ PIPropertyStorage::Property & PIPropertyStorage::operator[](const PIString & nam
|
||||
|
||||
|
||||
const PIPropertyStorage::Property PIPropertyStorage::operator[](const PIString & name) const {
|
||||
piForeachC(Property & p, props)
|
||||
for (const auto & p: props)
|
||||
if (p.name == name) return p;
|
||||
return Property();
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ PIString PIVariantTypes::IODevice::toPICout() const {
|
||||
}
|
||||
#endif // MICRO_PIP
|
||||
PIPropertyStorage ps = get();
|
||||
piForeachC(PIPropertyStorage::Property & p, ps) {
|
||||
for (const auto & p: ps) {
|
||||
s += ", " + p.name + "=\"" + p.value.toString() + "\"";
|
||||
}
|
||||
s += ")";
|
||||
|
||||
@@ -48,7 +48,7 @@ const PIVector<PIOpenCL::Platform> & PIOpenCL::platforms() {
|
||||
const PIVector<PIOpenCL::Device> PIOpenCL::devices() {
|
||||
PIVector<PIOpenCL::Device> ret;
|
||||
PIVector<PIOpenCL::Platform> pl = platforms();
|
||||
piForeachC(PIOpenCL::Platform & p, pl)
|
||||
for (const auto & p: pl)
|
||||
ret << p.devices;
|
||||
return ret;
|
||||
}
|
||||
@@ -56,8 +56,8 @@ const PIVector<PIOpenCL::Device> PIOpenCL::devices() {
|
||||
|
||||
PIOpenCL::Device PIOpenCL::deviceByID(void * id) {
|
||||
PIVector<PIOpenCL::Platform> pl = platforms();
|
||||
piForeachC(PIOpenCL::Platform & p, pl) {
|
||||
piForeachC(PIOpenCL::Device & d, p.devices) {
|
||||
for (const auto & p: pl) {
|
||||
for (const auto & d: p.devices) {
|
||||
if (d.id == id) return d;
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ void PIOpenCL::Context::deletePrograms() {
|
||||
piCout << "context: delete" << programs_.size() << "programs";
|
||||
PIVector<Program *> ptdl = programs_;
|
||||
programs_.clear();
|
||||
piForeach(Program * p, ptdl) {
|
||||
for (auto * p: ptdl) {
|
||||
if (p) delete p;
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ void PIOpenCL::Context::deleteBuffers() {
|
||||
piCout << "context: delete" << buffers_.size() << "buffers";
|
||||
PIVector<Buffer *> btdl = buffers_;
|
||||
buffers_.clear();
|
||||
piForeach(Buffer * b, btdl) {
|
||||
for (auto * b: btdl) {
|
||||
if (b) delete b;
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ PIOpenCL::Context * PIOpenCL::Context::create(const PIOpenCL::DeviceList & dl) {
|
||||
PIOpenCL::Context * PIOpenCL::Context::create(const PIString & part_name) {
|
||||
PIString pn = part_name.toLowerCase();
|
||||
PIVector<Device> dl = PIOpenCL::devices();
|
||||
piForeachC(Device & d, dl) {
|
||||
for (const auto & d: dl) {
|
||||
if (d.displayText().toLowerCase().contains(pn)) return create(d);
|
||||
}
|
||||
return 0;
|
||||
@@ -283,13 +283,13 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, co
|
||||
}
|
||||
PIStringList knl = PIString(knames).trim().split(";");
|
||||
PIVector<void *> kerns;
|
||||
piForeachC(PIString & k, knl) {
|
||||
for (const auto & k: knl) {
|
||||
cl_kernel kern = clCreateKernel(prog, k.dataAscii(), &ret);
|
||||
if (ret != 0) {
|
||||
piCout << "[PIOpenCL::Context]"
|
||||
<< "clCreateKernel" << k << "error" << ret;
|
||||
if (error) (*error) += "clCreateKernel(\"" + k + "\") error " + ret;
|
||||
piForeach(void * _k, kerns)
|
||||
for (auto * _k: kerns)
|
||||
clReleaseKernel((cl_kernel)_k);
|
||||
clReleaseProgram(prog);
|
||||
return 0;
|
||||
@@ -472,7 +472,7 @@ PIOpenCL::Program::Program() {
|
||||
PIOpenCL::Program::~Program() {
|
||||
// piCout << "destroy program" << this;
|
||||
if (context_) context_->programs_.removeAll(this);
|
||||
piForeach(Kernel * k, kernels_)
|
||||
for (auto * k: kernels_)
|
||||
delete k;
|
||||
if (PRIVATE->program) clReleaseProgram(PRIVATE->program);
|
||||
zero();
|
||||
@@ -487,7 +487,7 @@ void PIOpenCL::Program::zero() {
|
||||
|
||||
|
||||
bool PIOpenCL::Program::initKernels(PIVector<void *> kerns) {
|
||||
piForeach(void * _k, kerns) {
|
||||
for (auto * _k: kerns) {
|
||||
cl_kernel k = (cl_kernel)_k;
|
||||
// piCout << "init kernel" << k;
|
||||
Kernel * kern = new Kernel();
|
||||
@@ -635,7 +635,7 @@ int PIOpenCL::Kernel::argIndex(const PIString & an) const {
|
||||
|
||||
|
||||
PIOpenCL::KernelArg PIOpenCL::Kernel::argByName(const PIString & an) const {
|
||||
piForeachC(KernelArg & a, args_)
|
||||
for (const auto & a: args_)
|
||||
if (a.arg_name == an) return a;
|
||||
return KernelArg();
|
||||
}
|
||||
|
||||
22
main.cpp
22
main.cpp
@@ -12,7 +12,17 @@ const char * pageTitle = "<!DOCTYPE html>"
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
kbd.enableExitCapture();
|
||||
// piCout << PIString::readableSize(PISystemMonitor::usedRAM());
|
||||
|
||||
PIVector<int> vi;
|
||||
piForTimes(10) {
|
||||
piSleep(2.);
|
||||
vi.enlarge(1000000);
|
||||
piCout << "now" << vi.size() << vi.capacity();
|
||||
}
|
||||
|
||||
piSleep(5.);
|
||||
/*kbd.enableExitCapture();
|
||||
|
||||
PIHTTPServer server;
|
||||
|
||||
@@ -39,7 +49,7 @@ int main(int argc, char * argv[]) {
|
||||
return ret;
|
||||
});
|
||||
|
||||
server.registerPath("/api/*", MicrohttpdServer::Method::Post, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
|
||||
server.registerPath("/api/", MicrohttpdServer::Method::Post, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
|
||||
MicrohttpdServer::Reply ret;
|
||||
ret.setBody("<!DOCTYPE html><html><body>API etry %1</body></html>"_a.arg(r.path).toUTF8());
|
||||
ret.setCode(405);
|
||||
@@ -51,7 +61,7 @@ int main(int argc, char * argv[]) {
|
||||
ret.setBody("<!DOCTYPE html><html><body>Unknown</body></html>"_a.arg(r.path).toUTF8());
|
||||
ret.setCode(404);
|
||||
return ret;
|
||||
});
|
||||
});*/
|
||||
|
||||
/*server.setRequestCallback([](MicrohttpdServer::Request r) -> MicrohttpdServer::Reply {
|
||||
MicrohttpdServer::Reply rep;
|
||||
@@ -63,10 +73,12 @@ int main(int argc, char * argv[]) {
|
||||
rep.setBody(PIByteArray::fromAscii("[{\"value1\": true, \"value2\": \"ыекштп\"}]"));
|
||||
return rep;
|
||||
});*/
|
||||
piCout << "start" << server.isListen();
|
||||
|
||||
/*piCout << "start" << server.isListen();
|
||||
|
||||
WAIT_FOR_EXIT
|
||||
|
||||
server.stop();
|
||||
server.stop();*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ PIMap<PIString, PIStringList> qt_filters;
|
||||
|
||||
PIString findLib(const PIString & l) {
|
||||
if (PIFile::isExists(l)) return l;
|
||||
piForeachC(PIString & s, lib_dirs) {
|
||||
for (const auto & s: lib_dirs) {
|
||||
if (PIFile::isExists(s + l)) return s + l;
|
||||
if (win_target || l.toLowerCase().endsWith("dll")) {
|
||||
PIFile::FileInfo info(l);
|
||||
@@ -308,13 +308,13 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
|
||||
}
|
||||
if (!otool.isEmpty()) {
|
||||
lines = filter(execute(otool + " -L \"" + file + "\""), "(");
|
||||
piForeach(PIString & l, lines) {
|
||||
for (auto & l: lines) {
|
||||
l = l.left(l.find('('));
|
||||
l.trim(); //.append('.').prepend('.');
|
||||
}
|
||||
}
|
||||
}
|
||||
piForeachC(PIString & sl, lines) {
|
||||
for (const auto & sl: lines) {
|
||||
PIString l = sl.trimmed();
|
||||
if (!otool.isEmpty()) {
|
||||
PIString fname = frameworkName(l);
|
||||
@@ -367,7 +367,7 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
|
||||
}
|
||||
PIVector<PIString> clibs = cur_libs.toVector();
|
||||
if (!clibs.isEmpty()) piCout << " new dependencies:\n -" << PIStringList(clibs).join("\n - ");
|
||||
piForeachC(PIString & l, clibs) {
|
||||
for (const auto & l: clibs) {
|
||||
procLdd(l, false, cur_depth);
|
||||
}
|
||||
}
|
||||
@@ -402,7 +402,7 @@ void procQt() {
|
||||
PIDir(qt_plugins_dir).make(true);
|
||||
PIDir(qt_qml_dir).make(true);
|
||||
}
|
||||
piForeach(PIString l, vsl) {
|
||||
for (auto l: vsl) {
|
||||
if (l.trim().contains("Qt version")) {
|
||||
l.cutLeft(l.find("Qt version") + 10).trim();
|
||||
PIString qv = l.takeWord();
|
||||
@@ -411,7 +411,7 @@ void procQt() {
|
||||
piCout << "Qt" << qv << "in" << qloc;
|
||||
PIString qdir;
|
||||
PIStringList suffixes({".", "..", "qt5", "../qt5", "qt6", "../qt6"});
|
||||
piForeachC(PIString s, suffixes) {
|
||||
for (const auto & s: suffixes) {
|
||||
PIString qd = qloc + "/" + s + "/plugins/";
|
||||
if (piDebug) PICout(AddSpaces) << "Qt plugins root try" << qd << "...";
|
||||
if (PIDir::isExists(qd + "platforms")) {
|
||||
@@ -422,14 +422,14 @@ void procQt() {
|
||||
piCout << " no";
|
||||
}
|
||||
if (qdir.isEmpty()) break;
|
||||
piForeachC(PIString & plugin, pdirs) {
|
||||
for (const auto & plugin: pdirs) {
|
||||
PIStringList filters = qt_filters[plugin];
|
||||
piCout << "PLUG" << plugin << filters;
|
||||
piForeachC(PIString & f, filters) {
|
||||
for (const auto & f: filters) {
|
||||
if (f.isEmpty()) continue;
|
||||
copyWildcard(qdir + "plugins/" + plugin + "/" + f, qt_plugins_dir + plugin);
|
||||
PIVector<PIFile::FileInfo> copied = PIDir(qt_plugins_dir + plugin).entries();
|
||||
piForeachC(PIFile::FileInfo & fi, copied) {
|
||||
for (const auto & fi: copied) {
|
||||
if (fi.isFile()) {
|
||||
procLdd(fi.path);
|
||||
plugin_libs << fi.path;
|
||||
@@ -441,7 +441,7 @@ void procQt() {
|
||||
if (q.isEmpty()) continue;
|
||||
copyWildcard(qdir + "qml/" + q + "/*", qt_qml_dir + q);
|
||||
PIVector<PIFile::FileInfo> copied = PIDir(qt_qml_dir + q).allEntries();
|
||||
piForeachC(PIFile::FileInfo & fi, copied) {
|
||||
for (const auto & fi: copied) {
|
||||
if (fi.isFile()) {
|
||||
procLdd(fi.path);
|
||||
plugin_libs << fi.path;
|
||||
@@ -481,11 +481,11 @@ void patchNameTool() {
|
||||
PIFile::FileInfo fi;
|
||||
patch_list = input_files;
|
||||
patch_list << plugin_libs;
|
||||
piForeach(PIString l, clibs) {
|
||||
for (const auto & l: clibs) {
|
||||
fi.path = l;
|
||||
patch_list << (out_dir + fi.name());
|
||||
}
|
||||
piForeach(PIString local_lib, patch_list) {
|
||||
for (const auto & local_lib: patch_list) {
|
||||
execute("chmod +w \"" + local_lib + "\"");
|
||||
fi.path = local_lib;
|
||||
cmd = nametool + " -id \"@executable_path/../Frameworks/" + fi.name() + "\"";
|
||||
@@ -493,15 +493,15 @@ void patchNameTool() {
|
||||
// piCout << " " << cmd;
|
||||
execute(cmd);
|
||||
}
|
||||
piForeach(PIString f, flibs) {
|
||||
for (const auto & f: flibs) {
|
||||
PIString fl = findLib(frameworkName(f));
|
||||
if (fl.isEmpty()) continue;
|
||||
patch_list << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f));
|
||||
// PICout(DefaultControls) << "map" << f << "->" << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f));
|
||||
}
|
||||
piForeach(PIString local_lib, patch_list) {
|
||||
for (const auto & local_lib: patch_list) {
|
||||
dlibs = filter(execute(otool + " -L \"" + local_lib + "\""), "(");
|
||||
piForeach(PIString & l, dlibs) {
|
||||
for (auto & l: dlibs) {
|
||||
l = l.left(l.find('('));
|
||||
l.trim();
|
||||
}
|
||||
@@ -509,7 +509,7 @@ void patchNameTool() {
|
||||
execute("chmod +w \"" + local_lib + "\"");
|
||||
}
|
||||
piCout << "patch" << local_lib;
|
||||
piForeach(PIString sys_lib, dlibs) {
|
||||
for (auto sys_lib: dlibs) {
|
||||
sys_lib.cutRight(1).trim();
|
||||
fi.path = sys_lib;
|
||||
libname = fi.name();
|
||||
@@ -536,7 +536,7 @@ void patchNameTool() {
|
||||
}
|
||||
}
|
||||
}
|
||||
piForeach(PIString bin, input_files) {
|
||||
for (const auto & bin: input_files) {
|
||||
cmd = nametool + " -add_rpath \"@executable_path/../Frameworks\"";
|
||||
cmd += " \"" + bin + "\"" + ign_err_suffix;
|
||||
execute(cmd);
|
||||
@@ -559,9 +559,9 @@ void patchRPathFile(const PIFile::FileInfo & file) {
|
||||
void patchRPath() {
|
||||
PIStringList dirs({out_dir, target_dir, qt_plugins_dir, qt_qml_dir});
|
||||
dirs.removeDuplicates().removeStrings(PIString());
|
||||
piForeachC(PIString & d, dirs) {
|
||||
for (const auto & d: dirs) {
|
||||
PIVector<PIFile::FileInfo> files = PIDir(d).allEntries();
|
||||
piForeachC(PIFile::FileInfo & f, files) {
|
||||
for (const auto & f: files) {
|
||||
if (f.isDir()) continue;
|
||||
patchRPathFile(f.path);
|
||||
}
|
||||
@@ -649,7 +649,7 @@ int main(int argc, char * argv[]) {
|
||||
if (!qroot.endsWith("/")) qroot.append("/");
|
||||
lib_dirs << (qroot + "bin") << (qroot + "lib") << (qroot + "Frameworks");
|
||||
}
|
||||
piForeach(PIString & s, lib_dirs) {
|
||||
for (auto & s: lib_dirs) {
|
||||
s.trim();
|
||||
if (!s.endsWith("/")) s += "/";
|
||||
}
|
||||
@@ -669,7 +669,7 @@ int main(int argc, char * argv[]) {
|
||||
styles = cli.argumentValue("Styles").split(",");
|
||||
if (styles.isEmpty()) styles << "";
|
||||
PIStringList qpd = cli.argumentValue("qt-plugins").toLowerCase().split(DELIM).removeAll("");
|
||||
piForeachC(PIString & qp, qpd) {
|
||||
for (const auto & qp: qpd) {
|
||||
int _i = qp.find('=');
|
||||
if (_i < 0) continue;
|
||||
PIString pname = qp.left(_i).trim();
|
||||
@@ -739,7 +739,7 @@ int main(int argc, char * argv[]) {
|
||||
checkQtLib(f);
|
||||
});
|
||||
}
|
||||
piForeach(PIString & s, add_libs) {
|
||||
for (auto & s: add_libs) {
|
||||
if (s.isEmpty()) continue;
|
||||
PIString alib = findLib(s);
|
||||
if (alib.isEmpty()) continue;
|
||||
@@ -752,7 +752,7 @@ int main(int argc, char * argv[]) {
|
||||
if (is_deps) { // if Qt in system, then no plugins copy
|
||||
PIVector<PIString> qlibs = qt_libs.toVector();
|
||||
piCout << "check for installed Qt" << qlibs;
|
||||
piForeach(PIString l, qlibs) {
|
||||
for (const auto & l: qlibs) {
|
||||
if (procDpkg(l)) {
|
||||
piCout << "system Qt found!";
|
||||
need_qt_plugins = false;
|
||||
@@ -783,7 +783,7 @@ int main(int argc, char * argv[]) {
|
||||
out_dir.replaceAll("/", "\\");
|
||||
#endif
|
||||
PIVector<PIString> clibs = all_libs.toVector();
|
||||
piForeach(PIString l, clibs) {
|
||||
for (auto l: clibs) {
|
||||
PIFile::FileInfo fi;
|
||||
fi.path = l;
|
||||
#ifdef WINDOWS
|
||||
@@ -803,7 +803,7 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
}
|
||||
PIVector<PIString> fwdirs = frameworks.toVector();
|
||||
piForeachC(PIString & f, fwdirs) {
|
||||
for (const auto & f: fwdirs) {
|
||||
PIString fd = findLib(f);
|
||||
if (!fd.isEmpty()) {
|
||||
piCout << "copy framework" << f;
|
||||
|
||||
@@ -78,7 +78,7 @@ void Daemon::Remote::termTimerTick() {
|
||||
void Daemon::Remote::startAction(Daemon::PacketType a, const PIString & dir, const PIStringList & fl) {
|
||||
_fl = fl;
|
||||
if (!dir.isEmpty())
|
||||
piForeach(PIString & s, _fl)
|
||||
for (auto & s: _fl)
|
||||
s.prepend(dir);
|
||||
// piCout << "send" << _fl;
|
||||
action = a;
|
||||
@@ -122,7 +122,7 @@ void Daemon::Remote::updateDirEntries() {
|
||||
// piCout << dir_my;
|
||||
if (!dir_my.isExists()) dir_my = PIDir::current();
|
||||
my_filelist = dir_my.entries();
|
||||
piForeach(PIFile::FileInfo & f, my_filelist)
|
||||
for (auto & f: my_filelist)
|
||||
f.path = f.name();
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ Daemon::~Daemon() {
|
||||
dtimer.stopAndWait();
|
||||
requestCloseShell();
|
||||
PIVector<Remote *> rl = remotes.values();
|
||||
piForeach(Remote * r, rl) {
|
||||
for (auto * r: rl) {
|
||||
r->shellClose();
|
||||
delete r;
|
||||
}
|
||||
@@ -554,7 +554,7 @@ void Daemon::timerEvent(int delim) {
|
||||
screen->lock();
|
||||
list_daemons->content.clear();
|
||||
availableDaemons();
|
||||
piForeachC(PIString & i, available_daemons)
|
||||
for (const auto & i: available_daemons)
|
||||
list_daemons->content << TileList::Row(i, CellFormat());
|
||||
screen->unlock();
|
||||
if (delim == 5 && mode == rmInformation) {
|
||||
@@ -570,7 +570,7 @@ void Daemon::timerEvent(int delim) {
|
||||
PIStringList Daemon::availableDaemons() {
|
||||
available_daemons.clear();
|
||||
lock();
|
||||
piForeachC(PIPeer::PeerInfo & p, allPeers()) {
|
||||
for (const auto & p: allPeers()) {
|
||||
if (!p.name.startsWith(pisd_prefix)) continue;
|
||||
available_daemons << p.name.mid(6);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ PIStringList FileManager::TileDir::selectedNames() const {
|
||||
PIStringList ret;
|
||||
PIMutexLocker ml(e_mutex);
|
||||
PIVector<int> sind = selected.toVector();
|
||||
piForeachC(int i, sind)
|
||||
for (const auto i: sind)
|
||||
ret << entries[i].name();
|
||||
ret.removeOne("..");
|
||||
return ret;
|
||||
@@ -181,7 +181,7 @@ void FileManager::TileDir::buildNames() {
|
||||
CharFlags cf = 0;
|
||||
Color cc = Default;
|
||||
PIString fcol, scol;
|
||||
piForeachC(PIFile::FileInfo & e, entries) {
|
||||
for (const auto & e: entries) {
|
||||
if (e.isDir()) {
|
||||
t = '/';
|
||||
cf = Bold;
|
||||
@@ -258,7 +258,7 @@ FileManager::FileManager() {
|
||||
labels->direction = Horizontal;
|
||||
PIVector<SSPair> ll;
|
||||
ll << SSPair(" Esc", "Exit") << SSPair(" F5", "Copy") << SSPair(" F6", "Move") << SSPair(" F7", "MkDir") << SSPair(" F8", "Delete");
|
||||
piForeachC(SSPair & l, ll) {
|
||||
for (const auto & l: ll) {
|
||||
tl = new TileSimple();
|
||||
labels->addTile(tl);
|
||||
tl->content << TileSimple::Row(l.first, CellFormat(White, Transparent, Bold));
|
||||
@@ -315,7 +315,7 @@ PIStringList FileManager::selectedRemote() const {
|
||||
PIStringList ret;
|
||||
panels[1]->lock();
|
||||
PIVector<int> sil = panels[1]->selected.toVector();
|
||||
piForeachC(int i, sil)
|
||||
for (const auto i: sil)
|
||||
ret << panels[1]->entries[i].path;
|
||||
panels[1]->unlock();
|
||||
return ret;
|
||||
|
||||
@@ -197,7 +197,7 @@ public:
|
||||
// "]"
|
||||
,
|
||||
CellFormat());
|
||||
piForeachC(PIPeer::PeerInfo & p, daemon_.allPeers())
|
||||
for (const auto & p: daemon_.allPeers())
|
||||
peers_tl->content << TileList::Row(p.name + " | d = " + PIString::fromNumber(p.dist) + " | p = " +
|
||||
PIString::fromNumber(p.ping()) + " | n = " + PIString::fromBool(p.isNeighbour()),
|
||||
CellFormat());
|
||||
@@ -206,7 +206,7 @@ public:
|
||||
peerinfo_tl->content << TileSimple::Row("Name: " + pi.name, CellFormat());
|
||||
peerinfo_tl->content << TileSimple::Row("Addreses: " + PIString::fromNumber(pi.addresses.size()), CellFormat());
|
||||
peerinfo_tl->content << TileSimple::Row("Neighbours: " + pi.neighbours.join(", "), CellFormat());
|
||||
piForeachC(PIPeer::PeerInfo::PeerAddress & a, pi.addresses)
|
||||
for (const auto & a: pi.addresses)
|
||||
addrs_tl->content << TileList::Row(a.address.toString() + " | p = " + PIString::fromNumber(a.ping) +
|
||||
" | a = " + PIString::fromBool(a.isAvailable()),
|
||||
CellFormat());
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
s += " -> " + pp->name;
|
||||
peermap << s;
|
||||
}
|
||||
piForeachC(PIString & s, peermap)
|
||||
for (const auto & s: peermap)
|
||||
peermap_tl->content << TileList::Row(s, CellFormat());
|
||||
updatePeerDiag(peerdiagdata_tl, daemon_.diagnosticData());
|
||||
updatePeerDiag(peerdiagservice_tl, daemon_.diagnosticService());
|
||||
@@ -238,9 +238,9 @@ public:
|
||||
tile->content << TileList::Row("PID: " + PIString::fromNumber(sys_mon.statistic().ID), CellFormat());
|
||||
tile->content << TileList::Row(line, CellFormat());
|
||||
tile->content << TileList::Row("Threads:", CellFormat());
|
||||
piForeachC(PISystemMonitor::ThreadStats & t, ts)
|
||||
for (const auto & t: ts)
|
||||
maxlen = piMaxi(maxlen, t.name.length());
|
||||
piForeachC(PISystemMonitor::ThreadStats & t, ts) {
|
||||
for (const auto & t: ts) {
|
||||
line = PIString::fromNumber(++num).expandLeftTo(2, ' ') + ": ";
|
||||
line += PIString(t.name).expandRightTo(maxlen, ' ') + ": k ";
|
||||
PIString ns = PIString::fromNumber(t.cpu_load_kernel, 'f', 2);
|
||||
@@ -256,7 +256,7 @@ public:
|
||||
if (tinfo->visible) updateSysMon();
|
||||
}
|
||||
EVENT_HANDLER(void, menuRequest) {
|
||||
piForeach(PIScreenTile * t, mtiles)
|
||||
for (auto * t: mtiles)
|
||||
t->hide();
|
||||
daemon_.disconnect();
|
||||
tmenu->show();
|
||||
@@ -265,7 +265,7 @@ public:
|
||||
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e) {
|
||||
if (t == tmenu) {
|
||||
if (e.type == TileList::RowPressed) {
|
||||
piForeach(PIScreenTile * t, mtiles)
|
||||
for (auto * t: mtiles)
|
||||
t->hide();
|
||||
switch (e.data.toInt()) {
|
||||
case 0: tinfo->show(); break;
|
||||
|
||||
@@ -130,7 +130,7 @@ void removeFiles(const PIDir & dir, PIStringList l) {
|
||||
l.removeAll("..");
|
||||
PIString ap = dir.absolutePath();
|
||||
// piCout << "remove from" << ap;
|
||||
piForeachC(PIString & s, l) {
|
||||
for (const auto & s: l) {
|
||||
PIFile::FileInfo fi = PIFile::fileInfo(ap + PIDir::separator + s);
|
||||
if (fi.isDir()) {
|
||||
PIVector<PIFile::FileInfo> el = PIDir::allEntries(fi.path);
|
||||
@@ -149,7 +149,7 @@ bool cryptFiles(const PIDir & dir, PIStringList l, const PIByteArray & secret) {
|
||||
if (secret.size() != PICrypt::sizeKey() || secret.isEmpty()) return false;
|
||||
l.removeAll("..");
|
||||
PIString ap = dir.absolutePath();
|
||||
piForeachC(PIString & s, l) {
|
||||
for (const auto & s: l) {
|
||||
PIFile::FileInfo fi = PIFile::fileInfo(ap + PIDir::separator + s);
|
||||
if (fi.isDir()) {
|
||||
PIVector<PIFile::FileInfo> el = PIDir::allEntries(fi.path);
|
||||
|
||||
Reference in New Issue
Block a user