All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../common/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  m_vertexQuery(0),
38  m_edgeQuery(0),
39  m_listIsolatedVertex(true)
40 {
41 }
42 
44 {
45 }
46 
48 {
49  if(m_vertexQuery.get() == 0)
50  {
51  throw Exception(TE_TR("Iterator not initialized."));
52  }
53 
54  int id;
55 
56  if(m_vertexQuery->moveNext())
57  {
58  id = m_vertexQuery->getInt32(Globals::sm_tableVertexModelAttrId);
59  }
60  else
61  {
62  return 0;
63  }
64 
65  return m_graph->getVertex(id);
66 }
67 
69 {
70  if(m_vertexQuery.get() == 0)
71  {
72  throw Exception(TE_TR("Iterator not initialized."));
73  }
74 
75  int id;
76 
77  if(m_vertexQuery->movePrevious())
78  {
79  id = m_vertexQuery->getInt32(Globals::sm_tableVertexModelAttrId);
80  }
81  else
82  {
83  return 0;
84  }
85 
86  return m_graph->getVertex(id);
87 }
88 
90 {
91  if(m_vertexQuery.get() == 0)
92  {
93  throw Exception(TE_TR("Iterator not initialized."));
94  }
95 
96  return m_vertexQuery->isAfterEnd();
97 }
98 
100 {
101  if(m_vertexQuery.get() == 0)
102  {
103  throw Exception(TE_TR("Iterator not initialized."));
104  }
105 
106  return m_vertexQuery->size();
107 }
108 
110 {
111  m_listIsolatedVertex = flag;
112 }
113 
115 {
116  if(m_edgeQuery.get() == 0)
117  {
118  throw Exception(TE_TR("Iterator not initialized."));
119  }
120 
121  int id;
122 
123  if(m_edgeQuery->moveNext())
124  {
125  id = m_edgeQuery->getInt32(Globals::sm_tableEdgeModelAttrId);
126  }
127  else
128  {
129  return 0;
130  }
131 
132  return m_graph->getEdge(id);
133 }
134 
136 {
137  if(m_edgeQuery.get() == 0)
138  {
139  throw Exception(TE_TR("Iterator not initialized."));
140  }
141 
142  int id;
143 
144  if(m_edgeQuery->movePrevious())
145  {
146  id = m_vertexQuery->getInt32(Globals::sm_tableEdgeModelAttrId);
147  }
148  else
149  {
150  return 0;
151  }
152 
153  return m_graph->getEdge(id);
154 }
155 
157 {
158  if(m_edgeQuery.get() == 0)
159  {
160  throw Exception(TE_TR("Iterator not initialized."));
161  }
162 
163  return m_edgeQuery->isAfterEnd();
164 }
165 
167 {
168  if(m_edgeQuery.get() == 0)
169  {
170  throw Exception(TE_TR("Iterator not initialized."));
171  }
172 
173  return m_edgeQuery->size();
174 }
static const std::string sm_tableVertexModelAttrId
Attribute id.
Definition: Globals.h:97
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:347
void listIsolatedVertex(bool flag)
Used to set that the isolated vertex must be listed.
virtual ~AbstractIterator()
Virtual destructor.
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.
Definition: Globals.h:91
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.
virtual size_t getVertexInteratorCount()
It returns the number of elements of this iterator.
AbstractIterator(te::graph::AbstractGraph *g)
Default constructor.
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.