MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Buffer.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2014 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO 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, or
8  (at your option) any later version.
9 
10  MeteoIO 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 MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef BUFFER_H
19 #define BUFFER_H
20 
25 
26 namespace mio {
27 
38 class MeteoBuffer {
39  public:
40  MeteoBuffer() : ts_buffer(), ts_start(), ts_end() {}
41 
48  bool get(const Date& date, METEO_SET &vecMeteo) const;
49 
57  bool get(const Date& date_start, const Date& date_end, std::vector< METEO_SET > &vecMeteo) const;
58 
68  double getAvgSamplingRate() const;
69 
76  Date getBufferStart() const;
77 
84  Date getBufferEnd() const;
85 
90  bool empty() const;
91 
95  void clear();
96 
103  void push(const Date& date_start, const Date& date_end, const std::vector< METEO_SET >& vecMeteo);
104 
105 
112  void push(const Date& date_start, const Date& date_end, const std::vector<MeteoData>& vecMeteo);
113 
114  const std::string toString() const;
115 
116  //HACK: these should be removed in order to hide the internals! But this requires a re-write of MeteoProcessor
117  std::vector< METEO_SET >& getBuffer();
118  void setBufferStart(const Date& date);
119  void setBufferEnd(const Date& date);
120  private:
121  std::vector< METEO_SET > ts_buffer;
122  Date ts_start, ts_end;
123 };
124 
135 //TODO: make it a template so it can buffer dems, 2D, 3D grids
136 class GridBuffer {
137  public:
138  GridBuffer(const size_t& in_max_grids);
139 
140  bool empty() const {return IndexBufferedGrids.empty();}
141  void clear() {mapBufferedGrids.clear(); mapBufferedInfos.clear(); IndexBufferedGrids.clear();}
142  size_t size() const {return IndexBufferedGrids.size();}
143 
144  void setMaxGrids(const size_t& in_max_grids) {max_grids=in_max_grids;}
145 
146  bool get(DEMObject& grid, const std::string& grid_hash) const;
147  bool get(Grid2DObject& grid, const std::string& grid_hash) const;
148  bool get(Grid2DObject& grid, const std::string& grid_hash, std::string& grid_info) const;
149  bool get(Grid2DObject& grid, const MeteoGrids::Parameters& parameter, const Date& date) const;
150 
151  void push(const DEMObject& grid, const std::string& grid_hash);
152  void push(const Grid2DObject& grid, const std::string& grid_hash);
153  void push(const Grid2DObject& grid, const std::string& grid_hash, const std::string& grid_info);
154  void push(const Grid2DObject& grid, const MeteoGrids::Parameters& parameter, const Date& date);
155 
156  const std::string toString() const;
157  private:
158  std::map<std::string, Grid2DObject> mapBufferedGrids;
159  std::map<std::string, DEMObject> mapBufferedDEMs;
160  std::map<std::string, std::string> mapBufferedInfos;
161  std::vector<std::string> IndexBufferedGrids; // this is required in order to know which grid is the oldest one
162  std::vector<std::string> IndexBufferedDEMs; // this is required in order to know which grid is the oldest one
163  size_t max_grids;
164 };
165 
166 }
167 #endif
A class to buffer meteorological data. This class buffers MeteoData objects. It is currently NOT a pr...
Definition: Buffer.h:38
std::vector< MeteoData > METEO_SET
Definition: MeteoData.h:29
bool empty() const
Check if the buffer is empty.
Definition: Buffer.cc:74
bool empty() const
Definition: Buffer.h:140
void clear()
Definition: Buffer.h:141
MeteoBuffer()
Definition: Buffer.h:40
size_t size() const
Definition: Buffer.h:142
double getAvgSamplingRate() const
Returns the average sampling rate in the data. This computes the average sampling rate of the data th...
Definition: Buffer.cc:227
const std::string toString() const
Definition: Buffer.cc:274
A class to buffer gridded data. This class buffers Grid2D objects. It implements a proper ring buffer...
Definition: Buffer.h:136
Date getBufferEnd() const
Returns the end of the buffer. This is the end date of the request that was given to the IOHandler...
Definition: Buffer.cc:256
void setMaxGrids(const size_t &in_max_grids)
Definition: Buffer.h:144
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:39
void push(const DEMObject &grid, const std::string &grid_hash)
Definition: Buffer.cc:367
Date getBufferStart() const
Returns the begining of the buffer. This is the start date of the request that was given to the IOHan...
Definition: Buffer.cc:251
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:37
void setBufferStart(const Date &date)
Definition: Buffer.cc:266
void clear()
Clear the buffer; the data is deleted and the start and end dates reset to undef
Definition: Buffer.cc:80
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:79
GridBuffer(const size_t &in_max_grids)
Definition: Buffer.cc:297
const std::string toString() const
Definition: Buffer.cc:414
void push(const Date &date_start, const Date &date_end, const std::vector< METEO_SET > &vecMeteo)
Add data representing the available data between two dates.
Definition: Buffer.cc:152
std::vector< METEO_SET > & getBuffer()
Definition: Buffer.cc:261
Parameters
Definition: MeteoData.h:44
void setBufferEnd(const Date &date)
Definition: Buffer.cc:270