tmxparser  2.1.0
 All Classes Functions Variables Pages
TmxPropertySet.h
1 //-----------------------------------------------------------------------------
2 // TmxPropertySet.h
3 //
4 // Copyright (c) 2010-2014, Tamir Atias
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL TAMIR ATIAS BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Author: Tamir Atias
27 //-----------------------------------------------------------------------------
28 #pragma once
29 
30 #include <unordered_map>
31 #include <map>
32 #include <string>
33 
34 #include "TmxProperty.h"
35 
36 namespace tinyxml2 {
37  class XMLNode;
38 }
39 
40 namespace Tmx
41 {
42  class Property;
43 
44  //-----------------------------------------------------------------------------
46  //-----------------------------------------------------------------------------
48  {
49  public:
50  PropertySet();
51  ~PropertySet();
52 
54  void Parse(const tinyxml2::XMLNode *propertiesNode);
56  int GetIntProperty(const std::string &name, int defaultValue = 0) const;
58  float GetFloatProperty(const std::string &name, float defaultValue = 0.0f) const;
60  std::string GetStringProperty(const std::string &name, std::string defaultValue = "") const;
62  bool GetBoolProperty(const std::string &name, bool defaultValue = false) const;
64  Tmx::Color GetColorProperty(const std::string &name, Tmx::Color defaultValue = Tmx::Color()) const;
65 
67  int GetSize() const { return properties.size(); }
68 
70  bool HasProperty( const std::string& name ) const;
71 
73  const std::unordered_map< std::string, Property > &GetPropertyMap() const
74  { return properties; }
75 
78  std::map< std::string, std::string > GetList() const;
79 
81  bool Empty() const { return properties.empty(); }
82 
83  private:
84  std::unordered_map< std::string, Property > properties;
85 
86  };
87 }
bool Empty() const
Returns whether there are no properties.
Definition: TmxPropertySet.h:81
const std::unordered_map< std::string, Property > & GetPropertyMap() const
Returns the unordered map of properties.
Definition: TmxPropertySet.h:73
std::map< std::string, std::string > GetList() const
Returns the STL map of the properties.
Definition: TmxPropertySet.cpp:136
int GetSize() const
Returns the amount of properties.
Definition: TmxPropertySet.h:67
std::string GetStringProperty(const std::string &name, std::string defaultValue="") const
Get a string property.
Definition: TmxPropertySet.cpp:74
This class contains a map of properties.
Definition: TmxPropertySet.h:47
int GetIntProperty(const std::string &name, int defaultValue=0) const
Get a int property.
Definition: TmxPropertySet.cpp:84
Tmx::Color GetColorProperty(const std::string &name, Tmx::Color defaultValue=Tmx::Color()) const
Get a color property.
Definition: TmxPropertySet.cpp:120
bool HasProperty(const std::string &name) const
Checks if a property exists in the set.
Definition: TmxPropertySet.cpp:130
A class used for storing information about a color.
Definition: TmxColor.h:38
float GetFloatProperty(const std::string &name, float defaultValue=0.0f) const
Get a float property.
Definition: TmxPropertySet.cpp:96
void Parse(const tinyxml2::XMLNode *propertiesNode)
Parse a node containing all the property nodes.
Definition: TmxPropertySet.cpp:47
bool GetBoolProperty(const std::string &name, bool defaultValue=false) const
Get a bool property.
Definition: TmxPropertySet.cpp:108