All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SymbolLibraryManager.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/se/SymbolLibraryManager.cpp
22 
23  \brief The SymbolLibraryManager is a singleton that can be used to manage all loaded symbol libraries in TerraLib.
24 */
25 
26 // TerraLib
27 #include "../../../common/Exception.h"
28 #include "../../../common/STLUtils.h"
29 #include "../../../common/Translator.h"
30 #include "SymbolLibrary.h"
31 #include "SymbolLibraryManager.h"
32 
33 // STL
34 #include <cassert>
35 
37 {
38  assert(library);
39 
40  std::string name = library->getName();
41  if(findByName(name))
42  throw te::common::Exception(TE_TR("There is already a symbol library with the given name."));
43 
44  m_symbolLibraryMap[name] = library;
45 }
46 
48 {
49  assert(library);
50 
51  std::string name = library->getName();
52  std::map<std::string, SymbolLibrary*>::iterator it = m_symbolLibraryMap.find(name);
53 
54  if(it == m_symbolLibraryMap.end())
55  throw te::common::Exception(TE_TR("Could not find the symbol library with the given name."));
56 
57  m_symbolLibraryMap.erase(it);
58 
59  delete it->second;
60 }
61 
63 {
64  std::map<std::string, SymbolLibrary*>::const_iterator it = m_symbolLibraryMap.find(name);
65 
66  if(it != m_symbolLibraryMap.end())
67  return it->second;
68 
69  return 0;
70 }
71 
72 std::pair<std::map<std::string, te::qt::widgets::SymbolLibrary*>::const_iterator,
73  std::map<std::string, te::qt::widgets::SymbolLibrary*>::const_iterator> te::qt::widgets::SymbolLibraryManager::getIterator() const
74 {
75  return std::pair<std::map<std::string, SymbolLibrary*>::const_iterator,
76  std::map<std::string, SymbolLibrary*>::const_iterator>(m_symbolLibraryMap.begin(), m_symbolLibraryMap.end());
77 }
78 
80 {
81  te::common::FreeContents(m_symbolLibraryMap);
82  m_symbolLibraryMap.clear();
83 }
84 
86 {
87 }
88 
90 {
91 }
void clear()
It unloads all symbol libraries managed by SymbolLibraryManager.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
const std::string & getName() const
SymbolLibrary * findByName(const std::string &name) const
It returns the symbol library identified by a given name or NULL if none is found.
std::pair< std::map< std::string, SymbolLibrary * >::const_iterator, std::map< std::string, SymbolLibrary * >::const_iterator > getIterator() const
It returns a pair of iterators over the symbol libraries of this manager.
The SymbolLibraryManager is a singleton that can be used to manage all loaded symbol libraries in Ter...
std::map< std::string, SymbolLibrary * > m_symbolLibraryMap
The set of symbol libraries.
This class represents a library of symbols.
This class represents a library of symbols.
Definition: SymbolLibrary.h:52
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
void insert(SymbolLibrary *library)
It inserts a new symbol library that will be managed by SymbolLibraryManager.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
void remove(SymbolLibrary *library)
It removes the symbol library from the manager.
SymbolLibraryManager()
It initializes the Singleton.