All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../../common/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 {
44 }
45 
47 {
48  assert(symbol);
49 
50  std::string id = symbol->getInfo().m_id;
51  if(findById(id))
52  throw te::common::Exception(TE_TR("There is already a symbol with the given id."));
53 
54  m_symbolMap[id] = symbol;
55 }
56 
58 {
59  assert(symbol);
60 
61  std::string id = symbol->getInfo().m_id;
62  std::map<std::string, Symbol*>::iterator it = m_symbolMap.find(id);
63 
64  if(it == m_symbolMap.end())
65  throw te::common::Exception(TE_TR("Could not find the symbol with the given id."));
66 
67  m_symbolMap.erase(it);
68 }
69 
71 {
72  std::map<std::string, Symbol*>::const_iterator it = m_symbolMap.find(id);
73 
74  if(it != m_symbolMap.end())
75  return it->second;
76 
77  return 0;
78 }
79 
80 std::pair<std::map<std::string, te::qt::widgets::Symbol*>::const_iterator,
81  std::map<std::string, te::qt::widgets::Symbol*>::const_iterator> te::qt::widgets::SymbolLibrary::getIterator() const
82 {
83  return std::pair<std::map<std::string, Symbol*>::const_iterator,
84  std::map<std::string, Symbol*>::const_iterator>(m_symbolMap.begin(), m_symbolMap.end());
85 }
86 
87 const std::string& te::qt::widgets::SymbolLibrary::getName() const
88 {
89  return m_name;
90 }
91 
93 {
94  te::common::FreeContents(m_symbolMap);
95  m_symbolMap.clear();
96 }
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::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:347
const SymbolInfo & getInfo() const
It return the information associated to the symbol.
Definition: Symbol.cpp:50
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. ...
Definition: Exception.h:58
void remove(Symbol *symbol)
It removes the symbol from this 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