X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdirectorycollection.h;fp=source%2Fdirectorycollection.h;h=93f93545b589708f312fce6d87c1330de8f79ac3;hb=a4091f14dfbf4d5f822fa26740a7b3f305c449e6;hp=0000000000000000000000000000000000000000;hpb=534a9fb8c1e8ee6c40be90cb43c89bafb2cfbb24;p=libs%2Fdatafile.git diff --git a/source/directorycollection.h b/source/directorycollection.h new file mode 100644 index 0000000..93f9354 --- /dev/null +++ b/source/directorycollection.h @@ -0,0 +1,52 @@ +#ifndef MSP_DATAFILE_DIRECTORYCOLLECTION_H_ +#define MSP_DATAFILE_DIRECTORYCOLLECTION_H_ + +#include +#include "collection.h" + +namespace Msp { +namespace DataFile { + +/** +A Collection that can automatically load items from files in a directory. +*/ +class DirectoryCollection: public Collection +{ +private: + std::list dirs; + +public: + DirectoryCollection(); + +protected: + void set_directory(const FS::Path &); + void add_directory(const FS::Path &); + + template + CollectionItemType &add_type() + { + return Collection::add_type().creator(&DirectoryCollection::create); + } + +private: + template + T *create(const std::string &name) + { + FS::Path file; + if(lookup_file(name, file)) + { + RefPtr item = new T; + load(*item, file.str()); + return item.release(); + } + else + return 0; + } + + bool lookup_file(const std::string &, FS::Path &) const; +}; + +} // namespace DataFile +} // namespace Msp + +#endif