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
48 class XMLResourceDocument
49 {
52 public:
54 XMLResourceDocument();
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
76 XMLResourceDocument(const XMLResourceDocument &other);
77
78 ~XMLResourceDocument();
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
105 XMLResourceNode get_resource(
106 const std::string &resource_id) const;
107
109 bool get_boolean_resource(
110 const std::string &resource_id,
111 bool default_value) const;
112
114 int get_integer_resource(
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:
127 XMLResourceDocument &operator =(const XMLResourceDocument &copy);
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;
187 friend class XMLResourceDocument_Impl;
189 };
190
191 }
192
clan
Definition: clanapp.h:35
clan::XMLResourceDocument::create_resource
XMLResourceNode create_resource(const std::string &resource_id, const std::string &type)
Construct a new resource object.
clan::XMLResourceDocument::destroy_resource
void destroy_resource(const std::string &resource_id)
Destroy resource object.
clan::IODevice
I/O Device interface.
Definition: iodevice.h:50
clan::XMLResourceDocument::load
void load(const std::string &filename)
Load resource XML tree from file.
clan::XMLResourceDocument::get_resource_names_of_type
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.
clan::XMLResourceDocument::get_resource_names
std::vector< std::string > get_resource_names() const
Returns a list of all resources available.
clan::XMLResourceDocument::get_resource
XMLResourceNode get_resource(const std::string &resource_id) const
Returns Resource representing the given resource.
clan::StyleTokenType::string
@ keyword
clan::XMLResourceDocument::save
void save(const std::string &filename)
Save resource XML tree to file.
clan::XMLResourceDocument::resource_exists
bool resource_exists(const std::string &resource_id) const
Returns true if a resource exists.
clan::FileSystem
Virtual File System (VFS).
Definition: file_system.h:47
clan::XMLResourceDocument::XMLResourceDocument
XMLResourceDocument()
Construct a XMLResourceDocument.
clan::XMLResourceDocument::~XMLResourceDocument
~XMLResourceDocument()
clan::XMLResourceDocument::get_boolean_resource
bool get_boolean_resource(const std::string &resource_id, bool default_value) const
Returns the value of a boolean resource. (using the value attribute)
clan::XMLResourceDocument::remove_resources
void remove_resources(const XMLResourceDocument &additional_resources)
Remove resources from an other resource document.
clan::XMLResourceDocument::operator=
XMLResourceDocument & operator=(const XMLResourceDocument &copy)
clan::XMLResourceDocument::get_integer_resource
int get_integer_resource(const std::string &resource_id, int default_value) const
Returns the value of an integer resource. (using the value attribute)
clan::XMLResourceDocument::get_section_names
std::vector< std::string > get_section_names() const
Returns all the resource sections available.
clan::XMLResourceDocument
XML Resource Document.
Definition: xml_resource_document.h:48
clan::XMLResourceDocument::add_resources
void add_resources(const XMLResourceDocument &additional_resources)
Add resources from an other resource document.
clan::XMLResourceDocument::get_string_resource
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)
clan::XMLResourceNode
Resource node for a XMLResourceDocument.
Definition: xml_resource_node.h:46
clan::XMLResourceDocument::XMLResourceDocument_Impl
friend class XMLResourceDocument_Impl
Definition: xml_resource_document.h:187
clan::XMLResourceDocument::operator==
bool operator==(const XMLResourceDocument &that) const