]> Dogcows Code - chaz/yoink/blob - src/moof/resource.hh
ed8a7d06f8fd9a8c420d9fab59c0c54de60a0658
[chaz/yoink] / src / moof / resource.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_RESOURCE_HH_
13 #define _MOOF_RESOURCE_HH_
14
15 /**
16 * \file resource.hh
17 * Interface for textures, sounds, and other types of resources.
18 */
19
20 #include <cstdio>
21 #include <string>
22 #include <vector>
23
24
25 namespace moof {
26
27
28 /**
29 * Generic resource class.
30 */
31
32 class resource
33 {
34 public:
35
36 virtual ~resource() {}
37
38
39 /**
40 * Add a directory to search when looking for resource files.
41 * \param paths A colon-separated list of directory paths.
42 */
43 static void add_search_paths(const std::string& paths);
44
45 /**
46 * Add directories to search when looking for resource files.
47 * \param pathList The list of directory paths.
48 */
49 static void add_search_paths(const std::vector<std::string>& pathList);
50
51
52 /**
53 * Get the path to a resource of a given name.
54 * \param path The name of the resource to find. Upon successful
55 * return, this is changed to an absolute path to the resource.
56 * \param prefix A colon-separated list of subdirectories to search.
57 * \param extension A colon-separated list of possible extensions.
58 * \return True if a path to a resource was found, false otherwise.
59 */
60 static bool find_path(std::string& path,
61 const std::string& prefix = "",
62 const std::string& extension = "");
63
64 /**
65 * Get the path to a resource of a given name and open it if a resource
66 * was found.
67 * \param path The name of the resource to find. Upon successful
68 * return, this is changed to an absolute path to the resource.
69 * \param prefix A colon-separated list of subdirectories to search.
70 * \param extension A colon-separated list of possible extensions.
71 * \param mode The open mode.
72 * \return The FILE* if the resource was found, 0 otherwise.
73 */
74 static FILE* open_file(std::string& path,
75 const std::string& prefix = "",
76 const std::string& extension = "",
77 const std::string& mode = "rb");
78
79
80 private:
81
82 static std::vector<std::string> search_paths_;
83 };
84
85
86 } // namespace moof
87
88 #endif // _MOOF_RESOURCE_HH_
89
This page took 0.03596 seconds and 4 git commands to generate.