TimeSeriesIterator.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 TimeSeriesIterator.h
22 
23  \brief This file contains a time series iterator.
24  */
25 
26 #ifndef __TERRALIB_ST_INTERNAL_TIMESERIESITERATOR_H
27 #define __TERRALIB_ST_INTERNAL_TIMESERIESITERATOR_H
28 
29 // ST
30 #include "../../Config.h"
31 #include "TimeSeriesObservation.h"
32 
33 // STL
34 #include <vector>
35 #include <memory>
36 
37 // Boost
38 #include <boost/shared_ptr.hpp>
39 
40 // Forward declarations
41 namespace te { namespace dt { class DateTime; } }
42 namespace te { namespace gm { class Geometry; } }
43 
44 namespace te
45 {
46  namespace st
47  {
48  /*!
49  \class TimeSeriesIterator
50 
51  \brief A class to traverse the observations of a TimeSeries.
52 
53  This class provides a mechanism to traverse the time series
54  observations sequentially, ordered by time.
55 
56  An example of use:
57 
58  TimeSeriesIterator it = tj.begin();
59  while(it!=tj.end())
60  {
61  DateTime* t = it.getTime();
62  double v = it.getDouble(); //or getValue() or getInt or...
63  ++it;
64  }
65 
66  \sa TimeSeries
67  */
69  {
70  public:
71 
72  /*! \brief Empty constructor. */
74 
75  /*!
76  \brief Constructor.
77 
78  \param it A iterator that points to the TimeSeries observations
79  */
80  TimeSeriesIterator(TimeSeriesObservationSet::const_iterator& it);
81 
82  /*! \brief Assignment operator. */
84 
85  /*! \brief Operator == */
86  bool operator==(const TimeSeriesIterator& rhs);
87 
88  /*! \brief Operator != */
89  bool operator!=(const TimeSeriesIterator& rhs);
90 
91  /*!
92  \brief Prefix operator ++
93 
94  After using this operator, the internal cursor points
95  to the next TimeSeries observation.
96 
97  The semantics of prefix is this: Increment the value and then fetch it.
98  */
100 
101  /*!
102  \brief Postfix operator ++
103 
104  After using this operator, the internal cursor points
105  to the next TimeSeries observation.
106 
107  The semantics of postfix is: Fetch the value and then increment the original.
108  */
110 
111  /*!
112  \brief Prefix operator --
113 
114  After using this operator, the internal cursor points
115  to the preceding TimeSeries observation.
116 
117  The semantics of prefix is this: Increment the value and then fetch it.
118  */
120 
121  /*!
122  \brief Postfix operator --
123 
124  After using this operator, the internal cursor points
125  to the preceding TimeSeries observation.
126 
127  The semantics of postfix is: Fetch the value and then increment the original.
128  */
130 
131  /*!
132  \brief Prefix operator *
133 
134  It returns the observation (a pair of shared pointers to the time and value)
135  pointed by the internal cursor.
136  */
138 
139  /*!
140  \brief It returns the datetime pointed by the internal cursor.
141 
142  \return A pointer to the datetime pointed by the internal cursor.
143 
144  \note The caller will NOT take the ownership of the returned pointer.
145  */
147 
148  /*!
149  \brief It returns the attribute value pointed by the internal cursor.
150 
151  \return A pointer to the attribute value pointed by the internal cursor.
152 
153  \note The caller will NOT take the ownership of the returned pointer.
154  */
156 
157  /*!
158  \brief It returns the attribute value as a double pointed by the internal cursor.
159 
160  \return A pointer to the attribute value as a double pointed by the internal cursor.
161  */
162  double getDouble() const;
163 
164  /*!
165  \brief It returns the attribute value as an integer pointed by the internal cursor.
166 
167  \return A pointer to the attribute value as an integer pointed by the internal cursor.
168  */
169  int getInt() const;
170 
171  /*!
172  \brief It returns the attribute value as a string pointed by the internal cursor.
173 
174  \return A pointer to the attribute value as a string pointed by the internal cursor.
175  */
176  std::string getString() const;
177 
178 
179  /*! \brief Virtual destructor. */
181 
182  private:
183 
184  TimeSeriesObservationSet::const_iterator m_it; //!< The internal cursor
185  };
186 
187  /*!
188  \struct TimeSeriesPatch
189 
190  \brief A struct to represent a patch or a continuous piece of a time series.
191  */
193  {
194  public:
196 
197  TimeSeriesIterator begin() const { return m_begin; }
198 
199  TimeSeriesIterator end() const { return m_end; }
200 
201  private:
202  TimeSeriesIterator m_begin; //a pointer to the first observation
203  TimeSeriesIterator m_end; //a pointer to the position after the last observation
204  };
205 
206  } // end namespace st
207 } // end namespace te
208 
209 #endif // __TERRALIB_ST_INTERNAL_TIMESERIESITERATOR_H
210 
211 
This file contains a class to represent a time series observation.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
A class to traverse the observations of a TimeSeries.
TimeSeriesIterator()
Empty constructor.
TimeSeriesIterator & operator++()
Prefix operator ++.
const TimeSeriesIterator & operator=(const TimeSeriesIterator &rhs)
Assignment operator.
bool operator==(const TimeSeriesIterator &rhs)
Operator ==.
TimeSeriesIterator operator++(int aux)
Postfix operator ++.
virtual ~TimeSeriesIterator()
Virtual destructor.
TimeSeriesIterator(TimeSeriesObservationSet::const_iterator &it)
Constructor.
te::dt::DateTime * getTime() const
It returns the datetime pointed by the internal cursor.
TimeSeriesObservationSet::const_iterator m_it
The internal cursor.
double getDouble() const
It returns the attribute value as a double pointed by the internal cursor.
TimeSeriesObservation operator*() const
Prefix operator *.
std::string getString() const
It returns the attribute value as a string pointed by the internal cursor.
bool operator!=(const TimeSeriesIterator &rhs)
Operator !=.
int getInt() const
It returns the attribute value as an integer pointed by the internal cursor.
TimeSeriesIterator operator--(int aux)
Postfix operator –.
te::dt::AbstractData * getValue() const
It returns the attribute value pointed by the internal cursor.
TimeSeriesIterator & operator--()
Prefix operator –.
A class to represent an observation (time and value) of a time series.
TerraLib.
A struct to represent a patch or a continuous piece of a time series.
TimeSeriesPatch(TimeSeriesIterator b, TimeSeriesIterator e)
TimeSeriesIterator end() const
TimeSeriesIterator m_end
TimeSeriesIterator begin() const
TimeSeriesIterator m_begin
#define TESTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:88