X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fcollection.cpp;h=a16ae5a9dc2e7a9f70f638093348b59c8bd561eb;hp=d52ee22399ba7500c880798f2fcf3036d9cd095c;hb=495920e971324d29bd4933b8a319fb5668ca5562;hpb=4f036ceabe12869c86cb6821f698fbb65cd47ea6 diff --git a/source/collection.cpp b/source/collection.cpp index d52ee22..a16ae5a 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -1,5 +1,7 @@ #include "collection.h" +using namespace std; + namespace Msp { namespace DataFile { @@ -9,6 +11,22 @@ Collection::~Collection() delete *i; } +void Collection::add_future(const std::string &name) +{ + if(items.count(name)) + throw key_error(typeid(ItemMap)); + + for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i) + if((*i)->match_name(name)) + { + items.insert(ItemMap::value_type(name, (*i)->create_future())); + return; + } + + /* XXX throw something? If we do, DirectoryCollection needs some way to + check if a name matches any item type. */ +} + Collection::Loader::Loader(Collection &c): coll(c) @@ -27,5 +45,25 @@ CollectionItemTypeBase::~CollectionItemTypeBase() delete tag; } +void CollectionItemTypeBase::set_keyword(const string &k) +{ + kwd = k; + if(suffixes.empty()) + add_suffix("."+kwd); +} + +void CollectionItemTypeBase::add_suffix(const string &s) +{ + suffixes.push_back(s); +} + +bool CollectionItemTypeBase::match_name(const string &name) const +{ + for(vector::const_iterator i=suffixes.begin(); i!=suffixes.end(); ++i) + if(name.size()>i->size() && !name.compare(name.size()-i->size(), string::npos, *i)) + return true; + return false; +} + } // namespace DataFile } // namespace Msp