File: ISimpleResourceLoader.h

package info (click to toggle)
vcmi 0.99%2Bdfsg%2Bgit20190113.f06c8a87-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 11,136 kB
  • sloc: cpp: 142,615; sh: 315; objc: 248; makefile: 32; ansic: 28; python: 13
file content (107 lines) | stat: -rw-r--r-- 2,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * ISimpleResourceLoader.h, part of VCMI engine
 *
 * Authors: listed in file AUTHORS in main folder
 *
 * License: GNU General Public License v2.0 or later
 * Full text of license available in license.txt file, in main folder
 *
 */
#pragma once

class CInputStream;
class ResourceID;

/**
 * A class which knows the files containing in the archive or system and how to load them.
 */
class DLL_LINKAGE ISimpleResourceLoader
{
public:
	virtual ~ISimpleResourceLoader() { };

	/**
	 * Loads a resource with the given resource name.
	 *
	 * @param resourceName The unqiue resource name in space of the archive.
	 * @return a input stream object
	 */
	virtual std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const = 0;

	/**
	 * Checks if the entry exists.
	 *
	 * @return Returns true if the entry exists, false if not.
	 */
	virtual bool existsResource(const ResourceID & resourceName) const = 0;

	/**
	 * Gets mount point to which this loader was attached
	 *
	 * @return mount point URI
	 */
	virtual std::string getMountPoint() const = 0;

	/**
	 * Gets full name of resource, e.g. name of file in filesystem.
	 *
	 * @return path or empty optional if file can't be accessed independently (e.g. file in archive)
	 */
	virtual boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const
	{
		return boost::optional<boost::filesystem::path>();
	}

	/**
	 * Gets all full names of matching resources, e.g. names of files in filesystem.
	 *
	 * @return std::set with names.
	 */
	virtual std::set<boost::filesystem::path> getResourceNames(const ResourceID & resourceName) const
	{
		std::set<boost::filesystem::path> result;
		auto rn = getResourceName(resourceName);
		if(rn)
		{
			result.insert(rn->string());
		}
		return result;
	}

	/**
	 * Update lists of files that match filter function
	 *
	 * @param filter Filter that returns true if specified mount point matches filter
	 */
	virtual void updateFilteredFiles(std::function<bool(const std::string &)> filter) const = 0;

	/**
	 * Get list of files that match filter function
	 *
	 * @param filter Filter that returns true if specified ID matches filter
	 * @return Returns list of flies
	 */
	virtual std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const = 0;

	/**
	 * Creates new resource with specified filename.
	 *
	 * @return true if new file was created, false on error or if file already exists
	 */
	virtual bool createResource(std::string filename, bool update = false)
	{
		return false;
	}

	/**
	 * @brief Returns all loaders that have resource with such name
	 *
	 * @return vector with all loaders
	 */
	virtual std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const
	{
		if (existsResource(resourceName))
			return std::vector<const ISimpleResourceLoader *>(1, this);
		return std::vector<const ISimpleResourceLoader *>();
	}
};