All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../common/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 == 0)
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  else
54  repository->add(geom);
55 }
56 
58 {
59  Repository* repository = getRepository(source);
60 
61  if(repository == 0)
62  {
63  // Not found! Create a new repository associated with the given source
64  repository = new Repository(source);
65 
66  // Add the geometry
67  repository->add(id, geom);
68 
69  // Store!
70  m_repositories[source] = repository;
71  }
72  else
73  repository->add(id, geom);
74 }
75 
76 void te::edit::RepositoryManager::addFeature(const std::string& source, Feature* f)
77 {
78  Repository* repository = getRepository(source);
79 
80  if(repository == 0)
81  {
82  // Not found! Create a new repository associated with the given source
83  repository = new Repository(source);
84 
85  // Add the feature
86  repository->add(f);
87 
88  // Store!
89  m_repositories[source] = repository;
90  }
91  else
92  repository->add(f);
93 }
94 
95 bool te::edit::RepositoryManager::hasIdentify(const std::string& source, te::da::ObjectId* id)
96 {
97  assert(id);
98 
99  Repository* repository = getRepository(source);
100 
101  if(repository == 0)
102  return false;
103 
104  return repository->hasIdentifier(id);
105 }
106 
107 const std::map<std::string, te::edit::Repository*>& te::edit::RepositoryManager::getRepositories() const
108 {
109  return m_repositories;
110 }
111 
113 {
114  std::map<std::string, Repository*>::const_iterator it = m_repositories.find(source);
115 
116  if(it == m_repositories.end())
117  return 0;
118 
119  return it->second;
120 }
121 
122 std::vector<te::edit::Feature*> te::edit::RepositoryManager::getFeatures(const std::string& source, const te::gm::Envelope& e, int srid) const
123 {
124  Repository* repository = getRepository(source);
125 
126  if(repository == 0)
127  return std::vector<te::edit::Feature*>();
128 
129  return repository->getFeatures(e, srid);
130 }
131 
132 te::edit::Feature* te::edit::RepositoryManager::getFeature(const std::string& source, const te::gm::Envelope& e, int srid) const
133 {
134  Repository* repository = getRepository(source);
135 
136  if(repository == 0)
137  return 0;
138 
139  return repository->getFeature(e, srid);
140 }
141 
143 {
144  std::map<std::string, Repository*>::const_iterator it;
145  for(it = m_repositories.begin(); it != m_repositories.end(); ++it)
146  it->second->clear();
147 }
148 
149 void te::edit::RepositoryManager::clear(const std::string& source)
150 {
151  Repository* repository = getRepository(source);
152 
153  if(repository == 0)
154  return;
155 
156  repository->clear();
157 }
158 
160 {
161  te::common::FreeContents(m_repositories);
162  m_repositories.clear();
163 }
164 
165 void te::edit::RepositoryManager::remove(const std::string& source)
166 {
167  std::map<std::string, Repository*>::iterator it = m_repositories.find(source);
168 
169  if(it == m_repositories.end())
170  return;
171 
172  m_repositories.erase(it);
173 
174  delete it->second;
175 }
176 
178 {
179 }
180 
182 {
183  removeAll();
184 }
void addGeometry(const std::string &source, te::gm::Geometry *geom)
Feature * getFeature(const te::gm::Envelope &e, int srid) const
Definition: Repository.cpp:205
This is a singleton for managing edit repositories.
bool hasIdentifier(te::da::ObjectId *id)
Definition: Repository.cpp:151
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.
Definition: Envelope.h:51
void add(te::gm::Geometry *geom)
Definition: Repository.cpp:56
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
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.
Definition: Geometry.h:73
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:183
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:62
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.