xml_resource_document.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
30
31#include "../Resources/xml_resource_node.h"
32#include "../../Core/IOData/file_system.h"
33#include <vector>
34#include <memory>
35
36namespace clan
37{
40
41 class IODevice;
42 class XMLResourceNode;
43 class FileSystem;
44 class XMLResourceDocument_Impl;
45
48 {
49 public:
52
56 XMLResourceDocument(const std::string &filename);
57
62 XMLResourceDocument(const std::string &filename, FileSystem fs);
63
68 XMLResourceDocument(IODevice file, const std::string &base_path, FileSystem fs);
69
74
76
78 bool resource_exists(const std::string &resource_id) const;
79
81 std::vector<std::string> get_section_names() const;
82
84
85 std::vector<std::string> get_resource_names() const;
86
87 std::vector<std::string> get_resource_names(const std::string &section) const;
88
90
91 std::vector<std::string> get_resource_names_of_type(const std::string &type) const;
92
93 std::vector<std::string> get_resource_names_of_type(
94 const std::string &type,
95 const std::string &section) const;
96
99 const std::string &resource_id) const;
100
103 const std::string &resource_id,
104 bool default_value) const;
105
108 const std::string &resource_id,
109 int default_value) const;
110
113 const std::string &resource_id,
114 const std::string &default_value) const;
115
117
118 bool operator ==(const XMLResourceDocument &that) const;
119
121
123 void add_resources(const XMLResourceDocument& additional_resources);
124
126 void remove_resources(const XMLResourceDocument& additional_resources);
127
129 XMLResourceNode create_resource(const std::string &resource_id, const std::string &type);
130
132 void destroy_resource(const std::string &resource_id);
133
135 void save(const std::string &filename);
136
141 void save(const std::string &filename, const FileSystem &file_system);
142
146 void save(IODevice file);
147
149 void load(const std::string &filename);
150
155 void load(const std::string &filename, const FileSystem &file_system);
156
161 void load(IODevice file, const std::string &base_path = std::string(), const FileSystem &file_system = FileSystem());
162
163 private:
167 XMLResourceDocument(std::weak_ptr<XMLResourceDocument_Impl> &impl);
168
169 std::shared_ptr<XMLResourceDocument_Impl> impl;
170
171 friend class XMLResourceNode;
173 };
174
176}
Virtual File System (VFS).
Definition file_system.h:47
I/O Device interface.
Definition iodevice.h:50
void load(const std::string &filename)
Load resource XML tree from file.
XMLResourceDocument()
Construct a XMLResourceDocument.
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.
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)
void load(IODevice file, const std::string &base_path=std::string(), const FileSystem &file_system=FileSystem())
Load.
void save(const std::string &filename, const FileSystem &file_system)
Save.
XMLResourceDocument(const std::string &filename, FileSystem fs)
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)
std::vector< std::string > get_resource_names_of_type(const std::string &type, const std::string &section) const
void add_resources(const XMLResourceDocument &additional_resources)
Add resources from an other resource document.
XMLResourceDocument(IODevice file, const std::string &base_path, FileSystem fs)
Constructs a XMLResourceDocument.
void remove_resources(const XMLResourceDocument &additional_resources)
Remove resources from an other resource document.
std::vector< std::string > get_resource_names(const std::string &section) const
friend class XMLResourceDocument_Impl
Definition xml_resource_document.h:172
XMLResourceNode create_resource(const std::string &resource_id, const std::string &type)
Construct a new resource object.
XMLResourceNode get_resource(const std::string &resource_id) const
Returns Resource representing the given resource.
void save(IODevice file)
Save.
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.
std::vector< std::string > get_resource_names() const
Returns a list of all resources available.
XMLResourceDocument & operator=(const XMLResourceDocument &copy)
bool operator==(const XMLResourceDocument &that) const
XMLResourceDocument(const XMLResourceDocument &other)
Constructs a XMLResourceDocument.
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.
int get_integer_resource(const std::string &resource_id, int default_value) const
Returns the value of an integer resource. (using the value attribute)
friend class XMLResourceNode
Definition xml_resource_document.h:171
void save(const std::string &filename)
Save resource XML tree to file.
XMLResourceDocument(const std::string &filename)
Constructs a XMLResourceDocument.
Resource node for a XMLResourceDocument.
Definition xml_resource_node.h:46
Definition clanapp.h:36