All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Properties.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file Properties.h
22 
23  \brief The Properties class represents a persistent set of properties. The Properties can be saved to a file (Ex.: .json) or loaded from a file (Ex.: .json).
24  Also used for interaction, with user or other classes of this module, to change state of a MVC Component.
25 
26  \ingroup layout
27 */
28 
29 #ifndef __TERRALIB_LAYOUT_INTERNAL_PROPERTIES_H
30 #define __TERRALIB_LAYOUT_INTERNAL_PROPERTIES_H
31 
32 //Terralib
33 #include "Property.h"
34 #include "../enum/AbstractType.h"
35 #include "../Config.h"
36 #include "../enum/EnumType.h"
37 
38 //STL
39 #include <vector>
40 #include <algorithm>
41 
42 namespace te
43 {
44  namespace layout
45  {
46  /*!
47  \brief The Properties class represents a persistent set of properties. The Properties can be saved to a file (Ex.: .json) or loaded from a file (Ex.: .json).
48  Also used for interaction, with user or other classes of this module, to change state of a MVC Component.
49 
50  \ingroup layout
51  */
53  {
54  public:
55 
56  /*!
57  \brief Constructor
58 
59  \param objectName Object name that owns these properties
60  \param type Object type that owns these properties
61  */
62  Properties(std::string objectName, EnumType* type = 0, int hashCode = 0);
63 
64  /*!
65  \brief Destructor
66  */
67  virtual ~Properties(void);
68 
69  /*!
70  \brief Adds the specified property to the set of properties for this object.
71 
72  \param property specified property
73  \return true if add, false otherwise
74  */
75  virtual bool addProperty(Property property);
76 
77  /*!
78  \brief Removes a property from the set of properties of this object.
79 
80  \param property specified property
81  \return true if remove, false otherwise
82  */
83  virtual bool removeProperty(std::string name);
84 
85  /*!
86  \brief Clear set of properties of this object.
87 
88  \return true if clear, false otherwise
89  */
90  virtual bool clear();
91 
92  /*!
93  \brief Returns set of all properties
94 
95  \return set of all properties
96  */
97  virtual std::vector<Property> getProperties();
98 
99  /*!
100  \brief Returns object name that owns these properties.
101 
102  \return object name that owns these properties
103  */
104  virtual std::string getObjectName();
105 
106  /*!
107  \brief Sets object name that owns these properties.
108 
109  \param object name that owns these properties
110  */
111  virtual void setObjectName(std::string name);
112 
113  /*!
114  \brief Returns object type that owns these properties.
115 
116  \return object type that owns these properties
117  */
118  virtual EnumType* getTypeObj();
119 
120  /*!
121  \brief Sets object type that owns these properties.
122 
123  \param object type that owns these properties
124  */
125  virtual void setTypeObj(EnumType* type);
126 
127  /*!
128  \brief
129 
130  \param
131  */
132  virtual void setHasWindows(bool windows);
133 
134  /*!
135  \brief
136 
137  \return
138  */
139  virtual bool hasWindows();
140 
141  /*!
142  \brief Checks if the property is contained within the set of properties.
143 
144  \param property
145  \return true if contained, false otherwise
146  */
147  virtual bool contains(Property property);
148 
149  /*!
150  \brief Checks if the name is contained within the set of properties.
151 
152  \param name name of the property
153  \return true if contained, false otherwise
154  */
155  virtual Property contains(std::string name);
156 
157  /*!
158  \brief Returns the hashcode of a MVC component.
159 
160  \return hashCode
161  */
162  virtual int getHashCode();
163 
164  /*!
165  \brief Sets the hashcode of a MVC component.
166 
167  \return hashCode
168  */
169  virtual void setHashCode(int hashCode);
170 
171  protected:
172 
173  std::vector<Property> m_properties; //!< set of properties for this object
174  std::string m_objName; //!< Object name that owns these properties
175  EnumType* m_typeObj; //!< Object type that owns these properties
176  bool m_hasWindows; //!<
178 
179  };
180 
181  inline Properties::Properties(std:: string objectName, te::layout::EnumType* type, int hashCode) :
182  m_objName(objectName),
183  m_typeObj(type),
184  m_hasWindows(false),
185  m_hashcode(hashCode)
186  {
187  }
188 
189  inline Properties::~Properties( void )
190  {
191  }
192 
193  inline bool Properties::addProperty(Property property)
194  {
195  unsigned int total = m_properties.size();
196  m_properties.push_back(property);
197 
198  if(m_properties.size() > total)
199  return true;
200  return false;
201  }
202 
203 
204  inline bool Properties::removeProperty(std::string name)
205  {
206  bool result = false;
207 
208  for(std::vector<Property>::iterator it = m_properties.begin(); it != m_properties.end(); it++)
209  {
210  if((*it).getName().compare(name) == 0)
211  {
212  m_properties.erase(it);
213  result = true;
214  break;
215  }
216  }
217  return result;
218  }
219 
220  inline std::vector<Property> Properties::getProperties()
221  {
222  return m_properties;
223  }
224 
225  inline bool Properties::clear()
226  {
227  m_properties.clear();
228  return m_properties.empty();
229  }
230 
231  inline std::string Properties::getObjectName()
232  {
233  return m_objName;
234  }
235 
236  inline void Properties::setObjectName( std::string name )
237  {
238  m_objName = name;
239  }
240 
242  {
243  return m_typeObj;
244  }
245 
247  {
248  m_typeObj = type;
249  }
250 
251  inline bool Properties::contains( Property property )
252  {
253  bool is_present = false;
254 
255  if(std::find(m_properties.begin(), m_properties.end(), property) != m_properties.end())
256  {
257  is_present = true;
258  }
259 
260  return is_present;
261  }
262 
263  inline te::layout::Property Properties::contains( std::string name )
264  {
265  Property property(0);
266  property.setName(name);
267 
268  if(std::find(m_properties.begin(), m_properties.end(), property) != m_properties.end())
269  {
270  std::vector<Property>::iterator it = std::find(m_properties.begin(), m_properties.end(), property);
271 
272  property = (*it);
273  }
274  else
275  property.setName("");
276 
277  return property;
278  }
279 
280  inline void te::layout::Properties::setHasWindows( bool windows )
281  {
282  m_hasWindows = windows;
283  }
284 
286  {
287  return m_hasWindows;
288  }
289 
291  {
292  return m_hashcode;
293  }
294 
295  inline void te::layout::Properties::setHashCode( int hashCode )
296  {
297  m_hashcode = hashCode;
298  }
299  }
300 }
301 
302 #endif
virtual int getHashCode()
Returns the hashcode of a MVC component.
Definition: Properties.h:290
Properties(std::string objectName, EnumType *type=0, int hashCode=0)
Constructor.
Definition: Properties.h:181
virtual bool addProperty(Property property)
Adds the specified property to the set of properties for this object.
Definition: Properties.h:193
virtual bool hasWindows()
Definition: Properties.h:285
#define TELAYOUTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:99
virtual ~Properties(void)
Destructor.
Definition: Properties.h:189
std::string m_objName
Object name that owns these properties.
Definition: Properties.h:174
virtual void setHashCode(int hashCode)
Sets the hashcode of a MVC component.
Definition: Properties.h:295
virtual bool removeProperty(std::string name)
Removes a property from the set of properties of this object.
Definition: Properties.h:204
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
Definition: Properties.h:52
virtual std::vector< Property > getProperties()
Returns set of all properties.
Definition: Properties.h:220
virtual void setObjectName(std::string name)
Sets object name that owns these properties.
Definition: Properties.h:236
std::vector< Property > m_properties
set of properties for this object
Definition: Properties.h:173
virtual void setTypeObj(EnumType *type)
Sets object type that owns these properties.
Definition: Properties.h:246
virtual EnumType * getTypeObj()
Returns object type that owns these properties.
Definition: Properties.h:241
virtual std::string getObjectName()
Returns object name that owns these properties.
Definition: Properties.h:231
EnumType * m_typeObj
Object type that owns these properties.
Definition: Properties.h:175
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
Definition: EnumType.h:48
virtual bool clear()
Clear set of properties of this object.
Definition: Properties.h:225
virtual void setHasWindows(bool windows)
Definition: Properties.h:280
virtual bool contains(Property property)
Checks if the property is contained within the set of properties.
Definition: Properties.h:251
A property acts like a attribute member of a object and stores the state of this attribute. A set of properties stores the state of an object. Any data type, not included in the convertValue method in the class te::layout::Variant, it will be by default "std::string" value.
Definition: Property.h:47