Replace all uses of core::list with std::list (#12313)

master
paradust7 2022-05-21 15:11:59 -07:00 committed by GitHub
parent 2742fef458
commit 9f338f5a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 36 additions and 148 deletions

View File

@ -54,25 +54,10 @@ GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env,
#endif #endif
} }
GUIConfirmRegistration::~GUIConfirmRegistration()
{
removeChildren();
}
void GUIConfirmRegistration::removeChildren()
{
const core::list<gui::IGUIElement *> &children = getChildren();
core::list<gui::IGUIElement *> children_copy;
for (gui::IGUIElement *i : children)
children_copy.push_back(i);
for (gui::IGUIElement *i : children_copy)
i->remove();
}
void GUIConfirmRegistration::regenerateGui(v2u32 screensize) void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
{ {
acceptInput(); acceptInput();
removeChildren(); removeAllChildren();
/* /*
Calculate new sizes and positions Calculate new sizes and positions

View File

@ -34,9 +34,6 @@ public:
s32 id, IMenuManager *menumgr, Client *client, s32 id, IMenuManager *menumgr, Client *client,
const std::string &playername, const std::string &password, const std::string &playername, const std::string &password,
bool *aborted, ISimpleTextureSource *tsrc); bool *aborted, ISimpleTextureSource *tsrc);
~GUIConfirmRegistration();
void removeChildren();
/* /*
Remove and re-add (or reposition) stuff Remove and re-add (or reposition) stuff
*/ */

View File

@ -127,7 +127,8 @@ GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
GUIFormSpecMenu::~GUIFormSpecMenu() GUIFormSpecMenu::~GUIFormSpecMenu()
{ {
removeChildren(); removeAllChildren();
removeTooltip();
for (auto &table_it : m_tables) for (auto &table_it : m_tables)
table_it.second->drop(); table_it.second->drop();
@ -174,14 +175,8 @@ void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
} }
} }
void GUIFormSpecMenu::removeChildren() void GUIFormSpecMenu::removeTooltip()
{ {
const core::list<gui::IGUIElement*> &children = getChildren();
while (!children.empty()) {
(*children.getLast())->remove();
}
if (m_tooltip_element) { if (m_tooltip_element) {
m_tooltip_element->remove(); m_tooltip_element->remove();
m_tooltip_element->drop(); m_tooltip_element->drop();
@ -199,16 +194,7 @@ void GUIFormSpecMenu::setInitialFocus()
// 5. first focusable (not statictext, not tabheader) // 5. first focusable (not statictext, not tabheader)
// 6. first child element // 6. first child element
core::list<gui::IGUIElement*> children = getChildren(); const auto& children = getChildren();
// in case "children" contains any NULL elements, remove them
for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
it != children.end();) {
if (*it)
++it;
else
it = children.erase(it);
}
// 1. first empty editbox // 1. first empty editbox
for (gui::IGUIElement *it : children) { for (gui::IGUIElement *it : children) {
@ -236,8 +222,7 @@ void GUIFormSpecMenu::setInitialFocus()
} }
// 4. last button // 4. last button
for (core::list<gui::IGUIElement*>::Iterator it = children.getLast(); for (auto it = children.rbegin(); it != children.rend(); ++it) {
it != children.end(); --it) {
if ((*it)->getType() == gui::EGUIET_BUTTON) { if ((*it)->getType() == gui::EGUIET_BUTTON) {
Environment->setFocus(*it); Environment->setFocus(*it);
return; return;
@ -257,7 +242,7 @@ void GUIFormSpecMenu::setInitialFocus()
if (children.empty()) if (children.empty())
Environment->setFocus(this); Environment->setFocus(this);
else else
Environment->setFocus(*(children.begin())); Environment->setFocus(children.front());
} }
GUITable* GUIFormSpecMenu::getTable(const std::string &tablename) GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
@ -3045,7 +3030,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
} }
// Remove children // Remove children
removeChildren(); removeAllChildren();
removeTooltip();
for (auto &table_it : m_tables) for (auto &table_it : m_tables)
table_it.second->drop(); table_it.second->drop();
@ -3341,7 +3327,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
pos_offset = v2f32(); pos_offset = v2f32();
// used for formspec versions < 3 // used for formspec versions < 3
core::list<IGUIElement *>::Iterator legacy_sort_start = Children.getLast(); std::list<IGUIElement *>::iterator legacy_sort_start = std::prev(Children.end()); // last element
if (enable_prepends) { if (enable_prepends) {
// Backup the coordinates so that prepends can use the coordinates of choice. // Backup the coordinates so that prepends can use the coordinates of choice.
@ -3356,7 +3342,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
// legacy sorting for formspec versions < 3 // legacy sorting for formspec versions < 3
if (m_formspec_version >= 3) if (m_formspec_version >= 3)
// prepends do not need to be reordered // prepends do not need to be reordered
legacy_sort_start = Children.getLast(); legacy_sort_start = std::prev(Children.end()); // last element
else if (version_backup >= 3) else if (version_backup >= 3)
// only prepends elements have to be reordered // only prepends elements have to be reordered
legacySortElements(legacy_sort_start); legacySortElements(legacy_sort_start);
@ -3437,7 +3423,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
} }
} }
void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator from) void GUIFormSpecMenu::legacySortElements(std::list<IGUIElement *>::iterator from)
{ {
/* /*
Draw order for formspec_version <= 2: Draw order for formspec_version <= 2:
@ -3454,17 +3440,16 @@ void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator fro
if (from == Children.end()) if (from == Children.end())
from = Children.begin(); from = Children.begin();
else else
from++; ++from;
core::list<IGUIElement *>::Iterator to = Children.end(); std::list<IGUIElement *>::iterator to = Children.end();
// 1: Copy into a sortable container // 1: Copy into a sortable container
std::vector<IGUIElement *> elements; std::vector<IGUIElement *> elements(from, to);
for (auto it = from; it != to; ++it)
elements.emplace_back(*it);
// 2: Sort the container // 2: Sort the container
std::stable_sort(elements.begin(), elements.end(), std::stable_sort(elements.begin(), elements.end(),
[this] (const IGUIElement *a, const IGUIElement *b) -> bool { [this] (const IGUIElement *a, const IGUIElement *b) -> bool {
// TODO: getSpecByID is a linear search. It should made O(1), or cached here.
const FieldSpec *spec_a = getSpecByID(a->getID()); const FieldSpec *spec_a = getSpecByID(a->getID());
const FieldSpec *spec_b = getSpecByID(b->getID()); const FieldSpec *spec_b = getSpecByID(b->getID());
return spec_a && spec_b && return spec_a && spec_b &&
@ -3472,10 +3457,7 @@ void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator fro
}); });
// 3: Re-assign the pointers // 3: Re-assign the pointers
for (auto e : elements) { reorderChildren(from, to, elements);
*from = e;
from++;
}
} }
#ifdef __ANDROID__ #ifdef __ANDROID__
@ -3600,12 +3582,11 @@ void GUIFormSpecMenu::drawMenu()
/* /*
This is where all the drawing happens. This is where all the drawing happens.
*/ */
core::list<IGUIElement*>::Iterator it = Children.begin(); for (auto child : Children)
for (; it != Children.end(); ++it) if (child->isNotClipped() ||
if ((*it)->isNotClipped() ||
AbsoluteClippingRect.isRectCollided( AbsoluteClippingRect.isRectCollided(
(*it)->getAbsolutePosition())) child->getAbsolutePosition()))
(*it)->draw(); child->draw();
for (gui::IGUIElement *e : m_clickthrough_elements) for (gui::IGUIElement *e : m_clickthrough_elements)
e->setVisible(false); e->setVisible(false);

View File

@ -212,7 +212,7 @@ public:
m_lockscreensize = basescreensize; m_lockscreensize = basescreensize;
} }
void removeChildren(); void removeTooltip();
void setInitialFocus(); void setInitialFocus();
void setFocus(const std::string &elementname) void setFocus(const std::string &elementname)
@ -467,7 +467,7 @@ private:
* types were drawn before others. * types were drawn before others.
* This function sorts the elements in the old order for backwards compatibility. * This function sorts the elements in the old order for backwards compatibility.
*/ */
void legacySortElements(core::list<IGUIElement *>::Iterator from); void legacySortElements(std::list<IGUIElement *>::iterator from);
int m_btn_height; int m_btn_height;
gui::IGUIFont *m_font = nullptr; gui::IGUIFont *m_font = nullptr;

