All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSet.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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  */
70  DataSet(PGresult* result,
71  const std::vector<int>& ptypes,
72  bool timeIsInteger = true);
73 
74  /*! \brief The destructor will clear the internal PGresult. */
75  ~DataSet();
76 
77  te::common::TraverseType getTraverseType() const;
78 
79  te::common::AccessPolicy getAccessPolicy() const;
80 
81  std::size_t getNumProperties() const;
82 
83  int getPropertyDataType(std::size_t i) const;
84 
85  std::string getPropertyName(std::size_t i) const;
86 
87  std::string getDatasetNameOfProperty(std::size_t i) const;
88 
89  bool isEmpty() const;
90 
91  bool isConnected() const;
92 
93  std::size_t size() const;
94 
95  std::auto_ptr<te::gm::Envelope> getExtent(std::size_t i);
96 
97  bool moveNext();
98 
99  bool movePrevious();
100 
101  bool moveBeforeFirst();
102 
103  bool moveFirst();
104 
105  bool moveLast();
106 
107  bool move(std::size_t i);
108 
109  bool isAtBegin() const;
110 
111  bool isBeforeBegin() const;
112 
113  bool isAtEnd() const;
114 
115  bool isAfterEnd() const;
116 
117  char getChar(std::size_t i) const;
118 
119  unsigned char getUChar(std::size_t i) const;
120 
121  boost::int16_t getInt16(std::size_t i) const;
122 
123  boost::int32_t getInt32(std::size_t i) const;
124 
125  boost::int64_t getInt64(std::size_t i) const;
126 
127  bool getBool(std::size_t i) const;
128 
129  float getFloat(std::size_t i) const;
130 
131  double getDouble(std::size_t i) const;
132 
133  std::string getNumeric(std::size_t i) const;
134 
135  std::string getString(std::size_t i) const;
136 
137  std::auto_ptr<te::dt::ByteArray> getByteArray(std::size_t i) const;
138 
139  std::auto_ptr<te::gm::Geometry> getGeometry(std::size_t i) const;
140 
141  std::auto_ptr<te::rst::Raster> getRaster(std::size_t i) const;
142 
143  std::auto_ptr<te::dt::DateTime> getDateTime(std::size_t i) const;
144 
145  std::auto_ptr<te::dt::Array> getArray(std::size_t i) const;
146 
147  bool isNull(std::size_t i) const;
148 
149  /** @name PostGIS Extended Methods
150  * Methods that exists only in the PostGIS DataSet implementation.
151  */
152  //@{
153 
154  /*!
155  \brief It returns the internal pg result.
156 
157  \return The internal pg result.
158  */
159  PGresult* getPGResult() const { return m_result; }
160 
161  //@}
162 
163  protected:
164 
165  int m_i; //!< The index of the current row.
166  int m_size; //!< The number of datasets in the collection.
167  PGresult* m_result; //!< The internal buffer with the result query.
168  std::vector<int> m_ptypes; //!< The list of property types.
169  te::gm::Envelope* m_mbr; //!< The dataset extent.
170  bool m_timeIsInteger; //!< It indicates if the postgis stores, internally, the time and timestamp as an integer.
171  };
172 
173  } // end namespace pgis
174 } // end namespace te
175 
176 
177 #endif // __TERRALIB_POSTGIS_INTERNAL_DATASET_H
178 
179 
180 
Configuration flags for the PostGIS Driver Implementation of TerraLib.
PGresult * m_result
The internal buffer with the result query.
Definition: DataSet.h:167
int m_i
The index of the current row.
Definition: DataSet.h:165
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
bool m_timeIsInteger
It indicates if the postgis stores, internally, the time and timestamp as an integer.
Definition: DataSet.h:170
te::gm::Envelope * m_mbr
The dataset extent.
Definition: DataSet.h:169
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
struct pg_result PGresult
Definition: Connection.h:48
#define TEPGISEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:221
std::vector< int > m_ptypes
The list of property types.
Definition: DataSet.h:168
Implementation of a dataset for the PostGIS driver.
Definition: DataSet.h:60
int m_size
The number of datasets in the collection.
Definition: DataSet.h:166
double getDouble(const std::string &value, std::vector< std::string > &sVector)
Definition: Utils.cpp:54
PGresult * getPGResult() const
It returns the internal pg result.
Definition: DataSet.h:159
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111