All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataConverterManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 terralib/datatype/DataConverterManager.cpp
22 
23  \brief A singleton for managing the data type converter available in the system.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "DataConverterManager.h"
29 
30 // Boost
31 #include <boost/format.hpp>
32 
33 void te::dt::DataConverterManager::add(int src, int dst, te::dt::DataTypeConverter conv) throw(Exception)
34 {
35  std::pair<int, int> mapping(src, dst);
36 
37  std::map<std::pair<int, int>, DataTypeConverter>::iterator it = m_convMap.find(mapping);
38  if(it != m_convMap.end())
39  throw Exception((boost::format(TR_DATATYPE("There is already a converter registered for the data type conversion: %1% -> %2%.")) % src % dst).str());
40 
41  m_convMap[mapping] = conv;
42 }
43 
44 const te::dt::DataTypeConverter& te::dt::DataConverterManager::get(const std::pair<int, int>& typeMap) throw(Exception)
45 {
46  std::map<std::pair<int, int>, DataTypeConverter>::iterator it = m_convMap.find(typeMap);
47  if(it == m_convMap.end())
48  throw Exception((boost::format(TR_DATATYPE("There is not a converter registered for the data type conversion: %1% -> %2%.")) % typeMap.first % typeMap.second).str());
49 
50  return it->second;
51 }
52 
54 {
55 }
56 
58 {
59 }
#define TR_DATATYPE(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
Definition: Config.h:58
void add(int src, int dst, DataTypeConverter conv)
It adds a converter to the list of known data type mappings.
A singleton for managing the data type converter available in the system.
const DataTypeConverter & get(int src, int dst)
It returns a data type converter for the given source and destination data types. ...
boost::function1< AbstractData *, AbstractData * > DataTypeConverter
The definition of the data type converter.