LibraryManager.h
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.h
22 
23  \brief A singleton that can be used to observe the available libraries in the system.
24 */
25 
26 #ifndef __TERRALIB_COMMON_INTERNAL_LIBRARYMANAGER_H
27 #define __TERRALIB_COMMON_INTERNAL_LIBRARYMANAGER_H
28 
29 // TerraLib
30 #include "Config.h"
31 #include "Library.h"
32 #include "Singleton.h"
33 
34 // STL
35 #include <string>
36 
37 
38 namespace te
39 {
40  namespace common
41  {
42  /*!
43  \class LibraryManager
44 
45  \brief A singleton that can be used to observe the available libraries in the system.
46 
47  \note This singleton doesn't control the libraries lifetime, it
48  just make smart references to them that will be automatically removed
49  when a library goes out of scope (or been destroyed). Actually it works
50  like an observer of known libraries.
51 
52  \note This class is based on pimpl idiom.
53 
54  \ingroup common
55  */
56  class TECOMMONEXPORT LibraryManager : public Singleton<LibraryManager>
57  {
58  friend class Singleton<LibraryManager>;
59 
60  public:
61 
62  /*!
63  \brief It adds a new Library to be managed.
64 
65  This implementaion will keep the library in the manager
66  while there is at least someone pointing to it.
67  As soon as no one keeps a reference to it the
68  manager will be communicated and the library will not be available
69  anymore.
70 
71  \param id An identifier used to search for the library in successive lookups.
72  \param l The library to be managed.
73  */
74  void add(const std::string& id, const LibraryPtr& l) throw();
75 
76  /*!
77  \brief Returns a null pointer if a library doesnt't exist.
78 
79  \param name The library name.
80 
81  \return A pointer to an already loaded library or null.
82  */
83  LibraryPtr find(const std::string& name) throw();
84 
85  protected:
86 
87  /*! \brief Consructor. */
89 
90  /*! \brief Destructor. */
91  ~LibraryManager();
92 
93  private:
94 
95  class Impl;
96 
97  Impl* m_pImpl; //!< A pointer to the real implementation.
98  };
99 
100  } // end namespace common
101 } // end namespace te
102 
103 #endif // __TERRALIB_COMMON_INTERNAL_LIBRARYMANAGER_H
104 
Impl * m_pImpl
A pointer to the real implementation.
boost::shared_ptr< Library > LibraryPtr
Definition: Library.h:184
A class for handling shared libraries.
Configuration flags for the TerraLib Common Runtime module.
A singleton that can be used to observe the available libraries in the system.
Template support for singleton pattern.
URI C++ Library.
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
Template support for singleton pattern.
Definition: Singleton.h:100