DataSet.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/postgis/DataSet.h
22 
23  \brief Implementation of a dataset for the PostGIS driver.
24 */
25 
26 #ifndef __TERRALIB_POSTGIS_INTERNAL_DATASET_H
27 #define __TERRALIB_POSTGIS_INTERNAL_DATASET_H
28 
29 // TerraLib
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "Config.h"
32 
33 // Forward declaration for libpq
34 //extern "C"
35 //{
36 // struct pg_conn;
37 // typedef struct pg_conn PGconn;
38 // struct pg_result;
39 // typedef struct pg_result PGresult;
40 //}
41 
42 namespace te
43 {
44 // Forward declarations
45  namespace da
46  {
47  class DataSource;
48  class GeometryProperty;
49  }
50 
51  namespace pgis
52  {
53  /*!
54  \class DataSet
55 
56  \brief Implementation of a dataset for the PostGIS driver.
57 
58  \sa te::da::DataSet
59  */
61  {
62  public:
63 
64  /*!
65  \brief Constructor.
66 
67  \param result The internal PGresult.
68  \param ds The data source.
69  \param timeIsInteger A flag that indicates if the postgis stores, internally, the time and timestamp as an integer.
70  \param ce The connection character encoding.
71  */
72  DataSet(PGresult* result,
73  const std::vector<int>& ptypes,
74  bool timeIsInteger = true,
76 
77  /*! \brief The destructor will clear the internal PGresult. */
78  ~DataSet();
79 
80  te::common::TraverseType getTraverseType() const;
81 
82  te::common::AccessPolicy getAccessPolicy() const;
83 
84  std::size_t getNumProperties() const;
85 
86  int getPropertyDataType(std::size_t i) const;
87 
88  std::string getPropertyName(std::size_t i) const;
89 
90  te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const;
91 
92  std::string getDatasetNameOfProperty(std::size_t i) const;
93 
94  bool isEmpty() const;
95 
96  bool isConnected() const;
97 
98  std::size_t size() const;
99 
100  std::auto_ptr<te::gm::Envelope> getExtent(std::size_t i);
101 
102  bool moveNext();
103 
104  bool movePrevious();
105 
106  bool moveBeforeFirst();
107 
108  bool moveFirst();
109 
110  bool moveLast();
111 
112  bool move(std::size_t i);
113 
114  bool isAtBegin() const;
115 
116  bool isBeforeBegin() const;
117 
118  bool isAtEnd() const;
119 
120  bool isAfterEnd() const;
121 
122  char getChar(std::size_t i) const;
123 
124  unsigned char getUChar(std::size_t i) const;
125 
126  boost::int16_t getInt16(std::size_t i) const;
127 
128  boost::int32_t getInt32(std::size_t i) const;
129 
130  boost::int64_t getInt64(std::size_t i) const;
131 
132  bool getBool(std::size_t i) const;
133 
134  float getFloat(std::size_t i) const;
135 
136  double getDouble(std::size_t i) const;
137 
138  std::string getNumeric(std::size_t i) const;
139 
140  std::string getString(std::size_t i) const;
141 
142  std::auto_ptr<te::dt::ByteArray> getByteArray(std::size_t i) const;
143 
144  std::auto_ptr<te::gm::Geometry> getGeometry(std::size_t i) const;
145 
146  std::auto_ptr<te::rst::Raster> getRaster(std::size_t i) const;
147 
148  std::auto_ptr<te::dt::DateTime> getDateTime(std::size_t i) const;
149 
150  std::auto_ptr<te::dt::Array> getArray(std::size_t i) const;
151 
152  bool isNull(std::size_t i) const;
153 
154  /** @name PostGIS Extended Methods
155  * Methods that exists only in the PostGIS DataSet implementation.
156  */
157  //@{
158 
159  /*!
160  \brief It returns the internal pg result.
161 
162  \return The internal pg result.
163  */
164  PGresult* getPGResult() const { return m_result; }
165 
166  //@}
167 
168  protected:
169 
170  int m_i; //!< The index of the current row.
171  int m_size; //!< The number of datasets in the collection.
172  PGresult* m_result; //!< The internal buffer with the result query.
173  std::vector<int> m_ptypes; //!< The list of property types.
174  te::gm::Envelope* m_mbr; //!< The dataset extent.
175  bool m_timeIsInteger; //!< It indicates if the postgis stores, internally, the time and timestamp as an integer.
176  te::common::CharEncoding m_ce; //!< The connection character encoding.
177  };
178 
179  } // end namespace pgis
180 } // end namespace te
181 
182 
183 #endif // __TERRALIB_POSTGIS_INTERNAL_DATASET_H
bool m_timeIsInteger
It indicates if the postgis stores, internally, the time and timestamp as an integer.
Definition: DataSet.h:175
CharEncoding
Supported charsets (character encoding).
int m_size
The number of datasets in the collection.
Definition: DataSet.h:171
struct pg_result PGresult
Definition: Connection.h:48
PGresult * getPGResult() const
It returns the internal pg result.
Definition: DataSet.h:164
te::common::CharEncoding m_ce
The connection character encoding.
Definition: DataSet.h:176
std::vector< int > m_ptypes
The list of property types.
Definition: DataSet.h:173
#define TEPGISEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:195
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
Implementation of a dataset for the PostGIS driver.
Definition: DataSet.h:60
Configuration flags for the PostGIS Driver Implementation of TerraLib.
URI C++ Library.
PGresult * m_result
The internal buffer with the result query.
Definition: DataSet.h:172
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
int m_i
The index of the current row.
Definition: DataSet.h:170
te::gm::Envelope * m_mbr
The dataset extent.
Definition: DataSet.h:174