]> git.tdb.fi Git - libs/gltk.git/commitdiff
Convert all list containers to vectors
authorMikko Rasa <tdb@tdb.fi>
Sun, 20 Aug 2023 21:06:05 +0000 (00:06 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 21 Aug 2023 12:36:15 +0000 (15:36 +0300)
source/arrangement.h
source/container.cpp
source/container.h
source/layout.cpp
source/layout.h
source/partcache.h
source/style.h

index 4a651bac864a189cbb8c2942e35390939c2bff38..26e28a6f10f4967b45b480a8bd76005e84672f22 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef MSP_GLTK_ARRANGEMENT_H_
 #define MSP_GLTK_ARRANGEMENT_H_
 
-#include <list>
 #include <stdexcept>
+#include <vector>
 #include <msp/core/noncopyable.h>
 #include "layout.h"
 #include "mspgltk_api.h"
@@ -31,7 +31,7 @@ protected:
 
        struct Edge
        {
-               std::list<Widget *> widgets;
+               std::vector<Widget *> widgets;
                bool aligned = false;
 
                bool empty() { return widgets.empty(); }
index 9ef46f1ab85fcd511238ecb83f3f45cf912b7caa..64e3a9a7e296ce374819abddc035112a18948e53 100644 (file)
@@ -80,9 +80,9 @@ void Container::reposition_child(Widget &child, const Part &part) const
        child.set_geometry(determine_child_geometry(child, part));
 }
 
-list<Widget *> Container::get_children() const
+vector<Widget *> Container::get_children() const
 {
-       list<Widget *> result;
+       vector<Widget *> 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)
index b2f69d3bb2eae41cf35183d04f8cc5f1b47531ef..40fe4dc60d4855e44a890af8a4230b9ab764c3b7 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef MSP_GLTK_CONTAINER_H_
 #define MSP_GLTK_CONTAINER_H_
 
-#include <list>
 #include <stdexcept>
+#include <vector>
 #include <sigc++/trackable.h>
 #include "mspgltk_api.h"
 #include "widget.h"
@@ -37,7 +37,7 @@ protected:
                void rebuild_needed();
        };
 
-       std::list<Child *> children;
+       std::vector<Child *> 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<Widget *> get_children() const;
+       std::vector<Widget *> get_children() const;
        Widget *find_child_at(int, int) const;
        Widget *find_descendant_at(int, int) const;
        void raise(Widget &);
index 7fcbf103b085808fe34fa0d45f67b54fd5442251..4d6b6643a3c630bb99e5c54a25c02e5eb30fff9d 100644 (file)
@@ -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)
 { }
 
 
index aa11e965bf19cbc042b968c65d38506686625f27..14def25e718bc83e00f28d975ad4b08ba7945c29 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef MSP_GLTK_LAYOUT_H_
 #define MSP_GLTK_LAYOUT_H_
 
-#include <list>
 #include <set>
+#include <vector>
 #include <sigc++/trackable.h>
 #include <msp/strings/lexicalcast.h>
 #include "geometry.h"
@@ -132,7 +132,7 @@ private:
        struct Constraint
        {
                ConstraintType type;
-               Slot &target;
+               Slot *target = nullptr;
                int spacing = -1;
 
                Constraint(ConstraintType, Slot &);
@@ -151,7 +151,7 @@ private:
                Widget &widget;
                Geometry autosize_geom;
                Geometry geom;
-               std::list<Constraint> constraints;
+               std::vector<Constraint> constraints;
                Packing horiz_pack;
                Packing vert_pack;
                bool ghost = false;
@@ -173,14 +173,14 @@ private:
        struct Pointers;
 
        Container *container = nullptr;
-       std::list<Slot *> slots;
+       std::vector<Slot *> 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 *> arrangement_stack;
+       std::vector<Arrangement *> arrangement_stack;
 
        static Pointers pointers[2];
 
index 8099676f95d177ecc3855bf00006db2a3aa11263..71684738f0980922de8db5346d88249f53a058b5 100644 (file)
@@ -35,13 +35,11 @@ public:
                ~Rebuild() { cache.end_rebuild(); }
        };
 
-       typedef std::list<CachedPart> PartList;
-
 private:
        bool rebuilding = false;
-       PartList parts;
-       PartList::iterator next;
-       PartList::iterator current;
+       std::vector<CachedPart> parts;
+       std::vector<CachedPart>::iterator next;
+       std::vector<CachedPart>::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<CachedPart> &get_parts() const { return parts; }
 };
 
 } // namespace GLtk
index 2c4863ac4a340e627ecd1984c9ba79f6f5cde956..62a451100e7f21391240fcb647924be539d9a88d 100644 (file)
@@ -33,21 +33,19 @@ public:
                void unnamed_part();
        };
 
-       typedef std::list<Part> 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<Part> 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<Part> &get_parts() const { return parts; }
        const Part *find_part(const std::string &) const;
        bool compare_states(State, State) const;
 };