]> git.tdb.fi Git - libs/datafile.git/blob - source/collectionsource.h
Move the definition of Input's operator bool to the header
[libs/datafile.git] / source / collectionsource.h
1 #ifndef COLLECTIONSOURCE_H_
2 #define COLLECTIONSOURCE_H_
3
4 #include <list>
5 #include <string>
6 #include <msp/io/seekable.h>
7 #include "mspdatafile_api.h"
8
9 namespace Msp {
10 namespace DataFile {
11
12 class Collection;
13 class CollectionItemTypeBase;
14
15 /**
16 Provides automatically loadable objects for collections.  This is a base class;
17 see DirectorySource and PackSource for concrete classes.
18 */
19 class MSPDATAFILE_API CollectionSource
20 {
21 public:
22         typedef std::list<std::string> NameList;
23
24 protected:
25         CollectionSource() = default;
26 public:
27         virtual ~CollectionSource() = default;
28
29         /// Determines whether an object is available from this source.
30         virtual bool is_loadable(const CollectionItemTypeBase &type, const std::string &name) const = 0;
31
32         /** Returns the names of available objects of a specific type.  Implementors
33         should use type.match_name to check which names are acceptable. */
34         virtual NameList get_names(const CollectionItemTypeBase &type) const = 0;
35
36         /// Loads an item into a collection.
37         virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const = 0;
38
39         /** Opens a raw resource.  The caller is responsible for deleting the
40         returned object when done with it. */
41         virtual IO::Seekable *open(const std::string &) const = 0;
42 };
43
44 } // namespace DataFile
45 } // namespace Msp
46
47 #endif