All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataConverterManager.h
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.h
22 
23  \brief A singleton for managing the data type converter available in the system.
24 */
25 
26 #ifndef __TERRALIB_DATATYPE_INTERNAL_DATACONVERTERMANAGER_H
27 #define __TERRALIB_DATATYPE_INTERNAL_DATACONVERTERMANAGER_H
28 
29 // TerraLib
30 #include "../common/Singleton.h"
31 #include "Config.h"
32 #include "DataTypeConverter.h"
33 #include "Exception.h"
34 
35 // STL
36 #include <map>
37 
38 namespace te
39 {
40  namespace dt
41  {
42  /*!
43  \class DataConverterManager
44 
45  \brief A singleton for managing the data type converter available in the system.
46 
47  \ingroup datatype
48 
49  \sa DataTypeConverter
50  */
51  class TEDATATYPEEXPORT DataConverterManager : public te::common::Singleton<DataConverterManager>
52  {
54 
55  public:
56 
57  /*!
58  \brief It adds a converter to the list of known data type mappings.
59 
60  \param src The source data type of the converter.
61  \param dst The destination data type of the converter.
62  \param conv The data type converter.
63 
64  \exception Exception It throws an exception if a converter for the same source and destination data types already exists.
65  */
66  void add(int src, int dst, DataTypeConverter conv) throw(Exception);
67 
68  /*!
69  \brief It returns a data type converter for the given source and destination data types.
70 
71  \param src The source data type of the converter.
72  \param dst The destination data type of the converter.
73 
74  \return A data type converter for the given source and destination data types. or NULL if none is found.
75 
76  \exception Exception It throws an exception if none is found.
77  */
78  const DataTypeConverter& get(int src, int dst) throw(Exception);
79 
80  /*!
81  \brief It returns a data type converter for the given source and destination data types
82 
83  \param typeMap The type of converter: source-data-type -> destination-data-type.
84 
85  \return A data type converter for the given map.
86 
87  \exception Exception It throws an exception if none is found.
88  */
89  const DataTypeConverter& get(const std::pair<int, int>& typeMap) throw(Exception);
90 
91  protected:
92 
93  /*! \brief Constructor. */
95 
96  /*! \brief Destructor. */
98 
99  private:
100 
101  std::map<std::pair<int, int>, DataTypeConverter> m_convMap; //!< A map: (source-data-type, target-data-type) -> data type converter
102  };
103 
104  inline const DataTypeConverter& DataConverterManager::get(int src, int dst) throw(Exception)
105  {
106  std::pair<int, int> mapping(src, dst);
107  return get(mapping);
108  }
109 
110  } // end namespace dt
111 } // end namespace te
112 
113 #endif // __TERRALIB_DATATYPE_INTERNAL_DATACONVERTERMANAGER_H
Template support for singleton pattern.
Definition: Singleton.h:100
std::map< std::pair< int, int >, DataTypeConverter > m_convMap
A map: (source-data-type, target-data-type) -&gt; data type converter.
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:99
A singleton for managing the data type converter available in the system.
Definition of data type converter.
Configuration flags for the DataType module of TerraLib.
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.
An exception class for the DataType module.