]> git.tdb.fi Git - libs/datafile.git/commitdiff
Change most remaining uses of std::list to std::vector
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 May 2024 09:52:53 +0000 (12:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 May 2024 09:52:53 +0000 (12:52 +0300)
source/builtinsource.cpp
source/builtinsource.h
source/collection.cpp
source/collection.h
source/collectionsource.h
source/directorysource.cpp
source/directorysource.h
source/packsource.cpp
source/packsource.h
tool/tool.cpp

index 836d15d92f45b9218601faebb9be8f78af71c4ce..64fb28d47d616475340328787d8a60f8bd787080 100644 (file)
@@ -23,9 +23,9 @@ bool BuiltinSource::is_loadable(const CollectionItemTypeBase &, const string &na
        return objects.count(name);
 }
 
-CollectionSource::NameList BuiltinSource::get_names(const CollectionItemTypeBase &type) const
+vector<string> BuiltinSource::get_names(const CollectionItemTypeBase &type) const
 {
-       NameList names;
+       vector<string> names;
        for(const auto &kvp: objects)
                if(type.match_name(kvp.first))
                        names.push_back(kvp.first);
index 1a78b14b1c8f297895f816046d68fadc9d30ab72..cbb044e6f52d5cca97f767275148af89c256ca67 100644 (file)
@@ -26,7 +26,7 @@ public:
        void add_object(const std::string &, const char *);
 
        bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override;
-       NameList get_names(const CollectionItemTypeBase &) const override;
+       std::vector<std::string> get_names(const CollectionItemTypeBase &) const override;
        void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override;
        std::unique_ptr<IO::Seekable> open(const std::string &) const override;
 };
index 6e857b5c38a0f0b6bcce45f58fc3e2f1fd6fe6f5..7243c5d77566f567478c05a3cf709d47dbe78873 100644 (file)
@@ -60,7 +60,7 @@ const Variant *Collection::find_var(const string &name, const CollectionItemType
        return (i!=items.end() ? &i->second : nullptr);
 }
 
-void Collection::gather_items(vector<const Variant *> *vars, list<string> *names, const CollectionItemTypeBase &type, bool include_sources) const
+void Collection::gather_items(vector<const Variant *> *vars, vector<string> *names, const CollectionItemTypeBase &type, bool include_sources) const
 {
        for(const auto &kvp: items)
                if(type.check_item_type(kvp.second))
@@ -122,7 +122,7 @@ unique_ptr<IO::Seekable> Collection::open_raw(const string &name) const
        return nullptr;
 }
 
-void Collection::gather_names_from_sources(list<string> &names, const CollectionItemTypeBase &type) const
+void Collection::gather_names_from_sources(vector<string> &names, const CollectionItemTypeBase &type) const
 {
        set<string> new_names;
        for(const CollectionSource *s: sources)
index bc2a591e3be356bb74a01a36c41d6127a5714f59..ae6ec308b6b6c7dd4ebe88ab7a18c25078b0efc3 100644 (file)
@@ -144,18 +144,18 @@ private:
        T &extract(const Variant &var) const;
 
        template<typename T>
-       std::list<T *> extract_list(const std::vector<const Variant *> &vars) const
+       std::vector<T *> extract_list(const std::vector<const Variant *> &vars) const
        {
-               std::list<T *> result;
+               std::vector<T *> result;
                for(const Variant *v: vars)
                        result.push_back(&extract<T>(*v));
                return result;
        }
 
-       void gather_items(std::vector<const Variant *> *, std::list<std::string> *, const CollectionItemTypeBase &, bool) const;
+       void gather_items(std::vector<const Variant *> *, std::vector<std::string> *, const CollectionItemTypeBase &, bool) const;
 
        template<typename T>
-       void gather_items(std::vector<const Variant *> *vars, std::list<std::string> *names, const CollectionItemTypeBase *type, bool include_sources) const
+       void gather_items(std::vector<const Variant *> *vars, std::vector<std::string> *names, const CollectionItemTypeBase *type, bool include_sources) const
        {
                if(type || (type = get_type<T>()))
                        gather_items(vars, names, *type, include_sources);
@@ -166,9 +166,9 @@ private:
 public:
        /// Returns a list of the names of objects of one type in the collection.
        template<typename T>
-       std::list<std::string> get_names() const
+       std::vector<std::string> get_names() const
        {
-               std::list<std::string> names;
+               std::vector<std::string> names;
                gather_items<typename std::remove_cv<T>::type>(0, &names, 0, false);
                return names;
        }
@@ -176,16 +176,16 @@ public:
        /** Returns a list of the names of objects of one type in the collection or
        available from sources. */
        template<typename T>
-       std::list<std::string> get_names()
+       std::vector<std::string> get_names()
        {
-               std::list<std::string> names;
+               std::vector<std::string> names;
                gather_items<typename std::remove_cv<T>::type>(0, &names, 0, true);
                return names;
        }
 
        /// Returns a list of objects of one type in the collection.
        template<typename T>
-       std::list<T *> get_list() const
+       std::vector<T *> get_all() const
        {
                std::vector<const Variant *> vars;
                gather_items<typename std::remove_cv<T>::type>(&vars, 0, 0, false);
@@ -195,7 +195,7 @@ public:
        /** Returns a list of objects of one type, loading them from sources if
        necessary. */
        template<typename T>
-       std::list<T *> get_list()
+       std::vector<T *> get_all()
        {
                CollectionItemTypeBase *type = get_type<typename std::remove_cv<T>::type>();
                if(type)
@@ -282,7 +282,7 @@ public:
        std::unique_ptr<IO::Seekable> open_raw(const std::string &) const;
 
 private:
-       void gather_names_from_sources(std::list<std::string> &, const CollectionItemTypeBase &) const;
+       void gather_names_from_sources(std::vector<std::string> &, const CollectionItemTypeBase &) const;
 
        void load_items_from_sources(const CollectionItemTypeBase &);
 
index 10f71baa41e48d3adce1c080141ebaa36db740ac..8af70b43779bb6ecf4271c1143f5708e95ba6286 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef COLLECTIONSOURCE_H_
 #define COLLECTIONSOURCE_H_
 
-#include <list>
 #include <memory>
 #include <string>
+#include <vector>
 #include <msp/io/seekable.h>
 #include "mspdatafile_api.h"
 
@@ -19,9 +19,6 @@ see DirectorySource and PackSource for concrete classes.
 */
 class MSPDATAFILE_API CollectionSource
 {
-public:
-       using NameList = std::list<std::string>;
-
 protected:
        CollectionSource() = default;
 public:
@@ -32,7 +29,7 @@ public:
 
        /** Returns the names of available objects of a specific type.  Implementors
        should use type.match_name to check which names are acceptable. */
-       virtual NameList get_names(const CollectionItemTypeBase &type) const = 0;
+       virtual std::vector<std::string> get_names(const CollectionItemTypeBase &type) const = 0;
 
        /// Loads an item into a collection.
        virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const = 0;
index d57397a186109b2f1575af54f0cb4315728e1eab..6defe25579c8548c140511ad908288add19655d1 100644 (file)
@@ -20,9 +20,9 @@ bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &
        return objects.count(name);
 }
 
-CollectionSource::NameList DirectorySource::get_names(const CollectionItemTypeBase &type) const
+vector<string> DirectorySource::get_names(const CollectionItemTypeBase &type) const
 {
-       NameList names;
+       vector<string> names;
        for(const auto &kvp: objects)
                if(type.match_name(kvp.first))
                        names.push_back(kvp.first);
index 7e2066b6e0fd41613d238306b46fa04ad9299d35..11bdd3be7139a85fc16575c22a4cf7a4e8f3a8db 100644 (file)
@@ -22,7 +22,7 @@ public:
        void add_directory(const FS::Path &, bool = true);
 
        bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override;
-       NameList get_names(const CollectionItemTypeBase &) const override;
+       std::vector<std::string> get_names(const CollectionItemTypeBase &) const override;
        void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override;
        std::unique_ptr<IO::Seekable> open(const std::string &) const override;
 
index dcbc7d7c08aa2bfe0169607570d3c2886b72c359..608709245732f1fc4c1c8a01bfcace86e547737c 100644 (file)
@@ -65,9 +65,10 @@ void PackSource::add_pack(IO::Seekable *io, const string &fn, const string &filt
        }
 }
 
-list<PackSource::FileInfo> PackSource::list_files() const
+vector<PackSource::FileInfo> PackSource::list_files() const
 {
-       list<FileInfo> result;
+       vector<FileInfo> result;
+       result.reserve(files.size());
        for(const auto &kvp: files)
                result.push_back(kvp.second->get_info());
        return result;
@@ -86,9 +87,9 @@ bool PackSource::is_loadable(const CollectionItemTypeBase &type, const string &n
        return true;
 }
 
-CollectionSource::NameList PackSource::get_names(const CollectionItemTypeBase &type) const
+vector<string> PackSource::get_names(const CollectionItemTypeBase &type) const
 {
-       NameList names;
+       vector<string> names;
        for(const auto &kvp: objects)
        {
                if(!kvp.second->get_keyword().empty())
index d7bec4a46feaee36700cf46dfdce06009aa9cc84..7fa1125c6dde97bfb7478137ae2a81dde553fe5f 100644 (file)
@@ -141,10 +141,10 @@ private:
 
 public:
        /// Returns information about the files in the pack.
-       std::list<FileInfo> list_files() const;
+       std::vector<FileInfo> list_files() const;
 
        bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override;
-       NameList get_names(const CollectionItemTypeBase &) const override;
+       std::vector<std::string> get_names(const CollectionItemTypeBase &) const override;
        void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override;
        std::unique_ptr<IO::Seekable> open(const std::string &) const override;
 };
index a6b094475946cc9e6b56759c5c9c473f0df30711..a88829fa7cffc550da4d180c44da4079a5134876 100644 (file)
@@ -119,8 +119,8 @@ void DataTool::do_unpack()
        for(list<string>::const_iterator i=in_fns.begin(); i!=in_fns.end(); ++i)
                source.add_pack_file(*i);
 
-       list<DataFile::PackSource::FileInfo> files = source.list_files();
-       for(list<DataFile::PackSource::FileInfo>::const_iterator i=files.begin(); i!=files.end(); ++i)
+       vector<DataFile::PackSource::FileInfo> files = source.list_files();
+       for(vector<DataFile::PackSource::FileInfo>::const_iterator i=files.begin(); i!=files.end(); ++i)
        {
                unique_ptr<IO::Seekable> in = source.open(i->name);
                unique_ptr<IO::Base> out = open_output(i->name);