DataSourceTypeManager.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 terralib/qt/widgets/datasource/core/DataSourceTypeManager.cpp
22 
23  \brief A singleton to keep all the registered data source types.
24 */
25 
26 // TerraLib
27 #include "../../../../common/STLUtils.h"
28 #include "../../../../core/translator/Translator.h"
29 #include "../../Exception.h"
30 #include "DataSourceType.h"
31 #include "DataSourceTypeManager.h"
32 
33 // STL
34 #include <cassert>
35 
36 // Boost
37 #include <boost/format.hpp>
38 
40 {
42 }
43 
45 {
46  if(dst == nullptr)
47  throw Exception(TE_TR("Can not insert a NULL data source type into the manager!"));
48 
49  if(te::common::GetPValue(m_datasourceTypeMap, dst->getName()) != nullptr)
50  throw Exception((boost::format(TE_TR("There is already a data source type with the given id (%1%) in data source manager!")) % dst->getName()).str());
51 
52  m_datasourceTypeMap[dst->getName()] = dst;
53 }
54 
56 {
57  iterator it = m_datasourceTypeMap.find(name);
58 
59  if(it == m_datasourceTypeMap.end())
60  return;
61 
62  delete it->second;
63 
64  m_datasourceTypeMap.erase(it);
65 }
66 
68 {
69  return m_datasourceTypeMap.size();
70 }
71 
73 {
74  return m_datasourceTypeMap.begin();
75 }
76 
78 {
79  return m_datasourceTypeMap.begin();
80 }
81 
83 {
84  return m_datasourceTypeMap.end();
85 }
86 
88 {
89  return m_datasourceTypeMap.end();
90 }
91 
93 
Base exception class for plugin module.
V * GetPValue(const std::map< K, V * > &m, const K &k)
It finds for a given key in the map and returns a pointer if something is found or NULL otherwise...
Definition: STLUtils.h:179
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::map< std::string, DataSourceType * > m_datasourceTypeMap
std::map< std::string, DataSourceType * >::iterator iterator
std::map< std::string, DataSourceType * >::const_iterator const_iterator
const DataSourceType * get(const std::string &name) const
virtual std::string getName() const =0
A base class for the suppported types of data source.