All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Vertex.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 Vertex.cpp
22 
23  \brief From the point of view of graph theory, vertices are treated
24  as featureless and indivisible objects, although they may have
25  additional structure depending on the application from which the
26  graph arises;for instance, a semantic network is a graph in
27  which the vertices represent concepts or classes of objects.
28 */
29 
30 // Terralib Includes
31 #include "../../common/STLUtils.h"
32 #include "../../datatype/AbstractData.h"
33 #include "Vertex.h"
34 
35 
36 te::graph::Vertex::Vertex(int id, bool isNew) : m_vertexId(id), m_dirty(false), m_new(isNew)
37 {
38 }
39 
41 {
42  m_vertexId = rhs->getId();
43  m_dirty = false;
44  m_new = true;
45 
46  m_predecessors.insert(rhs->getPredecessors().begin(), rhs->getPredecessors().end());
47  m_successors.insert(rhs->getSuccessors().begin(), rhs->getSuccessors().end());
48  m_neighborhood.insert(rhs->getNeighborhood().begin(), rhs->getNeighborhood().end());
49 
50  this->setAttributeVecSize(rhs->getAttributes().size());
51 
52  for(size_t t = 0; t < rhs->getAttributes().size(); ++ t)
53  {
54  te::dt::AbstractData* ad = rhs->getAttributes()[t]->clone();
55 
56  this->addAttribute(t, ad);
57  }
58 }
59 
61 {
62  te::common::FreeContents(m_attrs);
63 
64  m_predecessors.clear();
65  m_successors.clear();
66  m_neighborhood.clear();
67 }
68 
70 {
71  return m_vertexId;
72 }
73 
74 std::vector<te::dt::AbstractData*>& te::graph::Vertex::getAttributes()
75 {
76  return m_attrs;
77 }
78 
80 {
81  m_attrs.resize(size);
82 }
83 
85 {
86  if(m_attrs[idx])
87  delete m_attrs[idx];
88 
89  m_attrs[idx] = ad;
90 
91  return;
92 }
93 
95 {
96  delete m_attrs[idx];
97 
98  return;
99 }
100 
102 {
103  return m_predecessors;
104 }
105 
107 {
108  return m_successors;
109 }
110 
112 {
113  return m_neighborhood;
114 }
115 
117 {
118  m_dirty = flag;
119 }
120 
122 {
123  return m_dirty;
124 }
125 
127 {
128  return m_new;
129 }
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the vertex elements.
Definition: Vertex.cpp:79
bool isDirty()
Used to verify the vertex state.
Definition: Vertex.cpp:121
std::set< int > & getPredecessors()
Returns the Predecessors vector.
Definition: Vertex.cpp:101
void removeAttribute(int idx)
Remove a attribute associated with this element.
Definition: Vertex.cpp:94
bool isNew()
Flag used to indicate that this element was a new one.
Definition: Vertex.cpp:126
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
Definition: Vertex.cpp:74
Vertex(int id, bool isNew=true)
Constructor.
Definition: Vertex.cpp:36
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
void setDirty(bool flag)
Flag used to indicate that this element was changed.
Definition: Vertex.cpp:116
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
std::set< int > & getSuccessors()
Returns the Successors vector.
Definition: Vertex.cpp:106
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
~Vertex()
Default destructor.
Definition: Vertex.cpp:60
std::set< int > & getNeighborhood()
Returns the Neighborhood vector.
Definition: Vertex.cpp:111
int getId()
It returns the vertex id.
Definition: Vertex.cpp:69
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
Definition: Vertex.cpp:84
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55