All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractGraphFactory.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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 AbstractGraphFactory.cpp
22 
23  \brief This is the abstract factory for Graphs.
24 */
25 
26 // TerraLib
27 #include "../../common/StringUtils.h"
28 #include "../../common/Translator.h"
29 #include "../Config.h"
30 #include "../Exception.h"
31 #include "AbstractGraphFactory.h"
32 #include "GraphMetadata.h"
33 
34 // STL
35 #include <memory>
36 
38 {
40 }
41 
43 {
44  std::string ucase = te::common::Convert2UCase(gType);
45 
47 }
48 
49 te::graph::AbstractGraph* te::graph::AbstractGraphFactory::make(const std::map<std::string, std::string>& dsInfo, const std::map<std::string, std::string>& gInfo)
50 {
51  return make(TE_DEFAULT_GRAPH_TYPE, dsInfo, gInfo);
52 }
53 
54 te::graph::AbstractGraph* te::graph::AbstractGraphFactory::make(const std::string& gType, const std::map<std::string, std::string>& dsInfo, const std::map<std::string, std::string>& gInfo)
55 {
56  std::string ucase = te::common::Convert2UCase(gType);
57 
59 
60  AbstractGraphFactory* f = static_cast<AbstractGraphFactory*>(d.find(ucase));
61 
62  if(f == 0)
63  throw Exception(TR_GRAPH("Could not find concrete factory! Check if it was initialized!"));
64 
65  AbstractGraph* g = f->create(dsInfo, gInfo);
66 
67  g->getMetadata()->setType(ucase);
68 
69  return g;
70 }
71 
72 te::graph::AbstractGraph* te::graph::AbstractGraphFactory::open(const std::map<std::string, std::string>& dsInfo, const std::map<std::string, std::string>& gInfo)
73 {
74  return open(TE_DEFAULT_GRAPH_TYPE, dsInfo, gInfo);
75 }
76 
77 te::graph::AbstractGraph* te::graph::AbstractGraphFactory::open(const std::string& gType, const std::map<std::string, std::string>& dsInfo, const std::map<std::string, std::string>& gInfo)
78 {
79  std::string ucase = te::common::Convert2UCase(gType);
80 
82 
83  AbstractGraphFactory* f = static_cast<AbstractGraphFactory*>(d.find(ucase));
84 
85  if(f == 0)
86  throw Exception(TR_GRAPH("Could not find concrete factory! Check if it was initialized!"));
87 
88  AbstractGraph* g = f->iOpen(dsInfo, gInfo);
89 
90  g->getMetadata()->setType(ucase);
91 
92  return g;
93 }
94 
96  : te::common::AbstractFactory<te::graph::AbstractGraph, std::string>(factoryKey)
97 {
98 }
99 
100 
101 
This is the abstract factory for Graphs.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:56
static AbstractGraph * make()
It creates and returns an empty graph with default graph type.
virtual te::graph::GraphMetadata * getMetadata()=0
Function used to access the graph metadata.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:163
TFACTORY * find(const TFACTORYKEY &factoryKey) const
It looks for a given factory identified by a key.
This class represents a dictionary of factories.
#define TR_GRAPH(message)
It marks a string in order to get translated. This is a special mark used in the Graph module of Terr...
Definition: Config.h:58
static TPRODUCT * make(const TFACTORYKEY &factoryKey)
It creates an object with the appropriated factory.
AbstractGraphFactory(const std::string &factoryKey)
Constructor.
This is the abstract factory for Graphs.
#define TE_DEFAULT_GRAPH_TYPE
This definition is used to set the default graph type.
Definition: Config.h:86
virtual AbstractGraph * iOpen(const std::map< std::string, std::string > &dsInfo, const std::map< std::string, std::string > &gInfo)=0
This method must be re-implemented by subclasses in order to have a finner control for the graph obje...
static dictionary_type & getDictionary()
It returns a reference to the internal dictionary of concrete factories.
virtual AbstractGraph * create(const std::map< std::string, std::string > &dsInfo, const std::map< std::string, std::string > &gInfo)=0
This method must be implemented by subclasses (graph types).
static AbstractGraph * open(const std::map< std::string, std::string > &dsInfo, const std::map< std::string, std::string > &gInfo)
It opens a graph with the given parameters and default graph type.
void setType(std::string graphType)
Set the graph type (defined in Enums file)
Class used to define the graph metadata informations.