All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GraphData.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 GraphData.cpp
22 
23  \brief This class define a important struct used to group
24  a map of vertex and edges. A flag is used to indicate
25  if any element of this group was changed.
26 */
27 
28 // Terralib Includes
29 #include "../../common/STLUtils.h"
30 #include "../core/Edge.h"
31 #include "../core/Vertex.h"
32 #include "GraphData.h"
33 
34 
36  m_id(id),
37  m_dirty(false)
38 {
39 }
40 
42 {
43  te::common::FreeContents(m_vertexMap);
44  te::common::FreeContents(m_edgeMap);
45 
46  m_vertexMap.clear();
47  m_edgeMap.clear();
48 }
49 
51 {
52  return m_id;
53 }
54 
56 {
57  m_vertexMap.insert(te::graph::GraphData::VertexMap::value_type(v->getId(), v));
58 
59  if(v->isDirty() || v->isNew())
60  {
61  setDirty(true);
62  }
63 }
64 
66 {
67  VertexMap::iterator it = m_vertexMap.find(id);
68 
69  if(it == m_vertexMap.end())
70  return false;
71 
72  m_vertexMap.erase(it);
73 
74  return true;
75 }
76 
78 {
79  VertexMap::iterator it = m_vertexMap.find(id);
80 
81  if(it != m_vertexMap.end())
82  {
83  return it->second;
84  }
85 
86  return 0;
87 }
88 
90 {
91  return m_vertexMap;
92 }
93 
95 {
96  m_vertexMap = map;
97 }
98 
100 {
101  m_edgeMap.insert(te::graph::GraphData::EdgeMap::value_type(e->getId(), e));
102 
103  if(e->isDirty() || e->isNew())
104  {
105  setDirty(true);
106  }
107 }
108 
110 {
111  EdgeMap::iterator it = m_edgeMap.find(id);
112 
113  if(it == m_edgeMap.end())
114  return false;
115 
116  m_edgeMap.erase(it);
117 
118  return true;
119 }
120 
122 {
123  EdgeMap::iterator it = m_edgeMap.find(id);
124 
125  if(it != m_edgeMap.end())
126  {
127  return it->second;
128  }
129 
130  return 0;
131 }
132 
134 {
135  return m_edgeMap;
136 }
137 
139 {
140  m_edgeMap = map;
141 }
142 
144 {
145  m_dirty = status;
146 }
147 
149 {
150  return m_dirty;
151 }
Vertex * getVertex(int id)
Definition: GraphData.cpp:77
VertexMap & getVertexMap()
It returns the the vertex map.
Definition: GraphData.cpp:89
bool isDirty()
Used to verify the vertex state.
Definition: Vertex.cpp:121
Edge * getEdge(int id)
Definition: GraphData.cpp:121
int getId()
Get data identifier.
Definition: GraphData.cpp:50
bool isNew()
Flag used to indicate that this element was a new one.
Definition: Vertex.cpp:126
void setVertexMap(const VertexMap &map)
Used to set a map of vertex elements.
Definition: GraphData.cpp:94
int getId()
It returns the edge identification.
Definition: Edge.cpp:66
std::map< int, Vertex * > VertexMap
typedef for vertex map
Definition: GraphData.h:66
This class define a important struct used to group a map of vertex and edges. A flag is used to indic...
void addEdge(Edge *e)
Definition: GraphData.cpp:99
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
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
void setDirty(bool status)
Flag used to define the graph data state.
Definition: GraphData.cpp:143
bool removeVertex(int id)
Definition: GraphData.cpp:65
void addVertex(Vertex *v)
Definition: GraphData.cpp:55
void setEdgeMap(const EdgeMap &map)
Used to set a map of edge elements.
Definition: GraphData.cpp:138
bool isNew()
Flag used to indicate that this element was a new one.
Definition: Edge.cpp:118
EdgeMap & getEdgeMap()
It returns the the edge map.
Definition: GraphData.cpp:133
GraphData(int id)
Default constructor.
Definition: GraphData.cpp:35
bool removeEdge(int id)
Definition: GraphData.cpp:109
bool isDirty()
Used to check the graph data state.
Definition: GraphData.cpp:148
int getId()
It returns the vertex id.
Definition: Vertex.cpp:69
std::map< int, Edge * > EdgeMap
typedef for edge map
Definition: GraphData.h:68
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
~GraphData()
Default destructor.
Definition: GraphData.cpp:41