]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/collection.cpp
Cosmetic changes
[libs/datafile.git] / source / collection.cpp
index 8b295858ac72fadf42a535be78c7272d8e50ba27..e1c25ddc914e6afd0f2be1b8e4ef198846c5c209 100644 (file)
@@ -7,10 +7,6 @@ using namespace std;
 namespace Msp {
 namespace DataFile {
 
-Collection::Collection():
-       fallback(0)
-{ }
-
 Collection::~Collection()
 {
        for(CollectionItemTypeBase *t: types)
@@ -20,8 +16,16 @@ Collection::~Collection()
 void Collection::add_var(const string &name, const CollectionItemTypeBase *type, const Variant &var)
 {
        insert_unique(items, name, var);
-       if(type)
-               type->notify_item(name, var);
+       try
+       {
+               if(type)
+                       type->notify_item(name, var);
+       }
+       catch(...)
+       {
+               remove_existing(items, name);
+               throw;
+       }
 }
 
 const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type)
@@ -59,7 +63,7 @@ const Variant *Collection::find_var(const string &name, const CollectionItemType
        }
 
        i = items.find(name);
-       return (i!=items.end() ? &i->second : 0);
+       return (i!=items.end() ? &i->second : nullptr);
 }
 
 void Collection::gather_items(vector<const Variant *> *vars, list<string> *names, const CollectionItemTypeBase &type, bool include_sources) const
@@ -99,7 +103,7 @@ CollectionItemTypeBase *Collection::get_type(const CollectionItemTypeBase &type)
        for(CollectionItemTypeBase *t: types)
                if(t->is_same_type(type))
                        return t;
-       return 0;
+       return nullptr;
 }
 
 CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const
@@ -107,7 +111,7 @@ CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const
        for(CollectionItemTypeBase *t: types)
                if(t->check_item_type(var))
                        return t;
-       return 0;
+       return nullptr;
 }
 
 void Collection::add_source(const CollectionSource &s)
@@ -121,7 +125,7 @@ IO::Seekable *Collection::open_raw(const string &name) const
                if(IO::Seekable *io = s->open(name))
                        return io;
 
-       return 0;
+       return nullptr;
 }
 
 void Collection::gather_names_from_sources(list<string> &names, const CollectionItemTypeBase &type) const