]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/collection.cpp
Turn internal type helpers into structs
[libs/datafile.git] / source / collection.cpp
index 5ac12ab7d366c3406cfc59206b42b166875557d5..87982e8f4baa5df80ec1dbe257e33ba4b83af594 100644 (file)
@@ -11,26 +11,33 @@ Collection::~Collection()
                delete *i;
 }
 
-void Collection::add_future(const string &name)
+const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type)
 {
-       for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i)
-               if((*i)->match_name(name))
+       ItemMap::iterator i = items.find(name);
+       if(i!=items.end())
+               return i->second;
+
+       if(type)
+       {
+               bool loaded = false;
+               if(type->can_create())
                {
-                       insert_unique(items, name, (*i)->create_future());
-                       return;
+                       type->create_item(*this, name);
+                       loaded = items.count(name);
                }
-}
-
-void Collection::add_future_with_keyword(const string &name, const string &keyword)
-{
-       for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i)
-               if((*i)->get_keyword()==keyword)
+               for(SourceList::iterator j=sources.begin(); (!loaded && j!=sources.end()); ++j)
                {
-                       insert_unique(items, name, (*i)->create_future());
-                       return;
+                       (*j)->load(*this, *type, name);
+                       loaded = items.count(name);
                }
+       }
 
-       throw runtime_error("Collection::add_future_with_keyword");
+       return get_item(items, name);
+}
+
+void Collection::add_source(CollectionSource &s)
+{
+       sources.push_back(&s);
 }