All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSourceInfoManager.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/dataaccess/datasource/DataSourceInfoManager.cpp
22 
23  \brief A singleton to keep all the registered data sources.
24 */
25 
26 // TerraLib
27 #include "../../common/STLUtils.h"
28 #include "../../common/Translator.h"
29 #include "../Exception.h"
30 #include "DataSourceInfo.h"
31 #include "DataSourceInfoManager.h"
32 
33 // STL
34 #include <cassert>
35 
36 // Boost
37 #include <boost/foreach.hpp>
38 #include <boost/format.hpp>
39 
41 {
42  std::map<std::string, DataSourceInfoPtr>::const_iterator it = m_datasources.find(id);
43 
44  return (it != m_datasources.end()) ? it->second : DataSourceInfoPtr();
45 }
46 
48 {
49  if(ds.get() == 0)
50  throw Exception(TE_TR("Can not insert a NULL data source into the manager!"));
51 
52  if(m_datasources.find(ds->getId()) == m_datasources.end())
53  m_datasources[ds->getId()] = ds;
54 }
55 
56 void te::da::DataSourceInfoManager::remove(const std::string& id)
57 {
58  std::map<std::string, DataSourceInfoPtr>::iterator it = m_datasources.find(id);
59 
60  if(it == m_datasources.end())
61  throw Exception((boost::format(TE_TR("There isn't a data source with the given id (%1%) in data source manager!")) % id).str());
62 
63  m_datasources.erase(it);
64 }
65 
66 void te::da::DataSourceInfoManager::removeByType(const std::string& dsTypeName)
67 {
68  std::map<std::string, DataSourceInfoPtr>::iterator it = m_datasources.begin();
69 
70  while(it!=m_datasources.end())
71  if(it->second->getType() == dsTypeName)
72  m_datasources.erase(it++);
73  else
74  ++it;
75 }
76 
77 
78 void te::da::DataSourceInfoManager::getByType(const std::string& dsTypeName, std::vector<DataSourceInfoPtr>& datasources) const
79 {
80  std::map<std::string, DataSourceInfoPtr>::const_iterator it = m_datasources.begin();
81  std::map<std::string, DataSourceInfoPtr>::const_iterator itend = m_datasources.end();
82 
83  while(it != itend)
84  {
85  if(it->second->getType() == dsTypeName)
86  datasources.push_back(it->second);
87 
88  ++it;
89  }
90 }
91 
93 {
94  return m_datasources.size();
95 }
96 
98 {
99  return m_datasources.begin();
100 }
101 
103 {
104  return m_datasources.begin();
105 }
106 
108 {
109  return m_datasources.end();
110 }
111 
113 {
114  return m_datasources.end();
115 }
116 
118 {
119 }
120 
122 {
123 }
124 
std::map< std::string, DataSourceInfoPtr >::iterator iterator
std::map< std::string, DataSourceInfoPtr >::const_iterator const_iterator
void getByType(const std::string &dsTypeName, std::vector< DataSourceInfoPtr > &datasources) const
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
DataSourceInfoPtr get(const std::string &id) const
A singleton to keep all the registered data sources.
void add(const DataSourceInfoPtr &ds)
A conteiner class for keeping information about a data source.
void remove(const std::string &id)
void removeByType(const std::string &dsTypeName)
std::map< std::string, DataSourceInfoPtr > m_datasources
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr