X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdirectorysource.cpp;h=207f30d0e31716c310f0927b82f5ba14fe456b6a;hb=HEAD;hp=4bf9f5cd3d12b0808f288b9e3cd647a5ee0db682;hpb=9b1656018f783eb4aad2fbdc1de1404691e89bb1;p=libs%2Fdatafile.git diff --git a/source/directorysource.cpp b/source/directorysource.cpp index 4bf9f5c..7e1e438 100644 --- a/source/directorysource.cpp +++ b/source/directorysource.cpp @@ -8,11 +8,11 @@ using namespace std; namespace Msp { namespace DataFile { -void DirectorySource::add_directory(const FS::Path &d) +void DirectorySource::add_directory(const FS::Path &d, bool replace) { - list files = FS::list_files(d); - for(list::const_iterator i=files.begin(); i!=files.end(); ++i) - objects[*i] = d / *i; + for(const string &f: FS::list_files(d)) + if(!objects.count(f) || replace) + objects[f] = d/f; } bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &name) const @@ -23,9 +23,9 @@ bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string & CollectionSource::NameList DirectorySource::get_names(const CollectionItemTypeBase &type) const { NameList names; - for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i) - if(type.match_name(i->first)) - names.push_back(i->first); + for(const auto &kvp: objects) + if(type.match_name(kvp.first)) + names.push_back(kvp.first); return names; } @@ -46,7 +46,7 @@ IO::Seekable *DirectorySource::open(const string &name) const if(lookup_file(name, file)) return new IO::BufferedFile(file.str()); - return 0; + return nullptr; } bool DirectorySource::lookup_file(const string &name, FS::Path &result) const