ColorSchemeCatalogManager.h
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/color/ColorSchemeCatalogManager.h
22 
23  \brief The ColorSchemeCatalogManager is a singleton that can be used to manage all loaded color scheme catalogs.
24 */
25 
26 #ifndef __TERRALIB_COLOR_INTERNAL_COLORSCHEMECATALOGMANAGER_H
27 #define __TERRALIB_COLOR_INTERNAL_COLORSCHEMECATALOGMANAGER_H
28 
29 // TerraLib
30 #include "../common/Singleton.h"
31 #include "Config.h"
32 
33 // STL
34 #include <map>
35 #include <string>
36 #include <vector>
37 
38 namespace te
39 {
40  namespace color
41  {
42 // Forward declaration
43  class ColorSchemeCatalog;
44 
45  /*!
46  \class ColorSchemeCatalogManager
47 
48  \brief The ColorSchemeCatalogManager is a singleton that can be used to manage all loaded color scheme catalogs.
49 
50  Use this class to keep the loaded catalogs and to be a point of entry for plugins that
51  need to known what are the opened catalogs of your application. When the singleton finishes
52  its life time it automatically clears all loaded catalogs stored on it.
53  You can also use it only inside a given window, where a list of catalogs will be displayed
54  and then when the window gets closed, you clear the catalogs to save memory.
55 
56  \note You can save memory not loading all catalogs and keeping then opened during the entire life of your application.
57 
58  \ingroup color
59 
60  \sa Singleton, ColorScheme, ColorSchemeGroup, ColorSchemeCatalog
61 
62  \todo Em breve, seria melhor transformar as classes ColorScheme, ColorSchemeCatalog
63  em pImpl ou shared pointers, para que as pessoas nao tenham que se preocupar
64  com concorrencia em nivel de thread no que diz respeito a quem pegou o ponteiro,
65  quem apagou e assim por diante!
66 
67  \todo Criar uma classe chamada ApplicationPreferences que guarda qual o catalogo
68  default de um dado usuario. Depois cria um classe XML que salva as preferencias num arquivo XML.
69  Exemplo de pereferncias: tipo de fonte padrao, cor padrao, catalogo de cores padrao, numero de cores padrao, tipo de agrupament padrao, driver de fonte de dados padrao,
70  nome usuario e senha por driver, localizacao do mapa de layout (quickview ou coisa assim),
71  estilo de ponto padrao, estilo de linha padrao, estilo de poligono padrao,
72  local de salvar o projeto, local de exportar dados,
73  local de importar dados.... e varias outras preferencias do usuario
74  */
75  class TECOLOREXPORT ColorSchemeCatalogManager : public te::common::Singleton<ColorSchemeCatalogManager>
76  {
78 
79  public:
80 
81  /** @name ColorSchemeCatalogManager Accessor Method
82  * Method used to access the data stored on this manager.
83  */
84  //@{
85 
86  /*!
87  \brief Inializes the manager from a JSON file containing instances of color schemes
88 
89  This methods reads the file "TE_JSON_FILES_LOCATION/color_ramps.json" for color schemes definitions and insert them on the manager if it is empty.
90  \exception te::srs::Exception if the JSON file is not well formed.
91  */
92  void init();
93 
94  /*!
95  \brief It inserts a new catalog that will be managed by ColorSchemeCatalogManager.
96 
97  \param c The new catalog to be managed by this manager.
98 
99  \exception Exception If the catalog already exists it will raise an exception.
100 
101  \note Don't free the resources used by the catalog, the manager will take the ownership of it.
102  */
103  void insert(ColorSchemeCatalog* c);
104 
105  /*!
106  \brief It removes the internal reference to the catalog.
107 
108  \param c The catalog to be removed.
109 
110  \exception Exception If the catalog doesn't exist it will raise an exception.
111 
112  \note The caller of this method will take the ownership of the catalog.
113  */
114  void disconnect(ColorSchemeCatalog* c);
115 
116  /*!
117  \brief It removes the catalog from the manager and clears it resources.
118 
119  \param c The catalog to be removed.
120 
121  \exception Exception If the catalog doesn't exist it will raise an exception.
122 
123  \note The memory pointed by c will be deallocated. Don't reference it anymore.
124  */
125  void erase(ColorSchemeCatalog* c);
126 
127  /*!
128  \brief It returns the catalog identified by a given name or NULL if none is found.
129 
130  \param name The name of the catalog we are looking for.
131 
132  \return A pointer to a catalog (don't free the pointer) or NULL if none is found.
133  */
134  ColorSchemeCatalog* findByName(const std::string& name) const;
135 
136  /*!
137  \brief It returns a pair of iterators over the catalogs of this manager.
138 
139  \return A pair of iterators over the catalogs of this manager where pair.first will be
140  the beginning and pair.second will be the end iterator.
141  */
142  std::pair<std::vector<ColorSchemeCatalog*>::const_iterator,
143  std::vector<ColorSchemeCatalog*>::const_iterator> getIterator() const;
144 
145  /*!
146  \brief It returns the list of catalogs available in the system.
147 
148  \return The list of catalogs available in the system.
149  */
150  const std::vector<ColorSchemeCatalog*>& getCatalogs() const;
151 
152  /*!
153  \brief It returns true if the manager contains at least one catalog. If no catalog exists, it returns false.
154 
155  \return True if the manager contains at least one catalog. If no catalog exists, it returns false.
156  */
157  bool isEmpty() const;
158 
159  /*! \brief It unloads all catalogs managed by ColorSchemeCatalogManager. */
160  void clear();
161 
162  //@}
163 
164  /** @name Initializer Methods
165  * Methods related to instantiation and destruction.
166  */
167  //@{
168 
169  /*! \brief Destructor. */
171 
172  //@}
173 
174  protected:
175 
176  /** @name Initializer Methods
177  * Methods related to instantiation and destruction.
178  */
179  //@{
180 
181  /*! \brief It initializes the Singleton. */
183 
184  //@}
185 
186  private:
187 
188  /** @name Copy Constructor and Assignment Operator
189  * Copy constructor and assignment operator not allowed.
190  */
191  //@{
192 
193  /*!
194  \brief Copy constructor not allowed.
195 
196  \param rhs The right-hand-side copy that would be used to copy from.
197  */
199 
200  /*!
201  \brief Assignment operator not allowed.
202 
203  \param rhs The right-hand-side copy that would be used to copy from.
204 
205  \return A reference to this object.
206  */
208 
209  //@}
210 
211  private:
212 
213  std::vector<ColorSchemeCatalog*> m_catalogs; //!< This is the list of all system's loaded catalogs.
214  std::map<std::string, ColorSchemeCatalog*> m_catalogIdxByName; //!< An index from catalog's name to catalog's instance (note: we can not have duplicated names).
215  };
216 
217  } // end namespace color
218 } // end namespace te
219 
220 #endif // __TERRALIB_COLOR_INTERNAL_COLORSCHEMECATALOGMANAGER_H
221 
std::map< std::string, ColorSchemeCatalog * > m_catalogIdxByName
An index from catalog's name to catalog's instance (note: we can not have duplicated names)...
Configuration flags for the Color module of TerraLib.
The ColorSchemeCatalogManager is a singleton that can be used to manage all loaded color scheme catal...
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
URI C++ Library.
std::vector< ColorSchemeCatalog * > m_catalogs
This is the list of all system's loaded catalogs.
A catalog for color schemes.
#define TECOLOREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:73
Template support for singleton pattern.
Definition: Singleton.h:100