]> git.tdb.fi Git - libs/datafile.git/commitdiff
Some minor fixes in Collection
authorMikko Rasa <tdb@tdb.fi>
Thu, 6 Dec 2012 21:44:11 +0000 (23:44 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 6 Dec 2012 21:44:11 +0000 (23:44 +0200)
Move RemoveConst invovations close to the public interface to reduce the
number of template function instantiations.

Correct access specifiers.

source/collection.h

index d5853f2ea6cb4a3fba658dd5912e148f419cb8e4..bbde9f904dfd3e8415ae0e0a8dc0ae8b2d9db641 100644 (file)
@@ -75,7 +75,6 @@ public:
                }
        };
 
-protected:
        template<typename T, bool = NeedsCollection<typename T::Loader>::value>
        class ItemLoader;
 
@@ -119,7 +118,7 @@ public:
        template<typename T>
        T &get(const std::string &name) const
        {
-               return extract<T>(get_item(items, name));
+               return extract<typename RemoveConst<T>::Type>(get_item(items, name));
        }
 
        /** Gets a typed object from the collection.  If the name is not found,
@@ -128,7 +127,8 @@ public:
        template<typename T>
        T &get(const std::string &name)
        {
-               return extract<T>(get_var(name, get_type<T>()));
+               typedef typename RemoveConst<T>::Type NCT;
+               return extract<NCT>(get_var(name, get_type<NCT>()));
        }
 
 private:
@@ -247,6 +247,7 @@ protected:
        template<typename T>
        CollectionItemType<T> &add_type();
 
+private:
        /// Returns the descriptor for a type, or null if one isn't defined.
        template<typename T>
        CollectionItemTypeBase *get_type() const;
@@ -254,8 +255,10 @@ protected:
        /// Returns the descriptor for an item, or null if it's of an unknown type.
        CollectionItemTypeBase *get_type_for_item(const Variant &) const;
 
+protected:
        void add_source(CollectionSource &);
 
+private:
        void gather_names_from_sources(std::list<std::string> &, const CollectionItemTypeBase &) const;
 
        void load_items_from_sources(const CollectionItemTypeBase &);
@@ -452,14 +455,12 @@ public:
 template<typename T>
 T &Collection::extract(const Variant &var) const
 {
-       typedef RefPtr<typename RemoveConst<T>::Type> RPNCT;
-
-       if(!var.check_type<RPNCT>())
+       if(!var.check_type<RefPtr<T> >())
                if(CollectionItemTypeBase *type = get_type_for_item(var))
                        if(T *item = type->extract<T>(var))
                                return *item;
 
-       return *var.value<RPNCT>();
+       return *var.value<RefPtr<T> >();
 }
 
 template<typename T>
@@ -474,7 +475,7 @@ template<typename T>
 CollectionItemTypeBase *Collection::get_type() const
 {
        for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j)
-               if(dynamic_cast<CollectionItemType<typename RemoveConst<T>::Type> *>(*j))
+               if(dynamic_cast<CollectionItemType<T> *>(*j))
                        return *j;
        for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j)
                if((*j)->can_extract<T>())