From: Mikko Rasa Date: Wed, 26 Sep 2012 16:04:33 +0000 (+0300) Subject: Make Collection::contains check for type X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e249d648f6393fbb4b74e76c2a7b9eee9f1187f1;p=libs%2Fdatafile.git Make Collection::contains check for type Checking item existence without type information is not particularly useful, since there's no guarantee that the object can be used for its intended purpose. --- diff --git a/source/collection.cpp b/source/collection.cpp index e60b200..d40ab19 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -9,11 +9,6 @@ Collection::~Collection() delete *i; } -bool Collection::contains(const std::string &n) const -{ - return items.count(n); -} - Collection::Loader::Loader(Collection &c): coll(c) diff --git a/source/collection.h b/source/collection.h index 5dd2fe6..d5e0806 100644 --- a/source/collection.h +++ b/source/collection.h @@ -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 + 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::Type>(); + } /// Returns the name of an item in the collection. template