Add a flag to control replacement of DirectorySource entries
authorMikko Rasa <tdb@tdb.fi>
Sun, 5 Oct 2014 01:50:48 +0000 (04:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Oct 2014 01:50:48 +0000 (04:50 +0300)
source/directorysource.cpp
source/directorysource.h

index 4bf9f5c..207f30d 100644 (file)
@@ -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<string> files = FS::list_files(d);
        for(list<string>::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
index b1324a7..660d4e8 100644 (file)
@@ -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;