ClanLib  2.3.7
resource_manager.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
31 
32 #pragma once
33 
34 #include "../api_core.h"
35 #include "../Resources/resource.h"
36 #include "../System/weakptr.h"
37 #include "../IOData/virtual_directory.h"
38 #include <vector>
39 
40 class CL_IODevice;
41 class CL_Resource;
43 class CL_ResourceManager_Impl;
44 
49 {
52 public:
55 
59  CL_ResourceManager(const CL_String &filename);
60 
65  CL_ResourceManager(const CL_String &filename, CL_VirtualDirectory directory);
66 
72 
77 
79 
83 public:
85  bool resource_exists(const CL_String &resource_id) const;
86 
88  std::vector<CL_String> get_section_names() const;
89 
91 
92  std::vector<CL_String> get_resource_names() const;
93 
94  std::vector<CL_String> get_resource_names(const CL_String &section) const;
95 
97 
98  std::vector<CL_String> get_resource_names_of_type(const CL_String &type) const;
99 
100  std::vector<CL_String> get_resource_names_of_type(
101  const CL_String &type,
102  const CL_String &section) const;
103 
105  CL_Resource get_resource(
106  const CL_String &resource_id,
107  bool resolve_alias = true,
108  int reserved = 0);
109 
111  CL_VirtualDirectory get_directory(const CL_Resource &resource) const;
112 
114  bool get_boolean_resource(
115  const CL_String &resource_id,
116  bool default_value);
117 
119  int get_integer_resource(
120  const CL_String &resource_id,
121  int default_value);
122 
124  CL_String get_string_resource(
125  const CL_String &resource_id,
126  const CL_StringRef &default_value);
127 
131 public:
132  CL_ResourceManager &operator =(const CL_ResourceManager &copy);
133 
134  bool operator ==(const CL_ResourceManager &manager) const;
135 
137  void set_directory(const CL_VirtualDirectory &directory);
138 
140 
142  void add_resources(const CL_ResourceManager& additional_resources);
143 
145  void remove_resources(const CL_ResourceManager& additional_resources);
146 
148  CL_Resource create_resource(const CL_String &resource_id, const CL_String &type);
149 
151  void destroy_resource(const CL_String &resource_id);
152 
154  void save(const CL_String &filename);
155 
160  void save(const CL_String &filename, CL_VirtualDirectory directory);
161 
165  void save(CL_IODevice file);
166 
168  void load(const CL_String &filename);
169 
174  void load(const CL_String &filename, CL_VirtualDirectory directory);
175 
180  void load(CL_IODevice file, CL_VirtualDirectory directory = CL_VirtualDirectory());
181 
185 private:
186 
190  CL_ResourceManager(CL_WeakPtr<CL_ResourceManager_Impl> &impl);
191 
192  CL_SharedPtr<CL_ResourceManager_Impl> impl;
193 
194  friend class CL_Resource;
196 };
197