From: Mikko Rasa Date: Sun, 5 Oct 2014 01:50:48 +0000 (+0300) Subject: Add a flag to control replacement of DirectorySource entries X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f38a2720fce4647b727030421e70fce6a28c9bd9;p=libs%2Fdatafile.git Add a flag to control replacement of DirectorySource entries --- diff --git a/source/directorysource.cpp b/source/directorysource.cpp index 4bf9f5c..207f30d 100644 --- a/source/directorysource.cpp +++ b/source/directorysource.cpp @@ -8,11 +8,14 @@ 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; + { + if(!objects.count(*i) || replace) + objects[*i] = d / *i; + } } bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &name) const diff --git a/source/directorysource.h b/source/directorysource.h index b1324a7..660d4e8 100644 --- a/source/directorysource.h +++ b/source/directorysource.h @@ -18,7 +18,7 @@ private: ObjectMap objects; public: - void add_directory(const FS::Path &); + void add_directory(const FS::Path &, bool = true); virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const; virtual NameList get_names(const CollectionItemTypeBase &) const;