From e249d648f6393fbb4b74e76c2a7b9eee9f1187f1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 26 Sep 2012 19:04:33 +0300 Subject: [PATCH] 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. --- source/collection.cpp | 5 ----- source/collection.h | 13 ++++++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) 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 -- 2.45.2