]> git.tdb.fi Git - libs/datafile.git/commitdiff
Add Collection::get_list
authorMikko Rasa <tdb@tdb.fi>
Thu, 18 Oct 2007 13:43:18 +0000 (13:43 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 18 Oct 2007 13:43:18 +0000 (13:43 +0000)
source/collection.h

index 85ca843f5e1aba552ab2c2ed26a7241d30675d0b..6ddbe6ed65c980d035b30160ad1eca18c0390f1f 100644 (file)
@@ -251,11 +251,26 @@ public:
        {
                std::list<std::string> result;
                for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i)
-                       if(dynamic_cast<const Item<T> *>(i->second))
+                       if(dynamic_cast<const Item<typename RemoveConst<T>::Type> *>(i->second))
                                result.push_back(i->first);
                return result;
        }
 
+       /**
+       Returns a list of objects of a specific type in the collection.
+       */
+       template<typename T>
+       std::list<T *> get_list() const
+       {
+               typedef typename RemoveConst<T>::Type NCT;
+
+               std::list<T *> result;
+               for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i)
+                       if(Item<NCT> *item=dynamic_cast<Item<NCT> *>(i->second))
+                               result.push_back(item->data);
+               return result;
+       }
+
        /**
        Checks whether a name exists in the collection.  Does not care about the
        type of the object.