All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../../../common/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/foreach.hpp>
38 #include <boost/format.hpp>
39 
41 {
43 }
44 
46 {
47  if(dst == 0)
48  throw Exception(TE_TR("Can not insert a NULL data source type into the manager!"));
49 
50  if(te::common::GetPValue(m_datasourceTypeMap, dst->getName()) != 0)
51  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());
52 
53  m_datasourceTypeMap[dst->getName()] = dst;
54 }
55 
57 {
58  iterator it = m_datasourceTypeMap.find(name);
59 
60  if(it == m_datasourceTypeMap.end())
61  return;
62 
63  delete it->second;
64 
65  m_datasourceTypeMap.erase(it);
66 }
67 
69 {
70  return m_datasourceTypeMap.size();
71 }
72 
74 {
75  return m_datasourceTypeMap.begin();
76 }
77 
79 {
80  return m_datasourceTypeMap.begin();
81 }
82 
84 {
85  return m_datasourceTypeMap.end();
86 }
87 
89 {
90  return m_datasourceTypeMap.end();
91 }
92 
94 {
95 }
96 
98 {
99 }
100 
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:347
std::map< std::string, DataSourceType * > m_datasourceTypeMap
std::map< std::string, DataSourceType * >::iterator iterator
std::map< std::string, DataSourceType * >::const_iterator const_iterator
virtual std::string getName() const =0
const DataSourceType * get(const std::string &name) const
A base class for the suppported types of data source.