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