sources.push_back(&s);
}
+IO::Seekable *Collection::open_from_sources(const string &name)
+{
+ for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ if(IO::Seekable *io = (*i)->open(name))
+ return io;
+
+ throw IO::file_not_found(name);
+}
+
void Collection::gather_names_from_sources(list<string> &names, const CollectionItemTypeBase &type) const
{
for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
protected:
void add_source(CollectionSource &);
+ IO::Seekable *open_from_sources(const std::string &);
+
private:
void gather_names_from_sources(std::list<std::string> &, const CollectionItemTypeBase &) const;
#include <list>
#include <string>
+#include <msp/io/seekable.h>
namespace Msp {
namespace DataFile {
virtual NameList get_names(const CollectionItemTypeBase &type) const = 0;
virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const = 0;
+
+ /** Opens a file from the source. The caller is responsible for deleting
+ the returned object when done with it. */
+ virtual IO::Seekable *open(const std::string &) const = 0;
};
} // namespace DataFile
}
}
+IO::Seekable *DirectorySource::open(const string &name) const
+{
+ FS::Path file;
+ if(lookup_file(name, file))
+ return new IO::BufferedFile(file.str());
+
+ return 0;
+}
+
bool DirectorySource::lookup_file(const string &name, FS::Path &result) const
{
ObjectMap::const_iterator i = objects.find(name);
virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const;
virtual NameList get_names(const CollectionItemTypeBase &) const;
virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const;
+ virtual IO::Seekable *open(const std::string &) const;
bool lookup_file(const std::string &, FS::Path &) const;
};
FileMap pack_files;
pack->collect_files(pack_files, filter);
+ files.insert(pack_files.begin(), pack_files.end());
for(FileMap::const_iterator i=pack_files.begin(); i!=pack_files.end(); ++i)
i->second->collect_objects(objects);
}
type.load_item(coll, parser, name);
}
+IO::Seekable *PackSource::open(const string &fn) const
+{
+ FileMap::const_iterator i = files.find(fn);
+ if(i!=files.end())
+ return i->second->open().release();
+
+ return 0;
+}
+
PackSource::Pack::Pack(const string &fn):
filename(fn),
loaded(false)
{ }
-RefPtr<IO::Base> PackSource::File::open() const
+RefPtr<IO::Seekable> PackSource::File::open() const
{
IO::BufferedFile *io_file = new IO::BufferedFile(pack.get_filename());
IO::Slice *io_slice = new IO::Slice(*io_file, pack.get_base_offset()+offset, length);
public:
File(const Pack &, const std::string &);
- RefPtr<IO::Base> open() const;
+ RefPtr<IO::Seekable> open() const;
const std::string &get_filename() const { return filename; }
std::string get_full_name() const;
bool is_collection() const { return collection; }
};
std::list<Pack> packs;
+ FileMap files;
ObjectMap objects;
public:
virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const;
virtual NameList get_names(const CollectionItemTypeBase &) const;
virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const;
+ virtual IO::Seekable *open(const std::string &) const;
};
} // namespace DataFile