All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LibraryManager.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/common/LibraryManager.cpp
22 
23  \brief A singleton that can be used to register the available libraries in the system.
24  */
25 
26 // TerraLib
27 #include "LibraryManager.h"
28 
29 // STL
30 #include <map>
31 
32 // Boost
33 #include <boost/weak_ptr.hpp>
34 
36 {
37  public:
38 
39  typedef boost::weak_ptr<te::common::Library> LibraryWeakPtr;
40 
41  Impl()
42  {
43  }
44 
46  {
47  }
48 
49  void add(const std::string& id, const te::common::LibraryPtr& l) throw()
50  {
51  m_libraryMap[id] = l;
52  }
53 
54  te::common::LibraryPtr find(const std::string& id) throw()
55  {
56  std::map<std::string, LibraryWeakPtr>::const_iterator it = m_libraryMap.find(id);
57 
58  if(it != m_libraryMap.end())
59  return it->second.lock();
60 
61  return te::common::LibraryPtr();
62  }
63 
64  private:
65 
66  std::map<std::string, LibraryWeakPtr> m_libraryMap;
67 };
68 
69 void te::common::LibraryManager::add(const std::string& id, const LibraryPtr& l) throw()
70 {
71  m_pImpl->add(id, l);
72 }
73 
75 {
76  return m_pImpl->find(id);
77 }
78 
80  : m_pImpl(0)
81 {
82  m_pImpl = new Impl;
83 }
84 
86 {
87  delete m_pImpl;
88 }
89 
Impl * m_pImpl
A pointer to the real implementation.
boost::shared_ptr< Library > LibraryPtr
Definition: Library.h:184
LibraryPtr find(const std::string &name)
Returns a null pointer if a library doesnt't exist.
std::map< std::string, LibraryWeakPtr > m_libraryMap
A singleton that can be used to observe the available libraries in the system.
te::common::LibraryPtr find(const std::string &id)
boost::weak_ptr< te::common::Library > LibraryWeakPtr
void add(const std::string &id, const LibraryPtr &l)
It adds a new Library to be managed.
void add(const std::string &id, const te::common::LibraryPtr &l)