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:
2024-11-20 20:01:47 +03:00
parent 24112498ce
commit caa7880cc4
40 changed files with 415 additions and 320 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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;