RepositoryManager.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/edit/RepositoryManager.cpp
22 
23  \brief This is a singleton for managing edit repositories.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../core/translator/Translator.h"
29 #include "Repository.h"
30 #include "RepositoryManager.h"
31 
32 // Boost
33 #include <boost/format.hpp>
34 
35 // STL
36 #include <cassert>
37 
38 void te::edit::RepositoryManager::addGeometry(const std::string& source, te::gm::Geometry* geom)
39 {
40  Repository* repository = getRepository(source);
41 
42  if (repository == nullptr)
43  {
44  // Not found! Create a new repository associated with the given source
45  repository = new Repository(source);
46 
47  // Add the geometry
48  repository->add(geom);
49 
50  // Store!
51  m_repositories[source] = repository;
52 
53  }
54  else
55  repository->add(geom);
56 }
57 
59 {
60  Repository* repository = getRepository(source);
61 
62  if (repository == nullptr)
63  {
64  // Not found! Create a new repository associated with the given source
65  repository = new Repository(source);
66 
67  // Add the geometry
68  repository->add(id, geom);
69 
70  // Store!
71  m_repositories[source] = repository;
72  }
73  else
74  repository->add(id, geom);
75 }
76 
77 void te::edit::RepositoryManager::addFeature(const std::string& source, Feature* f)
78 {
79  Repository* repository = getRepository(source);
80 
81  if (repository == nullptr)
82  {
83  // Not found! Create a new repository associated with the given source
84  repository = new Repository(source);
85 
86  // Add the feature
87  repository->add(f);
88 
89  // Store!
90  m_repositories[source] = repository;
91  }
92  else
93  repository->add(f);
94 }
95 
96 bool te::edit::RepositoryManager::hasIdentify(const std::string& source, te::da::ObjectId* id)
97 {
98  assert(id);
99 
100  Repository* repository = getRepository(source);
101 
102  if (repository == nullptr)
103  return false;
104 
105  return repository->hasIdentifier(id);
106 }
107 
108 const std::map<std::string, te::edit::Repository*>& te::edit::RepositoryManager::getRepositories() const
109 {
110  return m_repositories;
111 }
112 
114 {
115  std::map<std::string, Repository*>::const_iterator it = m_repositories.find(source);
116 
117  if (it == m_repositories.end())
118  return nullptr;
119 
120  return it->second;
121 }
122 
123 std::vector<te::edit::Feature*> te::edit::RepositoryManager::getFeatures(const std::string& source, const te::gm::Envelope& e, int srid) const
124 {
125  Repository* repository = getRepository(source);
126 
127  if (repository == nullptr)
128  return std::vector<te::edit::Feature*>();
129 
130  return repository->getFeatures(e, srid);
131 }
132 
133 te::edit::Feature* te::edit::RepositoryManager::getFeature(const std::string& source, const te::gm::Envelope& e, int srid) const
134 {
135  Repository* repository = getRepository(source);
136 
137  if (repository == nullptr)
138  return nullptr;
139 
140  return repository->getFeature(e, srid);
141 }
142 
144 {
145  Repository* repository = getRepository(source);
146 
147  if (repository == nullptr)
148  return nullptr;
149 
150  return repository->getFeature(id);
151 }
152 
154 {
155  std::map<std::string, Repository*>::const_iterator it;
156  for (it = m_repositories.begin(); it != m_repositories.end(); ++it)
157  it->second->clear();
158 }
159 
160 void te::edit::RepositoryManager::clear(const std::string& source)
161 {
162  Repository* repository = getRepository(source);
163 
164  if (repository == nullptr)
165  return;
166 
167  repository->clear();
168 }
169 
171 {
173  m_repositories.clear();
174 }
175 
176 void te::edit::RepositoryManager::remove(const std::string& source)
177 {
178  std::map<std::string, Repository*>::iterator it = m_repositories.find(source);
179 
180  if (it == m_repositories.end())
181  return;
182 
183  m_repositories.erase(it);
184 
185  delete it->second;
186 }
187 
189 {
190  Repository* repository = getRepository(source);
191 
192  if (repository == nullptr)
193  {
194  // Not found! Create a new repository associated with the given source
195  repository = new Repository(source);
196 
197  // Remove the feature
198  repository->remove(id);
199 
200  // Store!
201  m_repositories[source] = repository;
202  }
203  else
204  repository->remove(id);
205 }
206 
208 
210 {
211  removeAll();
212 }
void addGeometry(const std::string &source, te::gm::Geometry *geom)
Feature * getFeature(const te::gm::Envelope &e, int srid) const
Definition: Repository.cpp:215
This is a singleton for managing edit repositories.
bool hasIdentifier(te::da::ObjectId *id)
Definition: Repository.cpp:167
const std::map< std::string, Repository * > & getRepositories() const
std::map< std::string, Repository * > m_repositories
std::vector< Feature * > getFeatures(const std::string &source, const te::gm::Envelope &e, int srid) const
void clear(const std::string &source)
An Envelope defines a 2D rectangular region.
void add(te::gm::Geometry *geom)
Definition: Repository.cpp:54
void remove(te::da::ObjectId *id)
Definition: Repository.cpp:136
This class represents an unique id for a data set element.
This class represents a repository of geometries and features.
Feature * getFeature(const std::string &source, const te::gm::Envelope &e, int srid) const
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void removeFeature(const std::string &source, te::da::ObjectId *id)
bool hasIdentify(const std::string &source, te::da::ObjectId *id)
std::vector< Feature * > getFeatures(const te::gm::Envelope &e, int srid) const
Definition: Repository.cpp:182
void remove(const std::string &source)
Repository * getRepository(const std::string &source) const
This class represents a repository of geometries and features.
Definition: Repository.h:63
void addFeature(const std::string &source, Feature *f)
~RepositoryManager()
Singleton destructor.
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
RepositoryManager()
It initializes the singleton instance of the repository manager.