1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include "collection.h"
4 #include "directorysource.h"
11 void DirectorySource::add_directory(const FS::Path &d)
13 list<string> files = FS::list_files(d);
14 for(list<string>::const_iterator i=files.begin(); i!=files.end(); ++i)
18 bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &name) const
20 return objects.count(name);
23 CollectionSource::NameList DirectorySource::get_names(const CollectionItemTypeBase &type) const
26 for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i)
27 if(type.match_name(i->first))
28 names.push_back(i->first);
32 void DirectorySource::load(Collection &coll, const CollectionItemTypeBase &type, const string &name) const
35 if(lookup_file(name, file))
37 IO::BufferedFile in(file.str());
38 Parser parser(in, file.str());
39 type.load_item(coll, parser, name);
43 IO::Seekable *DirectorySource::open(const string &name) const
46 if(lookup_file(name, file))
47 return new IO::BufferedFile(file.str());
52 bool DirectorySource::lookup_file(const string &name, FS::Path &result) const
54 ObjectMap::const_iterator i = objects.find(name);
62 } // namespace DataFile