1 #ifndef MSP_DATAFILE_PACKSOURCE_H_
2 #define MSP_DATAFILE_PACKSOURCE_H_
4 #include <msp/core/refptr.h>
5 #include "collectionsource.h"
6 #include "objectloader.h"
12 A source that loads data from pack files. As opposed to plain collection
13 files, pack files are composed from a number of logical files. They also
14 contain an index of objects contained in the pack and which logical files they
15 are in. This allows the pack to be loaded in a piecewise manner instead of all
18 It's possible for a pack file to contain plain collection files as well. When
19 an object from such a file is requested, the entire sub-collection it is stored
22 class PackSource: public CollectionSource
35 typedef std::map<std::string, const File *> FileMap;
36 typedef std::map<std::string, const Object *> ObjectMap;
41 class Loader: public ObjectLoader<Pack>
46 void file(const std::string &);
53 std::list<File> files;
56 Pack(IO::Seekable *, const std::string &);
58 const std::string &get_filename() const { return filename; }
59 IO::Seekable *get_io() const { return io; }
60 unsigned get_base_offset() const { return base_offset; }
62 void collect_files(FileMap &, const std::string &) const;
68 class Loader: public ObjectLoader<File>
73 virtual void finish();
74 void object(const std::string &, const std::string &);
83 std::list<Object> objects;
87 File(const Pack &, const std::string &);
89 RefPtr<IO::Seekable> open() const;
90 const std::string &get_filename() const { return filename; }
91 FileInfo get_info() const;
92 std::string get_full_name() const;
93 bool is_collection() const { return collection; }
96 bool is_loaded() const { return loaded; }
98 void collect_objects(ObjectMap &) const;
109 Object(File &, const std::string &, const std::string &);
111 File &get_file() const { return file; }
112 const std::string &get_name() const { return name; }
113 const std::string &get_keyword() const { return keyword; }
116 std::list<Pack> packs;
121 /// Adds a pack file to load objects from. The index is read immediately.
122 void add_pack_file(const std::string &);
124 /** Adds a pack file with a regex to filter logical files. The index is
125 read on the first call; subsequent calls will use cached data. */
126 void add_pack_file(const std::string &, const std::string &);
128 /** Adds a pack from an existing seekable I/O object. The same object is
129 used for all accesses to the pack, so it must not be deleted before the
131 void add_pack_io(IO::Seekable &, const std::string & = std::string());
133 /** Adds a pack from an I/O object with a regex to filter logical files.
134 Multiple filters for the same I/O object can be added with repeated calls. */
135 void add_pack_io(IO::Seekable &, const std::string &, const std::string &);
138 void add_pack(IO::Seekable *, const std::string &, const std::string &);
141 /// Returns information about the files in the pack.
142 std::list<FileInfo> list_files() const;
144 virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const;
145 virtual NameList get_names(const CollectionItemTypeBase &) const;
146 virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const;
147 virtual IO::Seekable *open(const std::string &) const;
150 } // namespace DataFile