Constraint.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/Constraint.h
22 
23  \brief A class that describes a constraint.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_CONSTRAINT_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_CONSTRAINT_H
28 
29 // TerraLib
30 #include "../Config.h"
31 #include "../Enums.h"
32 
33 // STL
34 #include <string>
35 
36 namespace te
37 {
38  namespace da
39  {
40 // Forward declaration
41  class DataSetType;
42 
43  /*!
44  \class DataSetConstraint
45 
46  \brief A class that describes a constraint.
47 
48  \sa DataSetType, PrimaryKey, ForeignKey, UniqueKey, CheckConstraint
49  */
51  {
52  public:
53 
54  /*!
55  \brief Constructor.
56 
57  \param id The constraint identifier.
58 
59  \note The new constraint will belong to the given DataSetType.
60 
61  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
62  */
63  Constraint(unsigned int id = 0);
64 
65  /*!
66  \brief Constructor.
67 
68  \param name The constraint name.
69  \param id The constraint identifier.
70 
71  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
72  */
73  Constraint(const std::string& name, unsigned int id = 0);
74 
75  /*!
76  \brief Copy constructor not allowed.
77 
78  The new object will not have an associated DataSetType.
79 
80  \param rhs Right-hand-side instance.
81  */
82  Constraint(const Constraint& rhs);
83 
84  /*! \brief Virtual destructor. */
85  virtual ~Constraint() {}
86 
87  /*!
88  \brief Assignment operator not allowed.
89 
90  \param rhs Right-hand-side instance.
91 
92  \return A reference to this object.
93  */
94  Constraint& operator=(const Constraint& rhs);
95 
96  /*!
97  \brief It returns the constraint identifier.
98 
99  \return A number that identifies the constraint.
100 
101  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
102  */
103  virtual unsigned int getId() const { return m_id; }
104 
105  /*!
106  \brief It sets the constraint identifier.
107 
108  \param id A number that identifies the constraint.
109 
110  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
111  */
112  virtual void setId(unsigned int id) { m_id = id; }
113 
114  /*!
115  \brief It returns the constraint name.
116 
117  \return The constraint name.
118  */
119  virtual const std::string& getName() const { return m_name; }
120 
121  /*!
122  \brief It sets the constraint name.
123 
124  \param name The constraint name.
125  */
126  virtual void setName(const std::string& name) { m_name = name; }
127 
128  /*!
129  \brief It returns the DataSetType associated to the constraint.
130 
131  \return The DataSetType associated to the constraint.
132  */
133  virtual DataSetType* getDataSetType() const { return m_dt; }
134 
135  /*!
136  \brief It sets the DataSetType associated to the constraint.
137 
138  \param dt The DataSetType associated to this constraint.
139 
140  \warning Take care when calling this method. If the constraint belongs to a DataSetType,
141  remember to detach it from the DataSetType before calling this method.
142  */
143  virtual void setDataSetType(DataSetType* dt) { m_dt = dt; }
144 
145  /*!
146  \brief It returns the constraint type.
147 
148  \return The constraint type.
149 
150  \note Each child has to implement this method and return its specialized type.
151  */
152  virtual ConstraintType getType() const = 0;
153 
154  /*!
155  \brief It returns a clone of the object.
156 
157  The new object will not have an associated DataSetType.
158 
159  \return A clone of the object.
160  */
161  virtual Constraint* clone() = 0;
162 
163  private:
164 
165  unsigned int m_id; //!< An identification number for the constraint.
166  DataSetType* m_dt; //!< The associated DataSetType.
167  std::string m_name; //!< The constraint name.
168  };
169 
170  } // end namespace da
171 } // end namespace te
172 
173 #endif // __TERRALIB_DATAACCESS_INTERNAL_CONSTRAINT_H
174 
virtual void setName(const std::string &name)
It sets the constraint name.
Definition: Constraint.h:126
virtual void setDataSetType(DataSetType *dt)
It sets the DataSetType associated to the constraint.
Definition: Constraint.h:143
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual void setId(unsigned int id)
It sets the constraint identifier.
Definition: Constraint.h:112
ConstraintType
A ConstraintType can have one of the following types:
Definition: Enums.h:65
URI C++ Library.
virtual unsigned int getId() const
It returns the constraint identifier.
Definition: Constraint.h:103
unsigned int m_id
An identification number for the constraint.
Definition: Constraint.h:165
virtual ~Constraint()
Virtual destructor.
Definition: Constraint.h:85
std::string m_name
The constraint name.
Definition: Constraint.h:167
DataSetType * m_dt
The associated DataSetType.
Definition: Constraint.h:166
virtual DataSetType * getDataSetType() const
It returns the DataSetType associated to the constraint.
Definition: Constraint.h:133
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
virtual const std::string & getName() const
It returns the constraint name.
Definition: Constraint.h:119