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 &);
25 /** Examines the names of files in the designated directories and adds any
26 applicable ones as future objects. */
30 CollectionItemType<T> &add_type()
32 return Collection::add_type<T>().creator(&DirectoryCollection::create<T>);
37 T *create(const std::string &name)
40 if(lookup_file(name, file))
42 RefPtr<T> item = new T;
43 ItemLoader<T> ldr(*item, *this);
44 IO::BufferedFile in(file.str());
45 Parser parser(in, file.str());
47 return item.release();
54 bool lookup_file(const std::string &, FS::Path &) const;
57 } // namespace DataFile