xml_resource_document.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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 "../Resources/xml_resource_node.h"
33 #include "../IOData/file_system.h"
34 #include <vector>
35 #include <memory>
36 
37 namespace clan
38 {
41 
42 class IODevice;
43 class XMLResourceNode;
44 class FileSystem;
45 class XMLResourceDocument_Impl;
46 
49 {
52 public:
55 
59  XMLResourceDocument(const std::string &filename);
60 
65  XMLResourceDocument(const std::string &filename, FileSystem fs);
66 
71  XMLResourceDocument(IODevice file, const std::string &base_path, FileSystem fs);
72 
77 
79 
83 public:
85  bool resource_exists(const std::string &resource_id) const;
86 
88  std::vector<std::string> get_section_names() const;
89 
91 
92  std::vector<std::string> get_resource_names() const;
93 
94  std::vector<std::string> get_resource_names(const std::string &section) const;
95 
97 
98  std::vector<std::string> get_resource_names_of_type(const std::string &type) const;
99 
100  std::vector<std::string> get_resource_names_of_type(
101  const std::string &type,
102  const std::string &section) const;
103 
106  const std::string &resource_id) const;
107 
110  const std::string &resource_id,
111  bool default_value) const;
112 
115  const std::string &resource_id,
116  int default_value) const;
117 
119  std::string get_string_resource(
120  const std::string &resource_id,
121  const std::string &default_value) const;
122 
126 public:
128 
129  bool operator ==(const XMLResourceDocument &that) const;
130 
132 
134  void add_resources(const XMLResourceDocument& additional_resources);
135 
137  void remove_resources(const XMLResourceDocument& additional_resources);
138 
140  XMLResourceNode create_resource(const std::string &resource_id, const std::string &type);
141 
143  void destroy_resource(const std::string &resource_id);
144 
146  void save(const std::string &filename);
147 
152  void save(const std::string &filename, const FileSystem &file_system);
153 
157  void save(IODevice file);
158 
160  void load(const std::string &filename);
161 
166  void load(const std::string &filename, const FileSystem &file_system);
167 
172  void load(IODevice file, const std::string &base_path = std::string(), const FileSystem &file_system = FileSystem());
173 
177 private:
178 
182  XMLResourceDocument(std::weak_ptr<XMLResourceDocument_Impl> &impl);
183 
184  std::shared_ptr<XMLResourceDocument_Impl> impl;
185 
186  friend class XMLResourceNode;
189 };
190 
191 }
192 
std::string get_string_resource(const std::string &resource_id, const std::string &default_value) const
Returns the value of an string resource. (using the value attribute)
std::vector< std::string > get_resource_names_of_type(const std::string &type) const
Returns a list of all resources available matching a given type.
void load(const std::string &filename, const FileSystem &file_system)
Load.
std::vector< std::string > get_section_names() const
Returns all the resource sections available.
int get_integer_resource(const std::string &resource_id, int default_value) const
Returns the value of an integer resource. (using the value attribute)
Resource node for a XMLResourceDocument.
Definition: xml_resource_node.h:47
XMLResourceDocument()
Construct a XMLResourceDocument.
XMLResourceNode create_resource(const std::string &resource_id, const std::string &type)
Construct a new resource object.
std::vector< std::string > get_resource_names() const
Returns a list of all resources available.
bool operator==(const XMLResourceDocument &that) const
I/O Device interface.
Definition: iodevice.h:51
std::vector< std::string > get_resource_names(const std::string &section) const
XMLResourceDocument(const XMLResourceDocument &other)
Constructs a XMLResourceDocument.
bool get_boolean_resource(const std::string &resource_id, bool default_value) const
Returns the value of a boolean resource. (using the value attribute)
void load(const std::string &filename)
Load resource XML tree from file.
XMLResourceNode get_resource(const std::string &resource_id) const
Returns Resource representing the given resource.
XMLResourceDocument & operator=(const XMLResourceDocument &copy)
XMLResourceDocument(IODevice file, const std::string &base_path, FileSystem fs)
Constructs a XMLResourceDocument.
void add_resources(const XMLResourceDocument &additional_resources)
Add resources from an other resource document.
void destroy_resource(const std::string &resource_id)
Destroy resource object.
bool resource_exists(const std::string &resource_id) const
Returns true if a resource exists.
friend class XMLResourceDocument_Impl
Definition: xml_resource_document.h:187
void save(IODevice file)
Save.
void save(const std::string &filename)
Save resource XML tree to file.
std::vector< std::string > get_resource_names_of_type(const std::string &type, const std::string &section) const
XMLResourceDocument(const std::string &filename, FileSystem fs)
Constructs a XMLResourceDocument.
void load(IODevice file, const std::string &base_path=std::string(), const FileSystem &file_system=FileSystem())
Load.
Definition: clanapp.h:36
void save(const std::string &filename, const FileSystem &file_system)
Save.
Virtual File System (VFS).
Definition: file_system.h:48
XML Resource Document.
Definition: xml_resource_document.h:49
void remove_resources(const XMLResourceDocument &additional_resources)
Remove resources from an other resource document.
XMLResourceDocument(const std::string &filename)
Constructs a XMLResourceDocument.