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);
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;
};
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))
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)
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);
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;
}
/** 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);
/** 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)
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 &);
#ifndef COLLECTIONSOURCE_H_
#define COLLECTIONSOURCE_H_
-#include <list>
#include <memory>
#include <string>
+#include <vector>
#include <msp/io/seekable.h>
#include "mspdatafile_api.h"
*/
class MSPDATAFILE_API CollectionSource
{
-public:
- using NameList = std::list<std::string>;
-
protected:
CollectionSource() = default;
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;
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);
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;
}
}
-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;
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())
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;
};
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);