View File

@ -93,7 +93,8 @@ GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
GUIKeyChangeMenu::~GUIKeyChangeMenu() GUIKeyChangeMenu::~GUIKeyChangeMenu()
{ {
removeChildren(); removeAllChildren();
key_used_text = nullptr;
for (key_setting *ks : key_settings) { for (key_setting *ks : key_settings) {
delete[] ks->button_name; delete[] ks->button_name;
@ -102,23 +103,10 @@ GUIKeyChangeMenu::~GUIKeyChangeMenu()
key_settings.clear(); key_settings.clear();
} }
void GUIKeyChangeMenu::removeChildren()
{
const core::list<gui::IGUIElement*> &children = getChildren();
core::list<gui::IGUIElement*> children_copy;
for (gui::IGUIElement*i : children) {
children_copy.push_back(i);
}
for (gui::IGUIElement *i : children_copy) {
i->remove();
}
key_used_text = nullptr;
}
void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
{ {
removeChildren(); removeAllChildren();
key_used_text = nullptr;
const float s = m_gui_scale; const float s = m_gui_scale;
DesiredRect = core::rect<s32>( DesiredRect = core::rect<s32>(

View File

@ -46,7 +46,6 @@ public:
IMenuManager *menumgr, ISimpleTextureSource *tsrc); IMenuManager *menumgr, ISimpleTextureSource *tsrc);
~GUIKeyChangeMenu(); ~GUIKeyChangeMenu();
void removeChildren();
/* /*
Remove and re-add (or reposition) stuff Remove and re-add (or reposition) stuff
*/ */

View File

@ -51,23 +51,6 @@ GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
{ {
} }
GUIPasswordChange::~GUIPasswordChange()
{
removeChildren();
}
void GUIPasswordChange::removeChildren()
{
const core::list<gui::IGUIElement *> &children = getChildren();
core::list<gui::IGUIElement *> children_copy;
for (gui::IGUIElement *i : children) {
children_copy.push_back(i);
}
for (gui::IGUIElement *i : children_copy) {
i->remove();
}
}
void GUIPasswordChange::regenerateGui(v2u32 screensize) void GUIPasswordChange::regenerateGui(v2u32 screensize)
{ {
/* /*
@ -78,7 +61,7 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
/* /*
Remove stuff Remove stuff
*/ */
removeChildren(); removeAllChildren();
/* /*
Calculate new sizes and positions Calculate new sizes and positions

View File

@ -31,9 +31,7 @@ public:
GUIPasswordChange(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, GUIPasswordChange(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
IMenuManager *menumgr, Client *client, IMenuManager *menumgr, Client *client,
ISimpleTextureSource *tsrc); ISimpleTextureSource *tsrc);
~GUIPasswordChange();
void removeChildren();
/* /*
Remove and re-add (or reposition) stuff Remove and re-add (or reposition) stuff
*/ */

View File

@ -32,13 +32,12 @@ GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env,
GUIFileSelectMenu::~GUIFileSelectMenu() GUIFileSelectMenu::~GUIFileSelectMenu()
{ {
removeChildren();
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
} }
void GUIFileSelectMenu::regenerateGui(v2u32 screensize) void GUIFileSelectMenu::regenerateGui(v2u32 screensize)
{ {
removeChildren(); removeAllChildren();
m_fileOpenDialog = 0; m_fileOpenDialog = 0;
core::dimension2du size(600 * m_gui_scale, 400 * m_gui_scale); core::dimension2du size(600 * m_gui_scale, 400 * m_gui_scale);

View File

@ -59,12 +59,11 @@ bool GUIScrollContainer::OnEvent(const SEvent &event)
void GUIScrollContainer::draw() void GUIScrollContainer::draw()
{ {
if (isVisible()) { if (isVisible()) {
core::list<IGUIElement *>::Iterator it = Children.begin(); for (auto child : Children)
for (; it != Children.end(); ++it) if (child->isNotClipped() ||
if ((*it)->isNotClipped() ||
AbsoluteClippingRect.isRectCollided( AbsoluteClippingRect.isRectCollided(
(*it)->getAbsolutePosition())) child->getAbsolutePosition()))
(*it)->draw(); child->draw();
} }
} }

View File

@ -45,32 +45,12 @@ GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
{ {
} }
GUIVolumeChange::~GUIVolumeChange()
{
removeChildren();
}
void GUIVolumeChange::removeChildren()
{
if (gui::IGUIElement *e = getElementFromId(ID_soundText))
e->remove();
if (gui::IGUIElement *e = getElementFromId(ID_soundExitButton))
e->remove();
if (gui::IGUIElement *e = getElementFromId(ID_soundSlider))
e->remove();
if (gui::IGUIElement *e = getElementFromId(ID_soundMuteButton))
e->remove();
}
void GUIVolumeChange::regenerateGui(v2u32 screensize) void GUIVolumeChange::regenerateGui(v2u32 screensize)
{ {
/* /*
Remove stuff Remove stuff
*/ */
removeChildren(); removeAllChildren();
/* /*
Calculate new sizes and positions Calculate new sizes and positions
*/ */

View File

@ -31,9 +31,6 @@ public:
GUIVolumeChange(gui::IGUIEnvironment* env, GUIVolumeChange(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id, gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr, ISimpleTextureSource *tsrc); IMenuManager *menumgr, ISimpleTextureSource *tsrc);
~GUIVolumeChange();
void removeChildren();
/* /*
Remove and re-add (or reposition) stuff Remove and re-add (or reposition) stuff
*/ */

View File

@ -64,10 +64,6 @@ public:
// Remove all entries if there are duplicates // Remove all entries if there are duplicates
m_stack.remove(menu); m_stack.remove(menu);
/*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
assert(*i == menu);
m_stack.erase(i);*/
if(!m_stack.empty()) if(!m_stack.empty())
m_stack.back()->setVisible(true); m_stack.back()->setVisible(true);
} }

View File

@ -108,19 +108,6 @@ void GUIModalMenu::quitMenu()
#endif #endif
} }
void GUIModalMenu::removeChildren()
{
const core::list<gui::IGUIElement *> &children = getChildren();
core::list<gui::IGUIElement *> children_copy;
for (gui::IGUIElement *i : children) {
children_copy.push_back(i);
}
for (gui::IGUIElement *i : children_copy) {
i->remove();
}
}
// clang-format off // clang-format off
bool GUIModalMenu::DoubleClickDetection(const SEvent &event) bool GUIModalMenu::DoubleClickDetection(const SEvent &event)
{ {

View File

@ -47,7 +47,6 @@ public:
bool canTakeFocus(gui::IGUIElement *e); bool canTakeFocus(gui::IGUIElement *e);
void draw(); void draw();
void quitMenu(); void quitMenu();
void removeChildren();
virtual void regenerateGui(v2u32 screensize) = 0; virtual void regenerateGui(v2u32 screensize) = 0;
virtual void drawMenu() = 0; virtual void drawMenu() = 0;

View File

@ -360,7 +360,7 @@ struct TestMapBlock: public TestBase
MapNode node; MapNode node;
bool position_valid; bool position_valid;
core::list<v3s16> validity_exceptions; std::list<v3s16> validity_exceptions;
TC() TC()
{ {
@ -371,7 +371,7 @@ struct TestMapBlock: public TestBase
{ {
//return position_valid ^ (p==position_valid_exception); //return position_valid ^ (p==position_valid_exception);
bool exception = false; bool exception = false;
for(core::list<v3s16>::Iterator i=validity_exceptions.begin(); for(std::list<v3s16>::iterator i=validity_exceptions.begin();
i != validity_exceptions.end(); i++) i != validity_exceptions.end(); i++)
{ {
if(p == *i) if(p == *i)