All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Edge.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 Edge.cpp
22 
23  \brief Class used to define the edge struct of a graph. Its compose
24  with a identifier, the vertex origin and destiny information,
25  a set of properties if exist and flags to inform his state
26  (new or dirty).
27 */
28 
29 // Terralib Includes
30 #include "../../datatype/AbstractData.h"
31 #include "../../common/STLUtils.h"
32 #include "Edge.h"
33 
34 te::graph::Edge::Edge(int id, int vFrom, int vTo, bool isNew) :
35  m_edgeId(id),
36  m_vertexIdFrom(vFrom),
37  m_vertexIdTo(vTo),
38  m_dirty(false),
39  m_new(isNew)
40 {
41 }
42 
44 {
45  m_edgeId = rhs->getId();
46  m_vertexIdFrom = rhs->getIdFrom();
47  m_vertexIdTo = rhs->getIdTo();
48  m_dirty = false;
49  m_new = true;
50 
51  this->setAttributeVecSize(rhs->getAttributes().size());
52 
53  for(size_t t = 0; t < rhs->getAttributes().size(); ++ t)
54  {
55  te::dt::AbstractData* ad = rhs->getAttributes()[t]->clone();
56 
57  this->addAttribute(t, ad);
58  }
59 }
60 
62 {
63  te::common::FreeContents(m_attrs);
64 }
65 
67 {
68  return m_edgeId;
69 }
70 
72 {
73  return m_vertexIdFrom;
74 }
75 
77 {
78  return m_vertexIdTo;
79 }
80 
81 std::vector<te::dt::AbstractData*>& te::graph::Edge::getAttributes()
82 {
83  return m_attrs;
84 }
85 
87 {
88  m_attrs.resize(size);
89 }
90 
92 {
93  if(m_attrs[idx])
94  delete m_attrs[idx];
95 
96  m_attrs[idx] = ad;
97 
98  return;
99 }
100 
102 {
103  delete m_attrs[idx];
104 
105  return;
106 }
107 
109 {
110  m_dirty = flag;
111 }
112 
114 {
115  return m_dirty;
116 }
117 
119 {
120  return m_new;
121 }
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the edge elements.
Definition: Edge.cpp:86
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
int getId()
It returns the edge identification.
Definition: Edge.cpp:66
bool isDirty()
Used to verify the edge state.
Definition: Edge.cpp:113
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
Definition: Edge.h:58
~Edge()
Default destructor.
Definition: Edge.cpp:61
void removeAttribute(int idx)
Remove a attribute associated with this element.
Definition: Edge.cpp:101
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
bool isNew()
Flag used to indicate that this element was a new one.
Definition: Edge.cpp:118
int getIdFrom()
It returns the vertex origin identification.
Definition: Edge.cpp:71
void setDirty(bool flag)
Flag used to indicate that this element was changed.
Definition: Edge.cpp:108
Edge(int id, int vFrom, int vTo, bool isNew=true)
Constructor.
Definition: Edge.cpp:34
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
Definition: Edge.cpp:91
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
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
Definition: Edge.cpp:81
int getIdTo()
It returns the vertex destiny identification.
Definition: Edge.cpp:76