Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
XMLParser.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_XML_PARSER_H_
34#define DVD_XML_PARSER_H_
35
37
38namespace Divide
39{
40
41 class Scene;
42 class GFXDevice;
43 class SceneGraphNode;
44 class PlatformContext;
45
46 struct Configuration;
47
48 FWD_DECLARE_MANAGED_CLASS( Material );
49
50 namespace XML
51 {
52 namespace detail
53 {
54 struct LoadSave
55 {
56 mutable boost::property_tree::iptree XmlTree;
57 std::string _rootNodePath;
58 std::string _fileName;
60
61 [[nodiscard]] bool read( const ResourcePath& filePath, const char* fileName, const std::string& rootNode );
62 [[nodiscard]] bool write( const ResourcePath& filePath, const char* fileName ) const;
63 };
64 }
65
66#ifndef GET_PARAM
67#define CONCAT(first, second) first second
68
69#define GET_PARAM(X) GET_TEMP_PARAM(X, X)
70
71#define GET_TEMP_PARAM(X, TEMP) \
72 TEMP = LoadSave.XmlTree.get(LoadSave._rootNodePath + TO_STRING(X), TEMP)
73
74#define GET_PARAM_ATTRIB(X, Y) \
75 X.Y = LoadSave.XmlTree.get(CONCAT(CONCAT(LoadSave._rootNodePath + TO_STRING(X), ".<xmlattr>."), TO_STRING(Y)), (X.Y))
76
77#define PUT_TEMP_PARAM(X, TEMP) \
78 LoadSave.XmlTree.put(LoadSave._rootNodePath + TO_STRING(X), TEMP)
79#define PUT_PARAM_ATTRIB(X, Y) \
80 LoadSave.XmlTree.put(CONCAT(CONCAT(LoadSave._rootNodePath + TO_STRING(X), ".<xmlattr>."), TO_STRING(Y)), (X.Y))
81#endif
82
83#define PUT_PARAM(X) PUT_TEMP_PARAM(X, X)
84
86 {
87 public:
88 virtual ~IXMLSerializable() = default;
89
90 protected:
91 friend bool loadFromXML( IXMLSerializable& object, const ResourcePath& filePath, const char* fileName );
92 friend bool saveToXML( const IXMLSerializable& object, const ResourcePath& filePath, const char* fileName );
93
94 virtual bool fromXML( const ResourcePath& xmlFilePath, const char* fileName ) = 0;
95 virtual bool toXML( const ResourcePath& xmlFilePath, const char* fileName ) const = 0;
96
98 };
99
100 bool loadFromXML( IXMLSerializable& object, const ResourcePath& filePath, const char* fileName );
101 bool saveToXML( const IXMLSerializable& object, const ResourcePath& filePath, const char* fileName );
102
103 void writeXML( const ResourcePath& path, const boost::property_tree::ptree& tree );
104 void readXML( const ResourcePath& path, boost::property_tree::ptree& tree );
106 void loadDefaultKeyBindings( const ResourcePath& file, const Scene* scene );
107 void loadMusicPlaylist( const ResourcePath& scenePath, const Str<64>& fileName, Scene* scene, [[maybe_unused]] const Configuration& config );
108
110 {
113
115 };
116
117 } // namespace XML
118} // namespace Divide
119
120#endif //DVD_XML_PARSER_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
detail::LoadSave LoadSave
Definition: XMLParser.h:97
virtual ~IXMLSerializable()=default
virtual bool toXML(const ResourcePath &xmlFilePath, const char *fileName) const =0
friend bool loadFromXML(IXMLSerializable &object, const ResourcePath &filePath, const char *fileName)
Definition: XMLParser.cpp:18
friend bool saveToXML(const IXMLSerializable &object, const ResourcePath &filePath, const char *fileName)
Definition: XMLParser.cpp:23
virtual bool fromXML(const ResourcePath &xmlFilePath, const char *fileName)=0
bool loadFromXML(IXMLSerializable &object, const ResourcePath &filePath, const char *fileName)
Definition: XMLParser.cpp:18
bool saveToXML(const IXMLSerializable &object, const ResourcePath &filePath, const char *fileName)
Definition: XMLParser.cpp:23
void loadDefaultKeyBindings(const ResourcePath &file, const Scene *scene)
Child Functions.
Definition: XMLParser.cpp:174
void loadMusicPlaylist(const ResourcePath &scenePath, const Str< 64 > &fileName, Scene *scene, const Configuration &config)
Definition: XMLParser.cpp:235
void writeXML(const ResourcePath &path, const boost::property_tree::ptree &tree)
void readXML(const ResourcePath &path, boost::property_tree::ptree &tree)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
eastl::vector< Type > vector
Definition: Vector.h:42
uint64_t U64
vector< SceneNode > children
Definition: XMLParser.h:114
bool write(const ResourcePath &filePath, const char *fileName) const
Definition: XMLParser.cpp:78
boost::property_tree::iptree XmlTree
Definition: XMLParser.h:56
bool read(const ResourcePath &filePath, const char *fileName, const std::string &rootNode)
Definition: XMLParser.cpp:35