1 #include "collection.h"
8 Collection::~Collection()
10 for(TypeList::iterator i = types.begin(); i!=types.end(); ++i)
14 const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type)
16 ItemMap::iterator i = items.find(name);
23 if(type->can_create())
25 type->create_item(*this, name);
26 loaded = items.count(name);
28 for(SourceList::iterator j=sources.begin(); (!loaded && j!=sources.end()); ++j)
30 (*j)->load(*this, *type, name);
31 loaded = items.count(name);
35 return get_item(items, name);
38 void Collection::gather_items(list<const Variant *> *vars, list<string> *names, const CollectionItemTypeBase &type, bool include_sources) const
40 for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i)
41 if(type.check_item_type(i->second))
44 vars->push_back(&i->second);
46 names->push_back(i->first);
49 if(include_sources && names)
50 gather_names_from_sources(*names, type);
53 unsigned Collection::get_status(const string &name, const CollectionItemTypeBase &type) const
55 ItemMap::const_iterator i = items.find(name);
58 for(SourceList::const_iterator j=sources.begin(); j!=sources.end(); ++j)
59 if((*j)->is_loadable(type, name))
64 return type.check_item_type(i->second);
67 CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const
69 for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i)
70 if((*i)->check_item_type(var))
75 void Collection::add_source(CollectionSource &s)
77 sources.push_back(&s);
80 void Collection::gather_names_from_sources(list<string> &names, const CollectionItemTypeBase &type) const
82 for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
84 std::list<std::string> available_names = (*i)->get_names(type);
85 for(std::list<std::string>::iterator j=available_names.begin(); j!=available_names.end(); ++j)
91 void Collection::load_items_from_sources(const CollectionItemTypeBase &type)
93 for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
95 std::list<std::string> available_names = (*i)->get_names(type);
96 for(std::list<std::string>::iterator j=available_names.begin(); j!=available_names.end(); ++j)
98 (*i)->load(*this, type, *j);
103 Collection::Loader::Loader(Collection &c):
106 for(TypeList::const_iterator i = coll.types.begin(); i!=coll.types.end(); ++i)
107 (*i)->add_to_loader(*this);
111 CollectionItemTypeBase::~CollectionItemTypeBase()
113 for(vector<ExtractorBase *>::iterator i=extractors.begin(); i!=extractors.end(); ++i)
117 void CollectionItemTypeBase::set_keyword(const string &k)
124 void CollectionItemTypeBase::add_suffix(const string &s)
126 suffixes.push_back(s);
129 bool CollectionItemTypeBase::match_name(const string &name) const
131 for(vector<string>::const_iterator i=suffixes.begin(); i!=suffixes.end(); ++i)
132 if(name.size()>i->size() && !name.compare(name.size()-i->size(), string::npos, *i))
137 } // namespace DataFile