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