All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QueryGraphBuilder.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 QueryGraphBuilder.cpp
22 
23  \brief This class defines the Query strategy to build a graph having
24  a exist graph as input parameters.
25 
26  The query must be defined using only the terralib Query module
27  elements.
28 */
29 
30 // TerraLib
31 #include "../../common/Translator.h"
32 #include "../../common/progress/TaskProgress.h"
33 #include "../../dataaccess/query/Expression.h"
34 #include "../core/AbstractGraphFactory.h"
35 #include "../core/Edge.h"
36 #include "../core/GraphMetadata.h"
37 #include "../core/Vertex.h"
38 #include "../core/VertexProperty.h"
39 #include "../graphs/Graph.h"
40 #include "../iterator/QueryIterator.h"
41 #include "../Config.h"
42 #include "../Exception.h"
43 #include "QueryGraphBuilder.h"
44 
45 // STL
46 #include <cassert>
47 #include <cstdlib>
48 #include <iostream>
49 
50 
52 {
53 
54 }
55 
57 {
58 }
59 
60 bool te::graph::QueryGraphBuilder::build(te::graph::AbstractGraph* g, te::da::Expression* eEdge, te::da::Expression* eVertex, const std::map<std::string, std::string>& dsInfo, const std::string& graphType, const std::map<std::string, std::string>& gInfo)
61 {
62  //create output graph
63  m_graph.reset(te::graph::AbstractGraphFactory::make(graphType, dsInfo, gInfo));
64 
65  assert(m_graph);
66 
67  //copy attributes
68  for(int t = 0; t < g->getEdgePropertySize(); ++ t)
69  {
71  p->setParent(0);
72 
73  m_graph->addEdgeProperty(p);
74  }
75 
76  for(int t = 0; t < g->getVertexPropertySize(); ++ t)
77  {
79  p->setParent(0);
80 
81  m_graph->addVertexProperty(p);
82  }
83 
84  //create iterator
85  {
87 
88  te::graph::Vertex* vertex = it->getFirstVertex();
89 
91 
93  t.setMessage(TE_TR("Query Graph Builder - Vertex..."));
94  t.useTimer(true);
95 
96 
97  //copy elements
98  while(it->isVertexIteratorAfterEnd() == false)
99  {
100  if(vertex)
101  {
102  te::graph::Vertex* vNew = new te::graph::Vertex(vertex);
103 
104  m_graph->add(vNew);
105  }
106 
107  vertex = it->getNextVertex();
108 
109  t.pulse();
110  }
111 
112  delete it;
113  }
114 
115  {
117 
118  te::graph::Edge* edge = it->getFirstEdge();
119 
121 
123  t.setMessage(TE_TR("Query Graph Builder - Edges..."));
124  t.useTimer(true);
125 
126 
127  //copy elements
128  while(it->isEdgeIteratorAfterEnd() == false)
129  {
130  if(edge)
131  {
132  te::graph::Edge* eNew = new te::graph::Edge(edge);
133 
134  m_graph->add(eNew);
135  }
136 
137  edge = it->getNextEdge();
138 
139  t.pulse();
140  }
141 
142  delete it;
143 
144  }
145 
146  return true;
147 }
148 
void setMessage(const std::string &message)
Set the task message.
virtual te::dt::Property * getVertexProperty(int idx)
Get a vertex property given a index.
virtual te::dt::Property * getEdgeProperty(int idx)
Get a edge property given a index.
void useTimer(bool flag)
Used to define if task use progress timer information.
virtual Property * clone() const =0
It returns a clone of the object.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
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
virtual te::graph::Edge * getFirstEdge()
It returns a pointer to the first edge element of a graph.
It models a property definition.
Definition: Property.h:59
This is an abstract class that models a query expression.
Definition: Expression.h:47
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
void setTotalSteps(int value)
Set the task total stepes.
virtual te::graph::GraphMetadata * getMetadata()=0
Function used to access the graph metadata.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
Definition: Edge.h:58
virtual ~QueryGraphBuilder()
Virtual destructor.
This class defines the Query strategy to build a graph having a exist graph as input parameters...
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.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
virtual te::graph::Vertex * getNextVertex()
It returns a pointer to the next vertex element of a graph.
virtual int getEdgePropertySize()=0
Used to verify the number of properties associated to edge elements.
virtual int getVertexPropertySize()=0
Used to verify the number of properties associated to vertex elements.
virtual te::graph::Vertex * getFirstVertex()
It returns a pointer to the first vertex element of a graph.
virtual size_t getVertexInteratorCount()
It returns the number of elements of this iterator.
QueryGraphBuilder()
Default constructor.
This class defines a commun interface to represents a graph iterator class. The main diferency to ano...
Definition: QueryIterator.h:66
static AbstractGraph * make()
It creates and returns an empty graph with default graph type.
This abstract class provides the common functions for graph builder classes. Each builder strategy ha...
bool build(te::graph::AbstractGraph *g, te::da::Expression *eEdge, te::da::Expression *eVertex, const std::map< std::string, std::string > &dsInfo, const std::string &graphType, const std::map< std::string, std::string > &gInfo)
Function used to generated the vertex id based on raster coordenate.
virtual bool isVertexIteratorAfterEnd()
Used to check the iterator position.
virtual bool isEdgeIteratorAfterEnd()
Used to check the iterator position.
void setParent(Property *p)
It associate this property to the informed parent.
Definition: Property.h:177