xml_resource_document.h Source File - ClanLib SDK
Description: xml_resource_document.h Source File

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
47 class XMLResourceDocument
48 {
49 public:
51 XMLResourceDocument();
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
73 XMLResourceDocument(const XMLResourceDocument &other);
74
75 ~XMLResourceDocument();
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
98 XMLResourceNode get_resource(
99 const std::string &resource_id) const;
100
102 bool get_boolean_resource(
103 const std::string &resource_id,
104 bool default_value) const;
105
107 int get_integer_resource(
108 const std::string &resource_id,
109 int default_value) const;
110
112 std::string get_string_resource(
113 const std::string &resource_id,
114 const std::string &default_value) const;
115
116 XMLResourceDocument &operator =(const XMLResourceDocument &copy);
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;
172 friend class XMLResourceDocument_Impl;
173 };
174
176}
clan::FileSystem
Virtual File System (VFS).
Definition file_system.h:47
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::XMLResourceDocument
XMLResourceDocument()
Construct a XMLResourceDocument.
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_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::XMLResourceDocument::load
void load(IODevice file, const std::string &base_path=std::string(), const FileSystem &file_system=FileSystem())
Load.
clan::XMLResourceDocument::save
void save(const std::string &filename, const FileSystem &file_system)
Save.
clan::XMLResourceDocument::XMLResourceDocument
XMLResourceDocument(const std::string &filename, FileSystem fs)
Constructs a 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::get_resource_names_of_type
std::vector< std::string > get_resource_names_of_type(const std::string &type, const std::string &section) const
clan::XMLResourceDocument::add_resources
void add_resources(const XMLResourceDocument &additional_resources)
Add resources from an other resource document.
clan::XMLResourceDocument::XMLResourceDocument
XMLResourceDocument(IODevice file, const std::string &base_path, FileSystem fs)
Constructs a XMLResourceDocument.
clan::XMLResourceDocument::remove_resources
void remove_resources(const XMLResourceDocument &additional_resources)
Remove resources from an other resource document.
clan::XMLResourceDocument::get_resource_names
std::vector< std::string > get_resource_names(const std::string &section) const
clan::XMLResourceDocument::XMLResourceDocument_Impl
friend class XMLResourceDocument_Impl
Definition xml_resource_document.h:172
clan::XMLResourceDocument::create_resource
XMLResourceNode create_resource(const std::string &resource_id, const std::string &type)
Construct a new resource object.
clan::XMLResourceDocument::get_resource
XMLResourceNode get_resource(const std::string &resource_id) const
Returns Resource representing the given resource.
clan::XMLResourceDocument::save
void save(IODevice file)
Save.
clan::XMLResourceDocument::load
void load(const std::string &filename, const FileSystem &file_system)
Load.
clan::XMLResourceDocument::get_section_names
std::vector< std::string > get_section_names() const
Returns all the resource sections available.
clan::XMLResourceDocument::get_resource_names
std::vector< std::string > get_resource_names() const
Returns a list of all resources available.
clan::XMLResourceDocument::operator=
XMLResourceDocument & operator=(const XMLResourceDocument &copy)
clan::XMLResourceDocument::operator==
bool operator==(const XMLResourceDocument &that) const
clan::XMLResourceDocument::XMLResourceDocument
XMLResourceDocument(const XMLResourceDocument &other)
Constructs a XMLResourceDocument.
clan::XMLResourceDocument::~XMLResourceDocument
~XMLResourceDocument()
clan::XMLResourceDocument::destroy_resource
void destroy_resource(const std::string &resource_id)
Destroy resource object.
clan::XMLResourceDocument::resource_exists
bool resource_exists(const std::string &resource_id) const
Returns true if a resource exists.
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::XMLResourceNode
friend class XMLResourceNode
Definition xml_resource_document.h:171
clan::XMLResourceDocument::save
void save(const std::string &filename)
Save resource XML tree to file.
clan::XMLResourceDocument::XMLResourceDocument
XMLResourceDocument(const std::string &filename)
Constructs a XMLResourceDocument.
clan::XMLResourceNode
Resource node for a XMLResourceDocument.
Definition xml_resource_node.h:46
clan
Definition clanapp.h:36