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-2013 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 
78  /*!
79  \brief Copy constructor.
80 
81  \param rhs The right-hand-side copy used to copy from.
82 
83  \note Copy constructor doesn't preserve parent relationship.
84  */
85  Property(const Property& rhs);
86 
87  /*! \brief Virtual destructor. */
88  virtual ~Property() {}
89 
90  /*!
91  \brief Assignment operator.
92 
93  \param rhs The right-hand-side copy used to copy from.
94 
95  \return A reference to this object.
96 
97  \note Assignment operator doesn't preserve parent relationship.
98  */
99  Property& operator=(const Property& rhs);
100 
101  /*!
102  \brief It returns the property identifier.
103 
104  \return A number used to identify the property.
105 
106  \warning The identifier value may be used by data source implementations. So, don't rely on its value!
107  */
108  unsigned int getId() const { return m_id; }
109 
110  /*!
111  \brief It sets the property identifier.
112 
113  \param id A number used to identify the property.
114 
115  \warning The identifier value may be used by data source implementations. So, don't rely on its value!
116  */
117  void setId(unsigned int id) { m_id = id; }
118 
119  /*!
120  \brief It returns the property name.
121 
122  \return The property name.
123 
124  \note For DataSetTypes the name can have namespace prefix or schema name prefix, it will depend on the data source implementation.
125  */
126  const std::string& getName() const { return m_name; }
127 
128  /*!
129  \brief It sets the property name.
130 
131  \param name The new property name.
132 
133  \warning Take care when calling this method for a DataSetType associated to a DataSourceCatalog.
134  Prefer using the rename method on the DataSourceCatalog API instead of using this method.
135  */
136  void setName(const std::string& name) { m_name = name; }
137 
138  /*!
139  \brief It returns the property data type.
140 
141  \return The property data type.
142  */
143  int getType() const { return m_type; }
144 
145  /*!
146  \brief It returns the parent of this property, or NULL, if it doesn't have one.
147 
148  \return The parent of this property, or NULL, if it doesn't have one.
149  */
150  Property* getParent() const { return m_parent; }
151 
152  /*!
153  \brief It associate this property to the informed parent.
154 
155  \param p Teh parent property.
156 
157  \warning Don't use this method without knowing the internal details of its use.
158  */
159  void setParent(Property* p) { m_parent = p; }
160 
161  /*!
162  \brief It checks if the Property "p" is associated to this property or any other parent.
163 
164  This method can be used to ask if a given Property belongs
165  to a more complex type (like: CompositeProperty or DataSetType).
166 
167  \param p The Property we are checking.
168 
169  \return True if the given Property "p" is associated to to this Property, otherwise, returns false.
170  */
171  virtual bool has(Property* p) const = 0;
172 
173  /*!
174  \brief It returns a clone of the object.
175 
176  The new Property may not have associations to other elements.
177  For example, a DataSetType associated to a DataSourceCatalog
178  when cloned will not have the clone associate to the same DataSourceCatalog.
179 
180  \return A clone of the object.
181  */
182  virtual Property* clone() const = 0;
183 
184  protected:
185 
186  Property* m_parent; //!< The parent property type: it must be a CompositeProperty.
187  unsigned int m_id; //!< An identification number that can be used internally.
188  int m_type; //!< The property data type.
189  std::string m_name; //!< The property name.
190  };
191 
192  /*!
193  \brief For use with boost conteiners.
194  */
195  inline Property* new_clone(const Property& a)
196  {
197  return a.clone();
198  }
199 
200  } // end namespace dt
201 } // end namespace te
202 
203 #endif // __TERRALIB_DATATYPE_INTERNAL_PROPERTY_H
204 
Property * m_parent
The parent property type: it must be a CompositeProperty.
Definition: Property.h:186
virtual ~Property()
Virtual destructor.
Definition: Property.h:88
virtual Property * clone() const =0
It returns a clone of the object.
std::string m_name
The property name.
Definition: Property.h:189
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:117
Configuration flags for the DataType module of TerraLib.
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:136
Property * getParent() const
It returns the parent of this property, or NULL, if it doesn't have one.
Definition: Property.h:150
int getType() const
It returns the property data type.
Definition: Property.h:143
General enumerations for the data type module.
unsigned int m_id
An identification number that can be used internally.
Definition: Property.h:187
int m_type
The property data type.
Definition: Property.h:188
unsigned int getId() const
It returns the property identifier.
Definition: Property.h:108
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:126
void setParent(Property *p)
It associate this property to the informed parent.
Definition: Property.h:159