MetadataManager.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/metadata/MetadataManager.cpp
22  */
23 
24 // TerraLib
25 #include "../common/Exception.h"
26 #include "../core/translator/Translator.h"
27 #include "Config.h"
28 #include "MetadataAnnotation.h"
29 #include "MetadataManager.h"
30 
31 // STL
32 #include <cassert>
33 
35 
37 
38 void
40 {
41  assert(a);
42 
43  std::map<std::string,MetadataAnnotation*>::const_iterator it = m_metadata.find(a->getAnnotationtId());
44 
45  if (it != m_metadata.end())
46  throw te::common::Exception(TE_TR("A metadata annotation with this id already exists in the manager."));
47 
48  m_metadata.insert(std::make_pair(a->getAnnotationtId(),a));
49 }
50 
51 void
53 {
54  assert(a);
55 
56  std::map<std::string,MetadataAnnotation*>::iterator it = m_metadata.find(a->getAnnotationtId());
57 
58  if (it == m_metadata.end())
59  throw te::common::Exception(TE_TR("A metadata annotation with this id already exists in the manager."));
60 
61  m_metadata.erase(it);
62 
63 }
64 
66 te::md::MetadataManager::find(const std::string& aid) const
67 {
68  assert(!aid.empty());
69 
70  std::map<std::string,MetadataAnnotation*>::const_iterator it = m_metadata.find(aid);
71 
72  if (it == m_metadata.end())
73  return nullptr;
74 
75  return it->second;
76 }
77 
78 const std::map<std::string,te::md::MetadataAnnotation*>&
80 {
81  return m_metadata;
82 }
83 
84 
85 bool
87 {
88  return m_metadata.empty();
89 }
90 
91 void
93 {
94  m_metadata.clear();
95 }
96 
97 const std::map<std::string,te::md::MetadataAnnotation*>::const_iterator
99 {
100  return m_metadata.begin();
101 }
102 
103 const std::map<std::string,te::md::MetadataAnnotation*>::const_iterator
105 {
106  return m_metadata.end();
107 }
108 
109 
110 
111 
const std::map< std::string, MetadataAnnotation * > & getAnnotations() const
Gives access to the set of metadata annotations.
std::map< std::string, MetadataAnnotation * > m_metadata
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
void insert(MetadataAnnotation *a)
Inserts a new metadata annotation to the manager.
const std::string & getAnnotationtId() const
Gets the annotation identifier.
const MetadataAnnotation * find(const std::string &aid) const
Searches for an annotation, given its identification.
MetadataManager()
It initializes the Singleton.
A class to relate a metadata annotation to a TerraLib element (or entity).
bool isEmpty() const
Check wheter the manager is empty.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
const std::map< std::string, MetadataAnnotation * >::const_iterator getBeginIterator() const
Returns a begin iterator to the annotations managed.
Configuration flags for the Metadata support of TerraLib.
~MetadataManager()
Destructor.
void erase(MetadataAnnotation *a)
Removes the annotation from the manager and frees its resources.
const std::map< std::string, MetadataAnnotation * >::const_iterator getEndIterator() const
Returns an end iterator pointing to the annotations managed.
void clear()
Removes all the annotation from the manager.