]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/collection.h
Make Collection::contains check for type
[libs/datafile.git] / source / collection.h
index 5dd2fe67ff2769083532605e2b33bd5fe3c9dec1..d5e0806afeebad9fbfa2f043ef80d3ef9bc64878 100644 (file)
@@ -151,9 +151,16 @@ public:
                return result;
        }
 
-       /** Checks whether a name exists in the collection.  Does not care about the
-       type of the object. */
-       bool contains(const std::string &n) const;
+       /// Checks whether a typed object exists in the collection.
+       template<typename T>
+       bool contains(const std::string &name) const
+       {
+               ItemMap::const_iterator i = items.find(name);
+               if(i==items.end())
+                       return false;
+
+               return i->second.check_type<typename RemoveConst<T>::Type>();
+       }
 
        /// Returns the name of an item in the collection.
        template<typename T>