Loading...
Searching...
No Matches
CompositeProperty.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 terralib/datatype/CompositeProperty.h
22
23 \brief A base class for a compound properties (non-atomic properties).
24*/
25
26#ifndef __TERRALIB_DATATYPE_INTERNAL_COMPOSITEPROPERTY_H
27#define __TERRALIB_DATATYPE_INTERNAL_COMPOSITEPROPERTY_H
28
29// TerraLib
30#include "Property.h"
31
32// STL
33#include <vector>
34
35// Boost
36#include <boost/ptr_container/ptr_vector.hpp>
37
38namespace te
39{
40 namespace dt
41 {
42 /*!
43 \class CompositeProperty
44
45 \brief A base class for a compound property (non-atomic properties).
46
47 \ingroup datatype
48
49 \sa Property, SimpleProperty, NumericProperty, StringProperty, ArrayProperty, DateTimeProperty
50 */
52 {
53 public:
54
55 /*!
56 \brief It creates a new CompositeProperty.
57
58 \param cname The composite type name.
59 \param name The property name.
60 \param id The property identifier.
61 \param parent A reference to the parent Property of the new object if it has one.
62
63 \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
64 */
65 CompositeProperty(const std::string& cname,
66 const std::string& name,
67 unsigned int id = 0,
68 Property* parent = 0);
69
70 /*!
71 \brief Copy constructor.
72
73 \param rhs The right-hand-side copy used to copy from.
74 */
76
77 /*! \brief Virtual destructor. */
79
80 /*!
81 \brief Assignment operator.
82
83 \param rhs The right-hand-side copy used to copy from.
84
85 \return A reference to this object.
86 */
88
89 /*!
90 \brief It returns the name of the composite type.
91
92 \return The name of the composite type.
93
94 \note This name may be different from the property name (returned by getName method)!
95 */
96 const std::string& getCompositeName() const { return m_cname; }
97
98 /*!
99 \brief It sets the composite type name.
100
101 \param name The composite type name.
102 */
103 void setCompositeName(const std::string& cname) { m_cname = cname; }
104
105 /*!
106 \brief It adds a new property to the CompositeProperty.
107
108 \param p The property to be inserted.
109
110 \pre The Property p must be valid.
111 \pre The Property p must not be associated to another property.
112
113 \post The property p will be associated to CompositeProperty.
114 \post The CompositeProperty takes the ownership of the property.
115 */
116 void add(Property* p);
117
118 /*!
119 \brief It adds a list of property types to the CompositeProperty.
120
121 \param ps The list of properties to be added.
122
123 \pre The properties must be valid.
124 \pre The properties must not be associated to another property.
125
126 \note The CompositeProperty takes the ownership of the properties.
127 */
128 void add(const std::vector<Property*>& ps);
129
130 void add(const boost::ptr_vector<te::dt::Property>& ps);
131
132 /*!
133 \brief It inserts a new property to the CompositeProperty.
134
135 \param position The position where the property will be inserted
136 \param p The property to be inserted.
137
138 \pre The Property p must be valid.
139 \pre The Property p must not be associated to another property.
140
141 \post The property p will be associated to CompositeProperty.
142 \post The CompositeProperty takes the ownership of the property.
143 */
144 void insert(std::size_t position, Property* p);
145
146 /*!
147 \brief It removes the property from the composite.
148
149 \param p The property to be removed from the composite.
150
151 \post The property pointer will be invalidated.
152 */
153 virtual void remove(Property* p);
154
155 /*!
156 \brief It returns the number of properties of the CompositeProperty.
157
158 \return The number of properties of the CompositeProperty.
159 */
160 std::size_t size() const { return m_properties.size(); }
161
162 /*!
163 \brief It returns the list of properties describing the CompositeProperty.
164
165 \return The list of Propertys describing the CompositeProperty.
166 */
167 const std::vector<Property*>& getProperties() const { return m_properties; }
168
169 /*!
170 \brief It returns the list of properties describing the CompositeProperty.
171
172 \return The list of Propertys describing the CompositeProperty.
173 */
174 std::vector<Property*>& getProperties() { return m_properties; }
175
176 /*!
177 \brief It returns the i-th property.
178
179 \param i The property position in the property array.
180
181 \return A pointer to the i-th property. Don't delete it, as it belongs to the CompositeProperty.
182
183 \pre i must be in the valid range [0, size()).
184 */
185 Property* getProperty(std::size_t i) const { return m_properties[i]; }
186
187 /*!
188 \brief It returns the property with the given name or NULL if none is found.
189
190 \param name The name of the property we are looking for.
191
192 \return A pointer to a property or NULL if none is found. Don't delete it, as it belongs to the CompositeProperty.
193 */
194 Property* getProperty(const std::string& name) const;
195
196 /*!
197 \brief It returns the property position based on its name.
198
199 \param name The property name.
200
201 \return A property position in the property array.
202 */
203 std::size_t getPropertyPosition(const std::string& name) const;
204
205 /*!
206 \brief It returns the property position .
207
208 \param p The property.
209
210 \return A property position in the property array.
211 */
212 std::size_t getPropertyPosition(const Property* p) const;
213
214 /*!
215 \brief It searches for a property with the given ID.
216
217 \param id The property ID.
218
219 \return A pointer to the first property with the given ID if found or NULL otherwise. Don't delete it, as it belongs to the CompositeProperty.
220 */
221 Property* getPropertyById(unsigned int id) const;
222
223 /*!
224 \brief Tells if there is a property of the given data type.
225 */
226 bool hasPropertyOfType(const int t) const;
227
228 /*!
229 \brief returns the first property of the given data type. Caller doesn't take ownership of the returned pointer.
230 */
231 Property* findFirstPropertyOfType(const int t) const;
232
233 /*!
234 \brief It copies the properties from the vector.
235
236 \param ps The list of properties to be copied.
237
238 \note The CompositeProperty will not take the ownership of the properties, it will clone each one.
239 So, it is the caller responsability to release them.
240 */
241 void copy(const std::vector<Property*>& ps);
242
243 /*! \brief It clears the CompositeProperty definition. */
244 virtual void clear();
245
246 /*!
247 \brief It checks if the Property "p" is associated to this property or any other parent.
248
249 \param p The Property we are checking.
250
251 \return True if the given Property "p" is associated to to this Property, otherwise, returns false.
252 */
253 bool has(Property* p) const;
254
255 /*!
256 \brief It returns a clone of the object.
257
258 The new property will NOT have associations to other elements.
259
260 \return A clone of the object.
261 */
262 virtual Property* clone() const;
263
264 protected:
265
266 /*!
267 \brief It creates a new Property.
268
269 \param cname The composite type name.
270 \param name The Property name.
271 \param t The data type id.
272 \param id The property identifier.
273 \param parent A reference to the parent Property of the new object if it has one.
274 */
275 CompositeProperty(const std::string& cname,
276 const std::string& name,
277 int t,
278 unsigned int id,
279 Property* parent);
280
281 protected:
282
283 std::string m_cname; //!< The composite type name.
284 std::vector<Property*> m_properties; //!< The list of property types that make the CompositeProperty.
285 };
286
287 inline bool CompositeProperty::hasPropertyOfType(const int t) const
288 {
289 return findFirstPropertyOfType(t) != 0;
290 }
291
293 {
294 const std::size_t size = m_properties.size();
295
296 for(std::size_t i = 0; i != size; ++i)
297 if(m_properties[i]->getType() == t)
298 return m_properties[i];
299
300 return 0;
301 }
302
303 } // end namespace dt
304} // end namespace te
305
306
307#endif // __TERRALIB_DATATYPE_INTERNAL_COMPOSITEPROPERTY_H
308
309
It models a property definition.
A base class for a compound property (non-atomic properties).
Property * findFirstPropertyOfType(const int t) const
returns the first property of the given data type. Caller doesn't take ownership of the returned poin...
CompositeProperty(const std::string &cname, const std::string &name, unsigned int id=0, Property *parent=0)
It creates a new CompositeProperty.
CompositeProperty(const std::string &cname, const std::string &name, int t, unsigned int id, Property *parent)
It creates a new Property.
virtual void remove(Property *p)
It removes the property from the composite.
CompositeProperty & operator=(const CompositeProperty &rhs)
Assignment operator.
void copy(const std::vector< Property * > &ps)
It copies the properties from the vector.
std::size_t getPropertyPosition(const Property *p) const
It returns the property position .
const std::string & getCompositeName() const
It returns the name of the composite type.
void add(const std::vector< Property * > &ps)
It adds a list of property types to the CompositeProperty.
bool has(Property *p) const
It checks if the Property "p" is associated to this property or any other parent.
CompositeProperty(const CompositeProperty &rhs)
Copy constructor.
std::vector< Property * > m_properties
The list of property types that make the CompositeProperty.
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
std::string m_cname
The composite type name.
bool hasPropertyOfType(const int t) const
Tells if there is a property of the given data type.
void add(const boost::ptr_vector< te::dt::Property > &ps)
Property * getPropertyById(unsigned int id) const
It searches for a property with the given ID.
std::vector< Property * > & getProperties()
It returns the list of properties describing the CompositeProperty.
Property * getProperty(std::size_t i) const
It returns the i-th property.
std::size_t size() const
It returns the number of properties of the CompositeProperty.
virtual Property * clone() const
It returns a clone of the object.
Property * getProperty(const std::string &name) const
It returns the property with the given name or NULL if none is found.
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
void add(Property *p)
It adds a new property to the CompositeProperty.
virtual ~CompositeProperty()
Virtual destructor.
void insert(std::size_t position, Property *p)
It inserts a new property to the CompositeProperty.
void setCompositeName(const std::string &cname)
It sets the composite type name.
virtual void clear()
It clears the CompositeProperty definition.
It models a property definition.
Definition: Property.h:60
int getType() const
It returns the property data type.
Definition: Property.h:161
TerraLib.
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61