Loading...
Searching...
No Matches
DataTypeManager.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/datatype/DataTypeManager.h
22
23 \brief A singleton for managing all data types in the system.
24*/
25
26#ifndef __TERRALIB_DATATYPE_INTERNAL_DATATYPEMANAGER_H
27#define __TERRALIB_DATATYPE_INTERNAL_DATATYPEMANAGER_H
28
29// TerraLib
30#include "../common/Singleton.h"
31#include "DataType.h"
32#include "Exception.h"
33
34// STL
35#include <set>
36
37namespace te
38{
39 namespace dt
40 {
41 /*!
42 \class DataType
43
44 \brief A singleton for managing all data types in the system.
45
46 TerraLib keeps information about all available data types
47 in this singleton. Here, you can find all supported data types.
48
49 Basic constraints for data types:
50 <ul>
51 <li>No two data types may have the same name</li>
52 <li>The id of a data type will be dynamically generated by the manager</li>
53 <li>Data type names must be in capital letters although it can contains numbers and other symbols</li>
54 </ul>
55
56 \ingroup datatype
57
58 \sa DataType
59
60 \todo Remove the static data member and use the type code!
61 */
63 {
65
66 public:
67
68 /*!
69 \brief It adds a new data type to the system.
70
71 \param dt The data type to be added.
72
73 \return The id associated to the new data type on success (a number greater than 0).
74
75 \exception Exception It throws an exception if a data type with the same name already exists in the system.
76
77 \note Not thread-safe.
78 */
79 int add(const DataType& dt);
80
81 /*!
82 \brief It adds a new data type to the system.
83
84 \param name The new data type name.
85 \param description The data type description.
86
87 \return The id associated to the new data type on success (a number greater than 0).
88
89 \exception Exception It throws an exception if a data type with the same name already exists in the system.
90
91 \note Not thread-safe.
92 */
93 int add(const std::string& name, const std::string& description);
94
95 /*!
96 \brief It removes the data type.
97
98 \param dt The data type.
99 */
100 void remove(const DataType* dt);
101
102 /*!
103 \brief It finds a data type having the given id.
104
105 \param id The data type id.
106
107 \return The data type having the id or NULL if none is found.
108 */
109 const DataType* find(int id) const;
110
111 /*!
112 \brief It finds a data type having the given name.
113
114 \param name The data type name.
115
116 \return The data type having the name or NULL if none is found.
117 */
118 const DataType* find(const std::string& name) const;
119
120 protected:
121
122 /*! \brief Constructor for singletons is protected. */
124
125 /*! \brief Destructor for singletons is protected. */
127
128 private:
129
130 /*!
131 \struct NameComparer
132
133 \brief A functor for comparing a pair of pointers to data types by name.
134 */
136 {
137 bool operator()(const DataType* f, const DataType* s) const
138 {
139 return f->getName() < s->getName();
140 }
141 };
142
143 /*!
144 \struct IdComparer
145
146 \brief A functor for comparing a pair of pointers to data types by id.
147 */
149 {
150 bool operator()(const DataType* f, const DataType* s) const
151 {
152 return f->getId() < s->getId();
153 }
154 };
155
156 std::set<DataType*, IdComparer> m_types; //!< The set of data types ordered by id.
157 std::set<DataType*, NameComparer> m_nameIdx; //!< The set of data types ordered by name.
158
159 static int sm_lastId; //!< The id value of the last inserted data type.
160 };
161
162 } // end namespace da
163} // end namespace te
164
165#endif // __TERRALIB_DATATYPE_INTERNAL_DATATYPEMANAGER_H
166
It stores information about a data type.
Template support for singleton pattern.
Definition: Singleton.h:101
const DataType * find(int id) const
It finds a data type having the given id.
int add(const DataType &dt)
It adds a new data type to the system.
~DataTypeManager()
Destructor for singletons is protected.
static int sm_lastId
The id value of the last inserted data type.
void remove(const DataType *dt)
It removes the data type.
const DataType * find(const std::string &name) const
It finds a data type having the given name.
int add(const std::string &name, const std::string &description)
It adds a new data type to the system.
std::set< DataType *, NameComparer > m_nameIdx
The set of data types ordered by name.
std::set< DataType *, IdComparer > m_types
The set of data types ordered by id.
DataTypeManager()
Constructor for singletons is protected.
It stores information about a data type.
Definition: DataType.h:56
int getId() const
It returns the data type id.
Definition: DataType.h:133
const std::string & getName() const
It returns the data type name.
Definition: DataType.h:138
TerraLib.
A functor for comparing a pair of pointers to data types by id.
bool operator()(const DataType *f, const DataType *s) const
A functor for comparing a pair of pointers to data types by name.
bool operator()(const DataType *f, const DataType *s) const
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
An exception class for the XML module.