1 #ifndef MSP_DATAFILE_DIRECTORYCOLLECTION_H_
2 #define MSP_DATAFILE_DIRECTORYCOLLECTION_H_
4 #include <msp/fs/path.h>
5 #include "collection.h"
11 A Collection that can automatically load items from files in a directory.
13 class DirectoryCollection: public Collection
16 std::list<FS::Path> dirs;
19 DirectoryCollection();
22 void set_directory(const FS::Path &);
23 void add_directory(const FS::Path &);
26 CollectionItemType<T> &add_type()
28 return Collection::add_type<T>().creator(&DirectoryCollection::create<T>);
33 T *create(const std::string &name)
36 if(lookup_file(name, file))
38 RefPtr<T> item = new T;
39 load(*item, file.str());
40 return item.release();
46 bool lookup_file(const std::string &, FS::Path &) const;
49 } // namespace DataFile