ScummVM API documentation
loaders.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * This code is based on the CRAB engine
24 *
25 * Copyright (c) Arvind Raja Yadav
26 *
27 * Licensed under MIT
28 *
29 */
30
31#ifndef CRAB_LOADERS_H
32#define CRAB_LOADERS_H
33
34#include "common/debug.h"
35#include "common/path.h"
36#include "common/str.h"
37#include "crab/color.h"
38#include "crab/gametype.h"
39#include "crab/numstr.h"
40#include "crab/rapidxml/rapidxml.hpp"
41
42namespace Crab {
43
44// Function to check if node is valid
45// return true for valid, false otherwise
46bool nodeValid(rapidxml::xml_node<char> *node, const bool &echo = true);
47bool nodeValid(const Common::String &name, rapidxml::xml_node<char> *parentNode, const bool &echo = true);
48
49// Functions to load attributes from xml files
50// return true on success, false on failure
51bool loadStr(Common::String &val, const Common::String &name, rapidxml::xml_node<char> *node, const bool &echo = true);
52bool loadPath(Common::Path &val, const Common::String &name, rapidxml::xml_node<char> *node, const bool &echo = true);
53
54// Used for loading numerical types
55template<typename T>
56bool loadNum(T &val, const Common::String &name, rapidxml::xml_node<char> *node, const bool &echo = true) {
57 if (node->first_attribute(name.c_str()) != nullptr)
58 val = stringToNumber<T>(node->first_attribute(name.c_str())->value());
59 else {
60 if (echo)
61 warning("XML: attribute %s not found in node %s -> %s", name.c_str(), node->parent()->name(), node->name());
62 return false;
63 }
64
65 return true;
66}
67
68// Used for loading enumerator types that are integers
69template<typename T>
70bool loadEnum(T &val, const Common::String &name, rapidxml::xml_node<char> *node, const bool &echo = true) {
71 if (node->first_attribute(name.c_str()) != nullptr)
72 val = static_cast<T>(stringToNumber<int>(node->first_attribute(name.c_str())->value()));
73 else {
74 if (echo)
75 warning("XML: attribute %s not found in node %s -> %s", name.c_str(), node->parent()->name(), node->name());
76 return false;
77 }
78
79 return true;
80}
81
82//Load Color
83bool loadColor(Color &col, rapidxml::xml_node<char> *node, const bool &echo = true,
84 const Common::String &r_name = "r", const Common::String &g_name = "g", const Common::String &b_name = "b");
85
86//Shortcut to load integer color index to a number
87bool loadColor(int &col, rapidxml::xml_node<char> *node, const bool &echo = true);
88
89// Load two dimensional coordinates
90template<typename T>
91bool loadXY(T &x, T &y, rapidxml::xml_node<char> *node, const bool &echo = true) {
92 bool result = loadNum(x, "x", node, echo);
93 result = loadNum(y, "y", node, echo) && result;
94
95 return result;
96}
97
98// Load three dimensional coordinates
99template<typename T>
100bool loadXYZ(T &x, T &y, T &z, rapidxml::xml_node<char> *node, const bool &echo = true) {
101 bool result = loadNum(x, "x", node, echo);
102 result = loadNum(y, "y", node, echo) && result;
103 result = loadNum(z, "z", node, echo) && result;
104
105 return result;
106}
107
108// Load Boolean variable
109bool loadBool(bool &var, const Common::String &name, rapidxml::xml_node<char> *node, const bool &echo = true);
110
111// Write Boolean variable to file
112void saveBool(const bool &var, const char *name, rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root);
113
114// Functions to load various type of objects
115bool loadStatType(pyrodactyl::stat::StatType &type, rapidxml::xml_node<char> *node, const bool &echo = true);
116
117bool loadAlign(Align &align, rapidxml::xml_node<char> *node, const bool &echo = true, const Common::String &name = "align");
118bool loadDirection(Direction &dir, rapidxml::xml_node<char> *node, const bool &echo = true, const Common::String &name = "dir");
119
120bool loadTextureFlipType(TextureFlipType &flip, rapidxml::xml_node<char> *node, const bool &echo = true);
121
122// Check the version of a file
123uint version(const Common::Path &filename);
124
125} // End of namespace Crab
126
127#endif // CRAB_LOADERS_H
Definition: path.h:52
Definition: str.h:59
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1