Loading...
Searching...
No Matches
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
38namespace 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,
82 IndexType t = B_TREE_TYPE,
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. */
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
A class that models the description of a dataset.
Definition: DataSetType.h:73
It describes an index associated to a DataSetType.
Definition: Index.h:53
std::string m_name
The index name.
Definition: Index.h:220
void setDataSetType(DataSetType *dt)
It sets the DataSetType associated to the index.
Definition: Index.h:185
unsigned int m_id
An identification number for the index.
Definition: Index.h:217
IndexType getIndexType() const
It gets the index type.
Definition: Index.h:147
IndexType m_type
The index type.
Definition: Index.h:218
void setId(unsigned int id)
It sets the DataSetType identifier.
Definition: Index.h:126
void add(const te::dt::Property *p)
It adds the property to the list of properties of the index.
Definition: Index.h:168
~Index()
Destructor.
void setIndexType(IndexType t)
It sets the index type.
Definition: Index.h:154
unsigned int getId() const
It returns the index identifier.
Definition: Index.h:117
const std::string & getName() const
It returns the index name.
Definition: Index.h:133
Index & operator=(const Index &rhs)
Assignment operator.
Index(const Index &rhs)
Copy constructor.
bool has(const std::string &propertyName)
It verifies if Property is associated to the index.
Index(DataSetType *parent=0, unsigned int id=0)
Constructor.
std::vector< te::dt::Property * > m_properties
The list of properties that form the index.
Definition: Index.h:221
DataSetType * m_dt
The parent DataSetType.
Definition: Index.h:219
void replace(const std::string &propName, const te::dt::Property *pp)
It changes the reference to property p to pp.
void setName(const std::string &name)
It sets the index name.
Definition: Index.h:140
Index * clone() const
It returns a clone of the object.
DataSetType * getDataSetType() const
It returns the DataSetType associated to the index.
Definition: Index.h:175
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
Definition: Index.h:161
Index(const std::string &name, IndexType t=B_TREE_TYPE, DataSetType *dt=0, unsigned int id=0)
Constructor.
It models a property definition.
Definition: Property.h:60
virtual Property * clone() const =0
It returns a clone of the object.
IndexType
Index type.
Definition: Enums.h:108
TerraLib.
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97