+ return extract<typename std::remove_cv<T>::type>(get_item(items, name));
+ }
+
+ /** Gets a typed object from the collection. If the name is not found,
+ automatic creation with the type's creator function (if defined) or from
+ sources (if present) is attempted. */
+ template<typename T>
+ T &get(const std::string &name)
+ {
+ typedef typename std::remove_cv<T>::type NCT;
+ return extract<NCT>(get_var(name, get_type<NCT>(name)));
+ }
+
+ /** Finds a typed object in the collection. Returns null if the name does
+ not exist. Throws if the name exists but the object is of an incorrect
+ type. */
+ template<typename T>
+ T *find(const std::string &name) const
+ {
+ ItemMap::const_iterator i = items.find(name);
+ return (i!=items.end() ? extract<typename std::remove_cv<T>::type>(i->second) : 0);
+ }
+
+ template<typename T>
+ T *find(const std::string &name)
+ {
+ typedef typename std::remove_cv<T>::type NCT;
+ const Variant *var = find_var(name, get_type<NCT>(name));
+ return (var ? &extract<NCT>(*var) : 0);
+ }
+
+private:
+ void add_var(const std::string &, const CollectionItemTypeBase *, const Variant &);
+ const Variant &get_var(const std::string &, const CollectionItemTypeBase *);
+ const Variant *find_var(const std::string &, const CollectionItemTypeBase *);
+
+ template<typename T>
+ T &extract(const Variant &var) const;