namespace Msp {
namespace DataFile {
-PackSource::PackSource(const PackSource &other):
- packs(other.packs),
- files(other.files),
- objects(other.objects)
-{
- translate_maps(other);
-}
-
-PackSource &PackSource::operator=(const PackSource &other)
-{
- packs = list<Pack>(other.packs.begin(), other.packs.end());
- files = other.files;
- objects = other.objects;
- translate_maps(other);
- return *this;
-}
-
-void PackSource::translate_maps(const PackSource &other)
-{
- for(auto i=packs.begin(), j=other.packs.begin(); (i!=packs.end() && j!=other.packs.end()); ++i, ++j)
- i->translate_files(files, *j);
- for(auto i=files.begin(), j=other.files.begin(); (i!=files.end() && j!=other.files.end()); ++i, ++j)
- i->second->translate_objects(objects, *j->second);
-}
-
void PackSource::add_pack_file(const string &fn)
{
add_pack_file(fn, string());
void PackSource::add_pack(IO::Seekable *io, const string &fn, const string &filter)
{
- auto i = find_if(packs, [io, &fn](const Pack &p){ return p.get_filename()==fn || (io && p.get_io()==io); });
+ auto i = find_if(packs, [io, &fn](const auto &p){ return p->get_filename()==fn || (io && p->get_io()==io); });
if(i==packs.end())
{
- packs.push_back(Pack(io, fn));
+ packs.emplace_back(make_unique<Pack>(io, fn));
i = prev(packs.end());
if(io)
{
DataFile::Parser parser(*io, fn);
- Pack::Loader loader(*i);
+ Pack::Loader loader(**i);
loader.load(parser);
}
else
- DataFile::load(*i, fn);
+ DataFile::load(**i, fn);
}
FileMap pack_files;
- i->collect_files(pack_files, filter);
+ (*i)->collect_files(pack_files, filter);
for(const auto &kvp: pack_files)
{
files[kvp.first] = kvp.second;
io(i)
{ }
-PackSource::Pack::Pack(const Pack &other):
- filename(other.filename),
- io(other.io),
- base_offset(other.base_offset)
-{
- for(const File &f: other.files)
- files.push_back(File(f, *this));
-}
-
void PackSource::Pack::collect_files(FileMap &fm, const string &filter) const
{
if(filter.empty())
{
- for(const File &f: files)
- fm[f.get_filename()] = &f;
+ for(const auto &f: files)
+ fm[f->get_filename()] = f.get();
}
else
{
Regex re(filter);
- for(const File &f: files)
- if(re.match(f.get_filename()))
- fm[f.get_filename()] = &f;
- }
-}
-
-void PackSource::Pack::translate_files(FileMap &fm, const Pack &source) const
-{
- for(auto i=files.begin(), j=source.files.begin(); (i!=files.end() && j!=source.files.end()); ++i, ++j)
- {
- auto k = fm.find(i->get_filename());
- if(k!=fm.end() && k->second==&*j)
- k->second = &*i;
+ for(const auto &f: files)
+ if(re.match(f->get_filename()))
+ fm[f->get_filename()] = f.get();
}
}
filename(fn)
{ }
-PackSource::File::File(const File &other, const Pack &p):
- pack(p),
- filename(other.filename),
- offset(other.offset),
- length(other.length),
- collection(other.collection)
-{
- for(const Object &o: other.objects)
- objects.push_back(Object(o, *this));
-}
-
unique_ptr<IO::Seekable> PackSource::File::open() const
{
if(pack.get_io())
void PackSource::File::collect_objects(ObjectMap &objs) const
{
- for(const Object &o: objects)
- objs[o.get_name()] = &o;
-}
-
-void PackSource::File::translate_objects(ObjectMap &objs, const File &source) const
-{
- for(auto i=objects.begin(), j=source.objects.begin(); (i!=objects.end() && j!=source.objects.end()); ++i, ++j)
- {
- auto k = objs.find(i->get_name());
- if(k!=objs.end() && k->second==&*j)
- k->second = &*i;
- }
+ for(const auto &o: objects)
+ objs[o->get_name()] = o.get();
}
keyword(k)
{ }
-PackSource::Object::Object(const Object &other, const File &f):
- file(f),
- name(other.name),
- keyword(other.keyword)
-{ }
-
PackSource::Pack::Loader::Loader(Pack &p):
ObjectLoader<Pack>(p)
void PackSource::Pack::Loader::file(const string &fn)
{
- obj.files.push_back(File(obj, fn));
- load_sub(obj.files.back());
+ obj.files.emplace_back(make_sub<File>(obj, fn).load());
}
void PackSource::File::Loader::finish()
{
if(!obj.collection)
- {
- PackSource::Object ob(obj, obj.filename, string());
- obj.objects.push_back(ob);
- }
+ obj.objects.emplace_back(make_unique<PackSource::Object>(obj, obj.filename, string()));
}
void PackSource::File::Loader::object(const string &name, const string &kwd)
{
- obj.objects.push_back(PackSource::Object(obj, name, kwd));
+ obj.objects.emplace_back(make_unique<PackSource::Object>(obj, name, kwd));
obj.collection = true;
}
std::string filename;
IO::Seekable *io = nullptr;
IO::SeekOffset base_offset = 0;
- std::list<File> files;
+ std::vector<std::unique_ptr<File>> files;
public:
Pack(IO::Seekable *, const std::string &);
- Pack(const Pack &);
const std::string &get_filename() const { return filename; }
IO::Seekable *get_io() const { return io; }
IO::SeekOffset get_base_offset() const { return base_offset; }
void collect_files(FileMap &, const std::string &) const;
- void translate_files(FileMap &, const Pack &) const;
};
class File
IO::SeekOffset offset = 0;
IO::SeekOffset length = 0;
bool collection = false;
- std::list<Object> objects;
+ std::vector<std::unique_ptr<Object>> objects;
public:
File(const Pack &, const std::string &);
- File(const File &, const Pack &);
std::unique_ptr<IO::Seekable> open() const;
const std::string &get_filename() const { return filename; }
bool is_collection() const { return collection; }
void collect_objects(ObjectMap &) const;
- void translate_objects(ObjectMap &, const File &) const;
};
class Object
public:
Object(const File &, const std::string &, const std::string &);
- Object(const Object &, const File &);
const File &get_file() const { return file; }
const std::string &get_name() const { return name; }
const std::string &get_keyword() const { return keyword; }
};
- std::list<Pack> packs;
+ std::vector<std::unique_ptr<Pack>> packs;
FileMap files;
ObjectMap objects;
-public:
- PackSource() = default;
- PackSource(const PackSource &);
- PackSource &operator=(const PackSource &);
-private:
- void translate_maps(const PackSource &);
-
public:
/// Adds a pack file to load objects from. The index is read immediately.
void add_pack_file(const std::string &);