From: Mikko Rasa Date: Sun, 20 Aug 2023 21:06:05 +0000 (+0300) Subject: Convert all list containers to vectors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=762a689d799075c0a10e1633bf95d53de80b4572;p=libs%2Fgltk.git Convert all list containers to vectors --- diff --git a/source/arrangement.h b/source/arrangement.h index 4a651ba..26e28a6 100644 --- a/source/arrangement.h +++ b/source/arrangement.h @@ -1,8 +1,8 @@ #ifndef MSP_GLTK_ARRANGEMENT_H_ #define MSP_GLTK_ARRANGEMENT_H_ -#include #include +#include #include #include "layout.h" #include "mspgltk_api.h" @@ -31,7 +31,7 @@ protected: struct Edge { - std::list widgets; + std::vector widgets; bool aligned = false; bool empty() { return widgets.empty(); } diff --git a/source/container.cpp b/source/container.cpp index 9ef46f1..64e3a9a 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -80,9 +80,9 @@ void Container::reposition_child(Widget &child, const Part &part) const child.set_geometry(determine_child_geometry(child, part)); } -list Container::get_children() const +vector Container::get_children() const { - list result; + vector result; for(const Child *c: children) result.push_back(c->widget); return result; @@ -116,7 +116,9 @@ void Container::raise(Widget &wdg) if(i==children.end()) throw hierarchy_error("widget not in container"); - children.splice(children.end(), children, i); + Child *c = *i; + children.erase(i); + children.push_back(c); } void Container::set_pointer_focus(Widget *wdg, bool grab) diff --git a/source/container.h b/source/container.h index b2f69d3..40fe4dc 100644 --- a/source/container.h +++ b/source/container.h @@ -1,8 +1,8 @@ #ifndef MSP_GLTK_CONTAINER_H_ #define MSP_GLTK_CONTAINER_H_ -#include #include +#include #include #include "mspgltk_api.h" #include "widget.h" @@ -37,7 +37,7 @@ protected: void rebuild_needed(); }; - std::list children; + std::vector children; Widget *click_focus = nullptr; unsigned click_button = 0; Widget *pointer_focus = nullptr; @@ -59,7 +59,7 @@ protected: void autosize_child(const Widget &, const Part &, Geometry &) const; void reposition_child(Widget &, const Part &) const; public: - std::list get_children() const; + std::vector get_children() const; Widget *find_child_at(int, int) const; Widget *find_descendant_at(int, int) const; void raise(Widget &); diff --git a/source/layout.cpp b/source/layout.cpp index 7fcbf10..4d6b664 100644 --- a/source/layout.cpp +++ b/source/layout.cpp @@ -182,8 +182,8 @@ void Layout::remove_widget(Widget &wdg) { for(auto k=s->constraints.begin(); k!=s->constraints.end(); ) { - if(&k->target==*i) - s->constraints.erase(k++); + if(k->target==*i) + k = s->constraints.erase(k); else ++k; } @@ -225,7 +225,7 @@ void Layout::update_slot_indices() } for(const Constraint &c: s->constraints) - if(c.target.index>s->index && (c.type&SLACK)) + if(c.target->index>s->index && (c.type&SLACK)) ++n_slack_vars[c.type&1]; } } @@ -253,7 +253,7 @@ void Layout::create_constraint(Widget &src, ConstraintType type, Widget &tgt, in Slot &tgt_slot = get_slot_for_widget(tgt); for(const Constraint &c: src_slot.constraints) - if(c.type==type && &c.target==&tgt_slot) + if(c.type==type && c.target==&tgt_slot) return; src_slot.constraints.push_back(Constraint(type, tgt_slot)); @@ -423,7 +423,7 @@ void Layout::solve_constraints(int dir, SolveMode mode) /* Add rows for user-defined constraints. Constraints are always added in pairs, so it's only necessary to create a row for one half. */ for(const Constraint &c: s->constraints) - if(c.target.index>s->index && (c.type&1)==dir) + if(c.target->index>s->index && (c.type&1)==dir) { LinearProgram::Row row = linprog.add_row(); float polarity = ((c.type&SELF_DIM) ? -1 : 1); @@ -433,9 +433,9 @@ void Layout::solve_constraints(int dir, SolveMode mode) if(c.type&SELF_DIM) row[s->index*5+1] = polarity*dim_weight; if(c.type&TARGET_POS) - row[c.target.index*5] = -polarity; + row[c.target->index*5] = -polarity; if(c.type&TARGET_DIM) - row[c.target.index*5+1] = -polarity*dim_weight; + row[c.target->index*5+1] = -polarity*dim_weight; if(c.type&SPACING) row.back() = (c.spacing>=0 ? c.spacing : this->*(ptrs.spacing)); if(c.type&SLACK) @@ -470,7 +470,7 @@ void Layout::solve_constraints(int dir, SolveMode mode) Layout::Constraint::Constraint(ConstraintType t, Slot &s): type(t), - target(s) + target(&s) { } diff --git a/source/layout.h b/source/layout.h index aa11e96..14def25 100644 --- a/source/layout.h +++ b/source/layout.h @@ -1,8 +1,8 @@ #ifndef MSP_GLTK_LAYOUT_H_ #define MSP_GLTK_LAYOUT_H_ -#include #include +#include #include #include #include "geometry.h" @@ -132,7 +132,7 @@ private: struct Constraint { ConstraintType type; - Slot ⌖ + Slot *target = nullptr; int spacing = -1; Constraint(ConstraintType, Slot &); @@ -151,7 +151,7 @@ private: Widget &widget; Geometry autosize_geom; Geometry geom; - std::list constraints; + std::vector constraints; Packing horiz_pack; Packing vert_pack; bool ghost = false; @@ -173,14 +173,14 @@ private: struct Pointers; Container *container = nullptr; - std::list slots; + std::vector slots; unsigned n_active_slots = 0; unsigned n_slack_vars[2] = { 0, 0 }; Sides margin{ 8 }; unsigned row_spacing = 5; unsigned col_spacing = 4; Geometry autosize_geom; - std::list arrangement_stack; + std::vector arrangement_stack; static Pointers pointers[2]; diff --git a/source/partcache.h b/source/partcache.h index 8099676..7168473 100644 --- a/source/partcache.h +++ b/source/partcache.h @@ -35,13 +35,11 @@ public: ~Rebuild() { cache.end_rebuild(); } }; - typedef std::list PartList; - private: bool rebuilding = false; - PartList parts; - PartList::iterator next; - PartList::iterator current; + std::vector parts; + std::vector::iterator next; + std::vector::iterator current; public: void begin_rebuild(); @@ -49,7 +47,7 @@ public: GL::Mesh &create_mesh(const Part &, const GL::Texture2D &); void end_rebuild(); - const PartList &get_parts() const { return parts; } + const std::vector &get_parts() const { return parts; } }; } // namespace GLtk diff --git a/source/style.h b/source/style.h index 2c4863a..62a4511 100644 --- a/source/style.h +++ b/source/style.h @@ -33,21 +33,19 @@ public: void unnamed_part(); }; - typedef std::list PartSeq; - private: const GL::Font *font = nullptr; unsigned font_size = 0; GL::Color font_color[N_STATES_]; const GL::Sampler *sampler = nullptr; - PartSeq parts; + std::vector parts; public: const GL::Font &get_font() const; unsigned get_font_size() const { return font_size; } const GL::Color &get_font_color(State) const; const GL::Sampler &get_sampler() const; - const PartSeq &get_parts() const { return parts; } + const std::vector &get_parts() const { return parts; } const Part *find_part(const std::string &) const; bool compare_states(State, State) const; };