SymbolLibrary.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/SymbolLibrary.cpp
22 
23  \brief This class represents a library of symbols.
24 */
25 
26 // TerraLib
27 #include "../../../common/Exception.h"
28 #include "../../../common/STLUtils.h"
29 #include "../../../core/translator/Translator.h"
30 #include "Symbol.h"
31 #include "SymbolLibrary.h"
32 
33 // STL
34 #include <cassert>
35 
37  : m_name(name)
38 {
39  assert(!name.empty());
40 }
41 
43 
45 {
46  assert(symbol);
47 
48  std::string id = symbol->getInfo().m_id;
49  if(findById(id))
50  throw te::common::Exception(TE_TR("There is already a symbol with the given id."));
51 
52  m_symbolMap[id] = symbol;
53 }
54 
56 {
57  assert(symbol);
58 
59  std::string id = symbol->getInfo().m_id;
60  std::map<std::string, Symbol*>::iterator it = m_symbolMap.find(id);
61 
62  if(it == m_symbolMap.end())
63  throw te::common::Exception(TE_TR("Could not find the symbol with the given id."));
64 
65  m_symbolMap.erase(it);
66 }
67 
69 {
70  std::map<std::string, Symbol*>::const_iterator it = m_symbolMap.find(id);
71 
72  if(it != m_symbolMap.end())
73  return it->second;
74 
75  return nullptr;
76 }
77 
78 std::pair<std::map<std::string, te::qt::widgets::Symbol*>::const_iterator,
79  std::map<std::string, te::qt::widgets::Symbol*>::const_iterator> te::qt::widgets::SymbolLibrary::getIterator() const
80 {
81  return std::pair<std::map<std::string, Symbol*>::const_iterator,
82  std::map<std::string, Symbol*>::const_iterator>(m_symbolMap.begin(), m_symbolMap.end());
83 }
84 
85 const std::string& te::qt::widgets::SymbolLibrary::getName() const
86 {
87  return m_name;
88 }
89 
91 {
93  m_symbolMap.clear();
94 }
Symbol * findById(const std::string &id) const
It returns the symbol identified by a given id or NULL if none is found.
This class represents a symbol.
SymbolLibrary(const std::string &name)
Constructor.
std::map< std::string, Symbol * > m_symbolMap
The set of symbols.
std::pair< std::map< std::string, Symbol * >::const_iterator, std::map< std::string, Symbol * >::const_iterator > getIterator() const
It returns a pair of iterators over the symbols of this library.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
const SymbolInfo & getInfo() const
It return the information associated to the symbol.
Definition: Symbol.cpp:48
const std::string & getName() const
This class represents a library of symbols.
This class represents a symbol. TODO: More description!
Definition: Symbol.h:54
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void remove(Symbol *symbol)
It removes the symbol from this library.
std::string m_name
The name of the symbol library.
void clear()
It removes all symbols from this library.
void insert(Symbol *symbol)
It inserts a new symbol to this library.
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