All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PrimaryKey.cpp
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/PrimaryKey.cpp
22 
23  \brief A PrimaryKey describes a primary key (pk) constraint.
24 */
25 
26 // TerraLib
27 #include "../../datatype/Property.h"
28 #include "DataSetType.h"
29 #include "PrimaryKey.h"
30 
32  : Constraint(id),
33  m_index(0)
34 {
35  if(dt)
36  dt->add(this);
37 }
38 
39 te::da::PrimaryKey::PrimaryKey(const std::string& name, DataSetType* dt, unsigned int id)
40  : Constraint(name, id),
41  m_index(0)
42 {
43  if(dt)
44  dt->add(this);
45 }
46 
48  : Constraint(rhs.getName(), 0),
49  m_index(rhs.m_index),
50  m_properties(rhs.m_properties)
51 {
52 }
53 
55 {
56  if(this != &rhs)
57  {
59  m_index = rhs.m_index;
60  m_properties = rhs.m_properties;
61  }
62 
63  return *this;
64 }
65 
67 {
68  std::size_t size = m_properties.size();
69 
70  for(std::size_t i = 0; i < size; ++i)
71  if(m_properties[i] == p)
72  return true;
73 
74  return false;
75 }
76 
78 {
79  std::size_t size = m_properties.size();
80 
81  for(std::size_t i = 0; i < size; ++i)
82  if(m_properties[i] == p)
83  {
84  m_properties[i] = pp;
85  break;
86  }
87 }
88 
90 {
91  return new PrimaryKey(*this);
92 }
93 
It describes a primary key (pk) constraint.
std::vector< te::dt::Property * > m_properties
The properties that take part of primary key constraint.
Definition: PrimaryKey.h:177
A class that models the description of a dataset.
Definition: DataSetType.h:72
Constraint & operator=(const Constraint &rhs)
Assignment operator not allowed.
Definition: Constraint.cpp:52
PrimaryKey(DataSetType *dt=0, unsigned int id=0)
Constructor.
Definition: PrimaryKey.cpp:31
bool has(const te::dt::Property *p) const
It verifies if Property is associated to the primary key.
Definition: PrimaryKey.cpp:66
It models a property definition.
Definition: Property.h:59
Index * m_index
A pointer to an associated index.
Definition: PrimaryKey.h:176
void replace(te::dt::Property *p, te::dt::Property *pp)
It changes a reference to property p to pp.
Definition: PrimaryKey.cpp:77
Constraint * clone()
It returns a clone of the object.
Definition: PrimaryKey.cpp:89
void add(Constraint *c)
It adds a new constraint.
A class that models the description of a dataset.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
PrimaryKey & operator=(const PrimaryKey &rhs)
Assignment operator.
Definition: PrimaryKey.cpp:54