All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DirectedGraphFactory.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 DirectedGraphFactory.h
22 
23  \brief This is the concrete factory for the directed Graph type.
24 */
25 
26 // TerraLib
27 #include "../core/GraphMetadata.h"
28 #include "../Exception.h"
29 #include "../Globals.h"
30 #include "DirectedGraph.h"
31 #include "DirectedGraphFactory.h"
32 
33 
34 // STL
35 #include <memory>
36 
38 
39 const std::string& te::graph::DirectedGraphFactory::getType() const
40 {
42 }
43 
44 void te::graph::DirectedGraphFactory::getCreationalParameters(std::vector< std::pair<std::string, std::string> >& params) const
45 {
46  params.push_back(std::pair<std::string, std::string>("GRAPH_DATA_SOURCE_TYPE", ""));
47  params.push_back(std::pair<std::string, std::string>("GRAPH_ID", ""));
48  params.push_back(std::pair<std::string, std::string>("GRAPH_NAME", ""));
49  params.push_back(std::pair<std::string, std::string>("GRAPH_DESCRIPTION", ""));
50  params.push_back(std::pair<std::string, std::string>("GRAPH_STORAGE_MODE", ""));
51  params.push_back(std::pair<std::string, std::string>("GRAPH_STRATEGY_LOADER", ""));
52  params.push_back(std::pair<std::string, std::string>("GRAPH_CACHE_POLICY", ""));
53 }
54 
56 {
57  finalize();
58  sm_factory = new DirectedGraphFactory;
59 }
60 
62 {
63  delete sm_factory;
64  sm_factory = 0;
65 }
66 
68  : te::graph::AbstractGraphFactory(Globals::sm_factoryGraphTypeDirectedGraph)
69 {
70 }
71 
72 te::graph::AbstractGraph* te::graph::DirectedGraphFactory::iOpen(const std::map<std::string, std::string>& dsInfo, const std::map<std::string, std::string>& gInfo)
73 {
74  //create graph metadata
75  te::graph::GraphMetadata* gMetadata = getMetadata(dsInfo, gInfo);
76 
77  if(gMetadata->m_memoryGraph)
78  return 0;
79 
80  //get graph id
81  int id = getId(dsInfo, gInfo);
82 
83  try
84  {
85  gMetadata->load(id);
86  }
87  catch(const std::exception& e)
88  {
89  std::string errorMessage = TE_TR("Error opening graph metadata: ");
90  errorMessage += e.what();
91 
92  throw Exception(errorMessage);
93  }
94 
95  //create cache policy strategy
96  te::graph::AbstractCachePolicy* cp = getCachePolicy(gInfo);
97 
98  //create graph strategy
99  te::graph::AbstractGraphLoaderStrategy* ls = getLoaderStrategy(gInfo, gMetadata);
100 
101  //create graph
103 
104  return g;
105 }
106 
107 te::graph::AbstractGraph* te::graph::DirectedGraphFactory::create(const std::map<std::string, std::string>& dsInfo, const std::map<std::string, std::string>& gInfo)
108 {
109  //create graph metadata
110  te::graph::GraphMetadata* gMetadata = getMetadata(dsInfo, gInfo);
111 
112  setMetadataInformation(gInfo, gMetadata);
113 
114  try
115  {
116  gMetadata->save();
117  }
118  catch(const std::exception& e)
119  {
120  std::string errorMessage = TE_TR("Error saving graph metadata: ");
121  errorMessage += e.what();
122 
123  throw Exception(errorMessage);
124  }
125 
126  //create cache policy strategy
127  te::graph::AbstractCachePolicy* cp = getCachePolicy(gInfo);
128 
129  //create graph strategy
130  te::graph::AbstractGraphLoaderStrategy* ls = getLoaderStrategy(gInfo, gMetadata);
131 
132  //create graph
134 
135  if(gMetadata->m_memoryGraph)
136  g = new te::graph::DirectedGraph(gMetadata);
137  else
138  g = new te::graph::DirectedGraph(cp, ls);
139 
140  return g;
141 }
142 
144 {
145  return new Graph;
146 }
static void initialize()
It initializes the factory: the singleton instance will be registered in the abstract factory ...
virtual void load(int id)
Function used to load the graph information given a graph id.
Definition: GraphMetadata.h:73
bool m_memoryGraph
Flag used to indicate if the graph is a memory graph.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
void getCreationalParameters(std::vector< std::pair< std::string, std::string > > &params) const
It returns the list of parameters accepted as graph info.
This is the concrete factory for the directed Graph type.
te::graph::AbstractGraph * build()
Builder Function used to create the class object.
This class is used to set the main functions of a cache policy.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:55
te::graph::AbstractGraph * create(const std::map< std::string, std::string > &dsInfo, const std::map< std::string, std::string > &gInfo)
This method must be implemented by subclasses (graph types).
const std::string & getType() const
Returns the type (name) of this factory.
This class define the main functions necessary to save and load the graph data and metadata informati...
This is the abstract factory for Graphs.
static const std::string sm_factoryGraphTypeDirectedGraph
Directed Graph Factory Name.
Definition: Globals.h:54
static void finalize()
It finalizes the factory: the singleton instance will be destroyed and will be unregistered from the ...
This is a implementation of a Directed Graph. By convention a directed graph provides access to out-e...
Definition: DirectedGraph.h:54
te::graph::AbstractGraph * iOpen(const std::map< std::string, std::string > &dsInfo, const std::map< std::string, std::string > &gInfo)
This method must be re-implemented by subclasses in order to have a finner control for the graph obje...
virtual void save()
Function used to save the graph information.
Definition: GraphMetadata.h:79
An static class with global definitions for the TerraLib Graph Module.
Definition: Globals.h:45
This is the main graph implementation, that uses a cache policy anda graph loader to get all elements...
Definition: Graph.h:72
This is the concrete factory for the directed Graph type.
Class used to define the graph metadata informations.
Definition: GraphMetadata.h:56
static DirectedGraphFactory * sm_factory
Static instance used to register the factory.
This is a implementation of a Directed Graph. By convention a directed graph provides access to out-e...