AbstractIterator.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 AbstractIterator.cpp
22 
23  \brief
24 */
25 
26 // Terralib Includes
27 #include "../../core/translator/Translator.h"
28 #include "../../common/StringUtils.h"
29 #include "../core/AbstractGraph.h"
30 #include "../iterator/AbstractIterator.h"
31 #include "../Config.h"
32 #include "../Exception.h"
33 #include "../Globals.h"
34 
36  : m_graph(g),
37 
38  m_listIsolatedVertex(true)
39 {
40 }
41 
43 
45 {
46  if(m_vertexQuery.get() == nullptr)
47  {
48  throw Exception(TE_TR("Iterator not initialized."));
49  }
50 
51  int id;
52 
53  if(m_vertexQuery->moveNext())
54  {
56  }
57  else
58  {
59  return nullptr;
60  }
61 
62  return m_graph->getVertex(id);
63 }
64 
66 {
67  if(m_vertexQuery.get() == nullptr)
68  {
69  throw Exception(TE_TR("Iterator not initialized."));
70  }
71 
72  int id;
73 
74  if(m_vertexQuery->movePrevious())
75  {
77  }
78  else
79  {
80  return nullptr;
81  }
82 
83  return m_graph->getVertex(id);
84 }
85 
87 {
88  if(m_vertexQuery.get() == nullptr)
89  {
90  throw Exception(TE_TR("Iterator not initialized."));
91  }
92 
93  return m_vertexQuery->isAfterEnd();
94 }
95 
97 {
98  if(m_vertexQuery.get() == nullptr)
99  {
100  throw Exception(TE_TR("Iterator not initialized."));
101  }
102 
103  return m_vertexQuery->size();
104 }
105 
107 {
108  m_listIsolatedVertex = flag;
109 }
110 
112 {
113  if(m_edgeQuery.get() == nullptr)
114  {
115  throw Exception(TE_TR("Iterator not initialized."));
116  }
117 
118  int id;
119 
120  if(m_edgeQuery->moveNext())
121  {
123  }
124  else
125  {
126  return nullptr;
127  }
128 
129  return m_graph->getEdge(id);
130 }
131 
133 {
134  if(m_edgeQuery.get() == nullptr)
135  {
136  throw Exception(TE_TR("Iterator not initialized."));
137  }
138 
139  int id;
140 
141  if(m_edgeQuery->movePrevious())
142  {
144  }
145  else
146  {
147  return nullptr;
148  }
149 
150  return m_graph->getEdge(id);
151 }
152 
154 {
155  if(m_edgeQuery.get() == nullptr)
156  {
157  throw Exception(TE_TR("Iterator not initialized."));
158  }
159 
160  return m_edgeQuery->isAfterEnd();
161 }
162 
164 {
165  if(m_edgeQuery.get() == nullptr)
166  {
167  throw Exception(TE_TR("Iterator not initialized."));
168  }
169 
170  return m_edgeQuery->size();
171 }
te::graph::AbstractGraph * m_graph
Pointer to a abstract graph used to access the elements.
static const std::string sm_tableVertexModelAttrId
Attribute id.
Base exception class for plugin module.
virtual te::graph::Edge * getEdge(int id)=0
It returns the edge element if it&#39;s exist.
std::unique_ptr< te::da::DataSet > m_vertexQuery
Attribute used to keep the vertex iterator.
virtual te::graph::Edge * getNextEdge()
It returns a pointer to the next edge element of a graph.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
void listIsolatedVertex(bool flag)
Used to set that the isolated vertex must be listed.
virtual ~AbstractIterator()
Virtual destructor.
bool m_listIsolatedVertex
Flag used to indicated that the isolated vertex will be listed.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
Definition: Edge.h:58
static const std::string sm_tableEdgeModelAttrId
Attribute Id.
virtual te::graph::Vertex * getPreviousVertex()
It returns a pointer to the previous vertex element of a graph.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:55
virtual size_t getEdgeInteratorCount()
It returns the number of elements of this iterator.
virtual te::graph::Vertex * getNextVertex()
It returns a pointer to the next vertex element of a graph.
std::unique_ptr< te::da::DataSet > m_edgeQuery
Attribute used to keep the edge iterator.
virtual size_t getVertexInteratorCount()
It returns the number of elements of this iterator.
AbstractIterator(te::graph::AbstractGraph *g)
Default constructor.
virtual te::graph::Vertex * getVertex(int id)=0
It returns the vertex element if it&#39;s exist.
virtual te::graph::Edge * getPreviousEdge()
It returns a pointer to the previous edge element of a graph.
virtual bool isVertexIteratorAfterEnd()
Used to check the iterator position.
virtual bool isEdgeIteratorAfterEnd()
Used to check the iterator position.