All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Property.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/Property.h
22 
23  \brief It models a property definition.
24 */
25 
26 #ifndef __TERRALIB_DATATYPE_INTERNAL_PROPERTY_H
27 #define __TERRALIB_DATATYPE_INTERNAL_PROPERTY_H
28 
29 // TerraLib
30 #include "Config.h"
31 #include "Enums.h"
32 
33 // STL
34 #include <map>
35 #include <string>
36 
37 namespace te
38 {
39  namespace dt
40  {
41  /*!
42  \class Property
43 
44  \brief It models a property definition.
45 
46  The class Property defines information about the values of a given property.
47  This includes:
48  <ul>
49  <li>The data type associated to the property;</li>
50  <li>Any restrictions on the values of the property;</li>
51  </ul>
52 
53  \ingroup datatype
54 
55  \sa SimpleProperty, CompositeProperty, NumericProperty, StringProperty, DateTimeProperty
56 
57  \todo We must worry about write methods. To make classes safer we need to define pure abstract classes and implement them in the drivers.
58  */
60  {
61  public:
62 
63  /*!
64  \brief It initializes a new Property.
65 
66  \param name The Property name.
67  \param datatype The property data type.
68  \param id The property identifier.
69  \param parent A reference to the parent Property of the new object.
70 
71  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
72  */
73  Property(const std::string& name,
74  int datatype,
75  unsigned int id = 0,
76  Property* parent = 0,
77  const std::string& dsName = "");
78 
79  /*!
80  \brief Copy constructor.
81 
82  \param rhs The right-hand-side copy used to copy from.
83 
84  \note Copy constructor doesn't preserve parent relationship.
85  */
86  Property(const Property& rhs);
87 
88  /*! \brief Virtual destructor. */
89  virtual ~Property() {}
90 
91  /*!
92  \brief Assignment operator.
93 
94  \param rhs The right-hand-side copy used to copy from.
95 
96  \return A reference to this object.
97 
98  \note Assignment operator doesn't preserve parent relationship.
99  */
100  Property& operator=(const Property& rhs);
101 
102  /*!
103  \brief It returns the property identifier.
104 
105  \return A number used to identify the property.
106 
107  \warning The identifier value may be used by data source implementations. So, don't rely on its value!
108  */
109  unsigned int getId() const { return m_id; }
110 
111  /*!
112  \brief It sets the property identifier.
113 
114  \param id A number used to identify the property.
115 
116  \warning The identifier value may be used by data source implementations. So, don't rely on its value!
117  */
118  void setId(unsigned int id) { m_id = id; }
119 
120  /*!
121  \brief It returns the property name.
122 
123  \return The property name.
124 
125  \note For DataSetTypes the name can have namespace prefix or schema name prefix, it will depend on the data source implementation.
126  */
127  const std::string& getName() const { return m_name; }
128 
129  /*!
130  \brief It sets the property name.
131 
132  \param name The new property name.
133 
134  \warning Take care when calling this method for a DataSetType associated to a DataSourceCatalog.
135  Prefer using the rename method on the DataSourceCatalog API instead of using this method.
136  */
137  void setName(const std::string& name) { m_name = name; }
138 
139  /*!
140  \brief It returns the name of the propery's dataset.
141 
142  \return The the propery's dataset name.
143  */
144  const std::string& getDatasetName() const { return m_datasetName; }
145 
146  /*!
147  \brief It sets the property name.
148 
149  \param name The new property name.
150 
151  \warning Take care when calling this method for a DataSetType associated to a DataSourceCatalog.
152  Prefer using the rename method on the DataSourceCatalog API instead of using this method.
153  */
154  void setDatasetName(const std::string& dsName) { m_datasetName = dsName; }
155 
156  /*!
157  \brief It returns the property data type.
158 
159  \return The property data type.
160  */
161  int getType() const { return m_type; }
162 
163  /*!
164  \brief It returns the parent of this property, or NULL, if it doesn't have one.
165 
166  \return The parent of this property, or NULL, if it doesn't have one.
167  */
168  Property* getParent() const { return m_parent; }
169 
170  /*!
171  \brief It associate this property to the informed parent.
172 
173  \param p Teh parent property.
174 
175  \warning Don't use this method without knowing the internal details of its use.
176  */
177  void setParent(Property* p) { m_parent = p; }
178 
179  /*!
180  \brief It checks if the Property "p" is associated to this property or any other parent.
181 
182  This method can be used to ask if a given Property belongs
183  to a more complex type (like: CompositeProperty or DataSetType).
184 
185  \param p The Property we are checking.
186 
187  \return True if the given Property "p" is associated to to this Property, otherwise, returns false.
188  */
189  virtual bool has(Property* p) const = 0;
190 
191  /*!
192  \brief It returns a clone of the object.
193 
194  The new Property may not have associations to other elements.
195  For example, a DataSetType associated to a DataSourceCatalog
196  when cloned will not have the clone associate to the same DataSourceCatalog.
197 
198  \return A clone of the object.
199  */
200  virtual Property* clone() const = 0;
201 
202  protected:
203 
204  Property* m_parent; //!< The parent property type: it must be a CompositeProperty.
205  unsigned int m_id; //!< An identification number that can be used internally.
206  int m_type; //!< The property data type.
207  std::string m_name; //!< The property name.
208  std::string m_datasetName; //!< The property's dataset name.
209  };
210 
211  /*!
212  \brief For use with boost conteiners.
213  */
214  inline Property* new_clone(const Property& a)
215  {
216  return a.clone();
217  }
218 
219  } // end namespace dt
220 } // end namespace te
221 
222 #endif // __TERRALIB_DATATYPE_INTERNAL_PROPERTY_H
223 
Property * m_parent
The parent property type: it must be a CompositeProperty.
Definition: Property.h:204
virtual ~Property()
Virtual destructor.
Definition: Property.h:89
virtual Property * clone() const =0
It returns a clone of the object.
std::string m_name
The property name.
Definition: Property.h:207
void setDatasetName(const std::string &dsName)
It sets the property name.
Definition: Property.h:154
It models a property definition.
Definition: Property.h:59
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:64
void setId(unsigned int id)
It sets the property identifier.
Definition: Property.h:118
Configuration flags for the DataType module of TerraLib.
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:137
Property * getParent() const
It returns the parent of this property, or NULL, if it doesn't have one.
Definition: Property.h:168
std::string m_datasetName
The property's dataset name.
Definition: Property.h:208
int getType() const
It returns the property data type.
Definition: Property.h:161
General enumerations for the data type module.
unsigned int m_id
An identification number that can be used internally.
Definition: Property.h:205
const std::string & getDatasetName() const
It returns the name of the propery's dataset.
Definition: Property.h:144
int m_type
The property data type.
Definition: Property.h:206
unsigned int getId() const
It returns the property identifier.
Definition: Property.h:109
AbstractData * new_clone(const AbstractData &a)
For use with boost conteiners.
Definition: AbstractData.h:92
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
void setParent(Property *p)
It associate this property to the informed parent.
Definition: Property.h:177