Index.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/dataaccess/dataset/Index.h
22 
23  \brief It describes an index associated to a DataSetType.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_INDEX_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_INDEX_H
28 
29 // TerraLib
30 #include "../Config.h"
31 #include "../Enums.h"
32 #include "../../datatype/Property.h"
33 
34 // STL
35 #include <vector>
36 #include <string>
37 
38 namespace te
39 {
40  namespace da
41  {
42 // Forward declarations
43  class DataSetType;
44 
45  /*!
46  \class Index
47 
48  \brief It describes an index associated to a DataSetType.
49 
50  \sa DataSetType, PrimaryKey, ForeignKey, CheckConstraint, UniqueKey
51  */
53  {
54  public:
55 
56  /*!
57  \brief Constructor.
58 
59  \param dt The DataSetType associated to this index.
60  \param id The index identifier.
61 
62  \post If dt is provided, the index will belong to the given DataSetType.
63  \post By default the index type is BTreeType.
64 
65  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
66  */
67  Index(DataSetType* parent = 0, unsigned int id = 0);
68 
69  /*!
70  \brief Constructor.
71 
72  \param name The index name.
73  \param t The index type.
74  \param dt The DataSetType associated to this index.
75  \param id The index identifier.
76 
77  \post If dt is provided, the index will belong to the given DataSetType.
78 
79  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
80  */
81  Index(const std::string& name,
83  DataSetType* dt = 0,
84  unsigned int id = 0);
85 
86 
87  /*!
88  \brief Copy constructor.
89 
90  The new object will not have an associated DataSetType.
91 
92  \param rhs Right-hand-side instance.
93  */
94  Index(const Index& rhs);
95 
96  /*! \brief Destructor. */
97  ~Index();
98 
99  /*!
100  \brief Assignment operator.
101 
102  The new object will not have an assigned DataSetType.
103 
104  \param rhs Right-hand-side instance.
105 
106  \return A reference to this.
107  */
108  Index& operator=(const Index& rhs);
109 
110  /*!
111  \brief It returns the index identifier.
112 
113  \return A number that identifies the index.
114 
115  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
116  */
117  unsigned int getId() const { return m_id; }
118 
119  /*!
120  \brief It sets the DataSetType identifier.
121 
122  \param id A unique number that identifies the DataSetType in its DataSource.
123 
124  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
125  */
126  void setId(unsigned int id) { m_id = id; }
127 
128  /*!
129  \brief It returns the index name.
130 
131  \return The index name.
132  */
133  const std::string& getName() const { return m_name; }
134 
135  /*!
136  \brief It sets the index name.
137 
138  \param name The index name.
139  */
140  void setName(const std::string& name) { m_name = name; }
141 
142  /*!
143  \brief It gets the index type.
144 
145  \return The index type.
146  */
147  IndexType getIndexType() const { return m_type; }
148 
149  /*!
150  \brief It sets the index type.
151 
152  \param t The index type.
153  */
154  void setIndexType(IndexType t) { m_type = t; }
155 
156  /*!
157  \brief It returns the properties that take part of the index.
158 
159  \return The properties that take part of the index.
160  */
161  const std::vector<te::dt::Property*>& getProperties() const { return m_properties; }
162 
163  /*!
164  \brief It adds the property to the list of properties of the index.
165 
166  \param p The property that will take part of the index.
167  */
168  void add(const te::dt::Property* p) { m_properties.push_back(p->clone()); }
169 
170  /*!
171  \brief It returns the DataSetType associated to the index.
172 
173  \return The DataSetType associated to the index.
174  */
175  DataSetType* getDataSetType() const { return m_dt; }
176 
177  /*!
178  \brief It sets the DataSetType associated to the index.
179 
180  \param dt The DataSetType to which this index belongs.
181 
182  \warning Take care when calling this method. If the index belongs to a DataSetType,
183  remember to detach it from the DataSetType before calling this method.
184  */
185  void setDataSetType(DataSetType* dt) { m_dt = dt; }
186 
187  /*!
188  \brief It verifies if Property is associated to the index.
189 
190  \param propertyName The Property name to be verified.
191 
192  \return True if Property is associated to the index, false otherwise.
193  */
194  bool has(const std::string& propertyName);
195 
196  /*!
197  \brief It changes the reference to property p to pp.
198 
199  \param propName A property name that takes part of the index.
200  \param pp The property that will take p place.
201 
202  \note If the property p is not in the idx attribute list this method does nothing.
203  */
204  void replace(const std::string& propName, const te::dt::Property* pp);
205 
206  /*!
207  \brief It returns a clone of the object.
208 
209  The new object will not have an associated schema.
210 
211  \return A clone of the object.
212  */
213  Index* clone() const;
214 
215  private:
216 
217  unsigned int m_id; //!< An identification number for the index.
218  IndexType m_type; //!< The index type.
219  DataSetType* m_dt; //!< The parent DataSetType.
220  std::string m_name; //!< The index name.
221  std::vector<te::dt::Property*> m_properties; //!< The list of properties that form the index.
222  };
223 
224  } // end namespace da
225 } // end namespace te
226 
227 #endif // __TERRALIB_DATAACCESS_INTERNAL_INDEX_H
228 
te::da::B_TREE_TYPE
@ B_TREE_TYPE
Definition: Enums.h:109
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::da::IndexType
IndexType
Index type.
Definition: Enums.h:108
te::da::Index::setIndexType
void setIndexType(IndexType t)
It sets the index type.
Definition: Index.h:154
te::da::Index::m_properties
std::vector< te::dt::Property * > m_properties
The list of properties that form the index.
Definition: Index.h:221
te::da::Index::operator=
Index & operator=(const Index &rhs)
Assignment operator.
te::da::Index::Index
Index(const std::string &name, IndexType t=B_TREE_TYPE, DataSetType *dt=0, unsigned int id=0)
Constructor.
te::da::Index::clone
Index * clone() const
It returns a clone of the object.
te::da::Index::m_dt
DataSetType * m_dt
The parent DataSetType.
Definition: Index.h:219
te::da::Index
It describes an index associated to a DataSetType.
Definition: Index.h:53
te::da::Index::m_type
IndexType m_type
The index type.
Definition: Index.h:218
te::da::Index::setId
void setId(unsigned int id)
It sets the DataSetType identifier.
Definition: Index.h:126
te::da::Index::m_id
unsigned int m_id
An identification number for the index.
Definition: Index.h:217
te::da::Index::Index
Index(const Index &rhs)
Copy constructor.
TEDATAACCESSEXPORT
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
te::da::Index::add
void add(const te::dt::Property *p)
It adds the property to the list of properties of the index.
Definition: Index.h:168
te::da::Index::~Index
~Index()
Destructor.
te::da::Index::getProperties
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
Definition: Index.h:161
te::da::Index::replace
void replace(const std::string &propName, const te::dt::Property *pp)
It changes the reference to property p to pp.
te::da::Index::getIndexType
IndexType getIndexType() const
It gets the index type.
Definition: Index.h:147
te::da::Index::m_name
std::string m_name
The index name.
Definition: Index.h:220
te::da::Index::getDataSetType
DataSetType * getDataSetType() const
It returns the DataSetType associated to the index.
Definition: Index.h:175
te::da::Index::getName
const std::string & getName() const
It returns the index name.
Definition: Index.h:133
te::da::Index::getId
unsigned int getId() const
It returns the index identifier.
Definition: Index.h:117
te::da::Index::setName
void setName(const std::string &name)
It sets the index name.
Definition: Index.h:140
te::dt::Property
It models a property definition.
Definition: Property.h:60
te::da::DataSetType
A class that models the description of a dataset.
Definition: DataSetType.h:73
te::da::Index::has
bool has(const std::string &propertyName)
It verifies if Property is associated to the index.
te::da::Index::Index
Index(DataSetType *parent=0, unsigned int id=0)
Constructor.
te::dt::Property::clone
virtual Property * clone() const =0
It returns a clone of the object.
te::da::Index::setDataSetType
void setDataSetType(DataSetType *dt)
It sets the DataSetType associated to the index.
Definition: Index.h:185