Array.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/Array.h
22 
23  \brief Class for dealing with arrays of abstract data.
24 */
25 
26 #ifndef __TERRALIB_DATATYPE_INTERNAL_ARRAY_H
27 #define __TERRALIB_DATATYPE_INTERNAL_ARRAY_H
28 
29 // TerraLib
30 #include "AbstractData.h"
31 #include "Enums.h"
32 
33 // STL
34 #include <map>
35 #include <string>
36 #include <vector>
37 
38 namespace te
39 {
40  namespace dt
41  {
42  /*!
43  \class Array
44 
45  \brief The type for variable-length multidimensional arrays.
46 
47  \note This class was not designed to achieve performance,
48  since it maps a vector of positions to one abstract data. This
49  class is only a container to be used by database drivers. If
50  you need a high performance array class with matrix operations,
51  see the Matrix module. To access the data, you must define a vector
52  of positions, where each dimension in the vector corresponds to the
53  respective dimension in the array.
54 
55  \ingroup datatype
56 
57  \sa ArrayProperty, AbstractData
58  */
60  {
61  public:
62  /*!
63  \brief Multi-dimensional array constructor.
64 
65  \param d The number of dimensions of the array.
66  \param t The data type.
67  */
68  Array(std::size_t d, int t);
69 
70  /*!
71  \brief Copy constructor.
72 
73  \param rhs The right-hand-side instance.
74  */
75  Array(const Array& rhs);
76 
77  /*!
78  \brief Assignment operator.
79 
80  \param rhs The right-hand-side instance.
81 
82  \return A reference to this array.
83  */
84  Array& operator=(const Array& rhs);
85 
86  /*! \brief Destructor. */
87  ~Array();
88 
89  /*! \brief Returns the numbe of dimensions of the array. */
90  std::size_t getDimension() const;
91 
92  /*!
93  \brief Returns the data type of the elements of the array.
94 
95  \note The attribute types are listed in terralib/datatype/DataTypes.h
96  */
97  int getElementsTypeCode();
98 
99  /*!
100  \brief Gets the number of elements in the i-th dimension.
101 
102  \param i The dimension index.
103 
104  \return The number of elements in the i-th dimension.
105  */
106  std::size_t getDimensionSize(std::size_t i) const;
107 
108  /*!
109  \brief Inserts data into specified position.
110 
111  \param data The data to be inserted.
112  \param pos The position in the array to insert data (d1, d2, ... dn).
113  */
114  void insert(te::dt::AbstractData* data, const std::vector<std::size_t>& pos);
115 
116  /*!
117  \brief Returns data from specified position.
118 
119  \param i The position in the array to get data (d1, d2, ... dn).
120 
121  \return The data from specified position.
122  */
123  te::dt::AbstractData* getData(const std::vector<std::size_t>& i);
124 
125  /*!
126  \brief Access data in i index.
127 
128  \param i The data index, a vector of std::size_t.
129 
130  \warning The caller is reponsible for providing a valid index.
131 
132  \return A reference to the i-th data.
133  */
134  te::dt::AbstractData& operator[](const std::vector<std::size_t>& i);
135 
136  /*!
137  \brief It creates a new clone of the array.
138 
139  \return A new clone of the array. The caller will take its ownership.
140  */
141  AbstractData* clone() const;
142 
143  /*! \brief Returns the type code for array data: ARRAY_TYPE. */
144  int getTypeCode() const { return ARRAY_TYPE; }
145 
146  /*! \brief Return a string with all the data inside array. */
147  std::string toString() const;
148 
149  protected:
150 
151  std::map<std::vector<std::size_t>, te::dt::AbstractData*> m_data; //!< A map from positions to data.
152  std::size_t m_dimension; //!< The number of dimensions.
153  std::vector<std::size_t> m_dimensionSizes; //!< The vector of sizes for the dimensions.
154  int m_type; //!< The data type of this array.
155  };
156 
157  } // end namespace dt
158 } // end namespace te
159 
160 #endif //__TERRALIB_DATATYPE_INTERNAL_ARRAY_H
int m_type
The data type of this array.
Definition: Array.h:154
A base class for objects that can be retrieved from the data access module.
std::vector< std::size_t > m_dimensionSizes
The vector of sizes for the dimensions.
Definition: Array.h:153
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
The type for variable-length multidimensional arrays.
Definition: Array.h:59
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
URI C++ Library.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
std::size_t m_dimension
The number of dimensions.
Definition: Array.h:152
int getTypeCode() const
Returns the type code for array data: ARRAY_TYPE.
Definition: Array.h:144
General enumerations for the data type module.
std::map< std::vector< std::size_t >, te::dt::AbstractData * > m_data
A map from positions to data.
Definition: Array.h:151