tmxlite 1.0.0
lightweight parse for Tiled maps
Property.hpp
1/*********************************************************************
2Matt Marchant 2016 - 2021
3http://trederia.blogspot.com
4
5tmxlite - Zlib license.
6
7This software is provided 'as-is', without any express or
8implied warranty. In no event will the authors be held
9liable for any damages arising from the use of this software.
10
11Permission is granted to anyone to use this software for any purpose,
12including commercial applications, and to alter it and redistribute
13it freely, subject to the following restrictions:
14
151. The origin of this software must not be misrepresented;
16you must not claim that you wrote the original software.
17If you use this software in a product, an acknowledgment
18in the product documentation would be appreciated but
19is not required.
20
212. Altered source versions must be plainly marked as such,
22and must not be misrepresented as being the original software.
23
243. This notice may not be removed or altered from any
25source distribution.
26*********************************************************************/
27
28#pragma once
29
30#include <tmxlite/Config.hpp>
31#include <tmxlite/Types.hpp>
32
33#include <string>
34#include <cassert>
35#include <vector>
36
37namespace pugi
38{
39 class xml_node;
40}
41
42namespace tmx
43{
51 class TMXLITE_EXPORT_API Property final
52 {
53 public:
54
55 enum class Type
56 {
57 Boolean,
58 Float,
59 Int,
60 String,
61 Colour,
62 File,
63 Object,
64 Class,
65 Undef
66 };
67
68 Property();
69
70 static Property fromBoolean(bool value);
71 static Property fromFloat(float value);
72 static Property fromInt(int value);
73 static Property fromString(const std::string& value);
74 static Property fromColour(const Colour& value);
75 static Property fromFile(const std::string& value);
76 static Property fromObject(int value);
77
82 void parse(const pugi::xml_node&, bool isObjectTypes = false);
83
90 Type getType() const { return m_type; }
91
95 const std::string& getName() const { return m_name; }
96
100 bool getBoolValue() const { assert(m_type == Type::Boolean); return m_boolValue; }
101
105 float getFloatValue() const { assert(m_type == Type::Float); return m_floatValue; }
106
110 int getIntValue() const { assert(m_type == Type::Int || m_type == Type::Object); return m_intValue; }
111
115 const std::string& getStringValue() const { assert(m_type == Type::String); return m_stringValue; }
116
120 const Colour& getColourValue() const { assert(m_type == Type::Colour); return m_colourValue; }
121
125 const std::string& getFileValue() const { assert(m_type == Type::File); return m_stringValue; }
126
130 const std::vector<Property>& getClassValue() const {assert(m_type == Type::Class); return m_classValue; }
131
135 const std::string getPropertyType() const {assert(m_type == Type::Class); return m_propertyType; }
136
140 int getObjectValue() const { assert(m_type == Type::Object); return m_intValue; }
141
142
143 private:
144 union
145 {
146 bool m_boolValue;
147 float m_floatValue;
148 int m_intValue;
149 };
150 std::string m_stringValue;
151 std::string m_name;
152 std::string m_propertyType;
153
154 Colour m_colourValue;
155 std::vector<Property> m_classValue;
156
157 Type m_type;
158 };
159}
Objects are stored in ObjectGroup layers. Objects may be rectangular, elliptical, polygonal or a poly...
Definition Object.hpp:84
float getFloatValue() const
Returns the property's value as a float.
Definition Property.hpp:105
const std::vector< Property > & getClassValue() const
Returns an array of properties.
Definition Property.hpp:130
void parse(const pugi::xml_node &, bool isObjectTypes=false)
Attempts to parse the given node as a property.
bool getBoolValue() const
Returns the property's value as a boolean.
Definition Property.hpp:100
const std::string & getStringValue() const
Returns the property's value as a string.
Definition Property.hpp:115
const Colour & getColourValue() const
Returns the property's value as a Colour struct.
Definition Property.hpp:120
int getObjectValue() const
Returns the property's value as an integer object handle.
Definition Property.hpp:140
const std::string & getFileValue() const
Returns the file path property as a string, relative to the map file.
Definition Property.hpp:125
Type getType() const
Returns the type of data stored in the property. This should generally be called first before trying ...
Definition Property.hpp:90
int getIntValue() const
Returns the property's value as an integer.
Definition Property.hpp:110
const std::string & getName() const
Returns the name of this property.
Definition Property.hpp:95
const std::string getPropertyType() const
Returns an the propertytype value.
Definition Property.hpp:135
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition Types.hpp:111