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, bool replace)
13 list<string> files = FS::list_files(d);
14 for(list<string>::const_iterator i=files.begin(); i!=files.end(); ++i)
16 if(!objects.count(*i) || replace)
21 bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &name) const
23 return objects.count(name);
26 CollectionSource::NameList DirectorySource::get_names(const CollectionItemTypeBase &type) const
29 for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i)
30 if(type.match_name(i->first))
31 names.push_back(i->first);
35 void DirectorySource::load(Collection &coll, const CollectionItemTypeBase &type, const string &name) const
38 if(lookup_file(name, file))
40 IO::BufferedFile in(file.str());
41 Parser parser(in, file.str());
42 type.load_item(coll, parser, name);
46 IO::Seekable *DirectorySource::open(const string &name) const
49 if(lookup_file(name, file))
50 return new IO::BufferedFile(file.str());
55 bool DirectorySource::lookup_file(const string &name, FS::Path &result) const
57 ObjectMap::const_iterator i = objects.find(name);
65 } // namespace DataFile