xml_resource_document.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 
29 
30 #pragma once
31 
32 #include "../api_core.h"
33 #include "../Resources/xml_resource_node.h"
34 #include "../IOData/file_system.h"
35 #include <vector>
36 #include <memory>
37 
38 namespace clan
39 {
42 
43 class IODevice;
44 class XMLResourceNode;
45 class FileSystem;
46 class XMLResourceDocument_Impl;
47 
49 class CL_API_CORE XMLResourceDocument
50 {
53 public:
56 
60  XMLResourceDocument(const std::string &filename);
61 
66  XMLResourceDocument(const std::string &filename, FileSystem fs);
67 
72  XMLResourceDocument(IODevice file, const std::string &base_path, FileSystem fs);
73 
78 
80 
84 public:
86  bool resource_exists(const std::string &resource_id) const;
87 
89  std::vector<std::string> get_section_names() const;
90 
92 
93  std::vector<std::string> get_resource_names() const;
94 
95  std::vector<std::string> get_resource_names(const std::string &section) const;
96 
98 
99  std::vector<std::string> get_resource_names_of_type(const std::string &type) const;
100 
101  std::vector<std::string> get_resource_names_of_type(
102  const std::string &type,
103  const std::string &section) const;
104 
106  XMLResourceNode get_resource(
107  const std::string &resource_id) const;
108 
110  bool get_boolean_resource(
111  const std::string &resource_id,
112  bool default_value) const;
113 
115  int get_integer_resource(
116  const std::string &resource_id,
117  int default_value) const;
118 
120  std::string get_string_resource(
121  const std::string &resource_id,
122  const std::string &default_value) const;
123 
127 public:
128  XMLResourceDocument &operator =(const XMLResourceDocument &copy);
129 
130  bool operator ==(const XMLResourceDocument &that) const;
131 
133 
135  void add_resources(const XMLResourceDocument& additional_resources);
136 
138  void remove_resources(const XMLResourceDocument& additional_resources);
139 
141  XMLResourceNode create_resource(const std::string &resource_id, const std::string &type);
142 
144  void destroy_resource(const std::string &resource_id);
145 
147  void save(const std::string &filename);
148 
153  void save(const std::string &filename, const FileSystem &file_system);
154 
158  void save(IODevice file);
159 
161  void load(const std::string &filename);
162 
167  void load(const std::string &filename, const FileSystem &file_system);
168 
173  void load(IODevice file, const std::string &base_path = std::string(), const FileSystem &file_system = FileSystem());
174 
178 private:
179 
183  XMLResourceDocument(std::weak_ptr<XMLResourceDocument_Impl> &impl);
184 
185  std::shared_ptr<XMLResourceDocument_Impl> impl;
186 
187  friend class XMLResourceNode;
188  friend class XMLResourceDocument_Impl;
190 };
191 
192 }
193 
I/O Device interface.
Definition: iodevice.h:51
Virtual File System (VFS).
Definition: file_system.h:48
XML Resource Document.
Definition: xml_resource_document.h:49
Resource node for a XMLResourceDocument.
Definition: xml_resource_node.h:47