1 #include <msp/strings/format.h>
2 #include "packcollection.h"
9 void PackCollection::add_pack_file(const string &fn)
11 packs.push_back(Pack(fn));
12 Pack &pack = packs.back();
16 pack.collect_objects(pack_objs);
17 for(ObjectMap::const_iterator i=pack_objs.begin(); i!=pack_objs.end(); ++i)
19 if(i->second->get_keyword().empty())
22 add_future_with_keyword(i->first, i->second->get_keyword());
25 objects.insert(pack_objs.begin(), pack_objs.end());
29 PackCollection::Pack::Pack(const string &fn):
34 void PackCollection::Pack::collect_objects(ObjectMap &objs) const
36 for(list<File>::const_iterator i=files.begin(); i!=files.end(); ++i)
37 i->collect_objects(objs);
41 PackCollection::File::File(const Pack &p, const string &fn):
50 RefPtr<IO::Base> PackCollection::File::open() const
52 RefPtr<IO::BufferedFile> io_file = new IO::BufferedFile(pack.get_filename());
53 io_file->seek(pack.get_base_offset()+offset, IO::S_BEG);
57 string PackCollection::File::get_full_name() const
59 return format("%s/%s", pack.get_filename(), filename);
62 void PackCollection::File::set_loaded()
67 void PackCollection::File::collect_objects(ObjectMap &objs) const
69 for(list<Object>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
70 objs[i->get_name()] = &*i;
74 PackCollection::Object::Object(File &f, const string &n, const string &k):
81 PackCollection::Pack::Loader::Loader(Pack &p):
84 add("file", &Loader::file);
85 add("base_offset", &Pack::base_offset);
88 void PackCollection::Pack::Loader::file(const string &fn)
90 obj.files.push_back(File(obj, fn));
91 load_sub(obj.files.back());
95 PackCollection::File::Loader::Loader(File &f):
98 add("object", &Loader::object);
99 add("slice", &File::offset, &File::length);
102 void PackCollection::File::Loader::finish()
106 PackCollection::Object ob(obj, obj.filename, string());
107 obj.objects.push_back(ob);
111 void PackCollection::File::Loader::object(const string &name, const string &kwd)
113 obj.objects.push_back(PackCollection::Object(obj, name, kwd));
114 obj.collection = true;
117 } // namespace DataFile