hdf5serie  2.0.0
HDF5 Serie
vectorserie.h
1 /* Copyright (C) 2009 Markus Friedrich
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact:
18  * friedrich.at.gc@googlemail.com
19  *
20  */
21 
22 #ifndef _HDF5SERIE_VECTORSERIE_H_
23 #define _HDF5SERIE_VECTORSERIE_H_
24 
25 #include <hdf5serie/interface.h>
26 #include <hdf5serie/file.h>
27 #include <vector>
28 
29 namespace H5 {
30 
31 
32 
62  template<class T>
63  class VectorSerie : public Dataset {
64  friend class Container<Object, GroupBase>;
65  private:
66  hid_t memDataTypeID; // no need to useScopedHID since only a static hid_t is stored here
67  ScopedHID memDataSpaceID;
68  hsize_t dims[2];
69  protected:
70  VectorSerie(int dummy, GroupBase *parent_, const std::string &name_);
71  VectorSerie(GroupBase *parent_, const std::string &name_, int cols,
72  int compression=File::getDefaultCompression(), int chunkSize=File::getDefaultChunkSize());
73  ~VectorSerie() override;
74  void close() override;
75 
76  public:
81  void setDescription(const std::string& description);
82 
88  void append(const T data[], size_t size);
89 
94  template<class DataType>
95  void append(const DataType &data){
96  append(&data[0], data.size());
97  }
98 
100  inline int getRows();
101 
103  inline unsigned int getColumns();
104 
109  void getRow(int row, size_t size, T data[]);
110 
115  template<class DataType>
116  void getRow(const int row, DataType &data) {
117  getRow(row, data.size(), &data[0]);
118  }
119 
122  std::vector<T> getRow(const int row) {
123  std::vector<T> data(dims[1]);
124  getRow(row, dims[1], &data[0]);
125  return data;
126  }
127 
132  void getColumn(int column, size_t size, T data[]);
133 
138  template<class DataType>
139  void getColumn(const int column, DataType &data) {
140  getColumn(column, data.size(), &data[0]);
141  }
142 
145  std::vector<T> getColumn(const int row) {
146  size_t rows=getRows();
147  std::vector<T> data(rows);
148  getColumn(row, rows, &data[0]);
149  return data;
150  }
151 
156  std::string getDescription();
157 
158  void setColumnLabel(const std::vector<std::string> &columnLabel);
159 
165  std::vector<std::string> getColumnLabel();
166  };
167 
168 
169 
170  // inline definitions
171 
172  template<class T>
174  ScopedHID fileSpaceID(H5Dget_space(id), &H5Sclose);
175  H5Sget_simple_extent_dims(fileSpaceID, dims, nullptr);
176  return dims[0];
177  }
178 
179  template<class T>
180  unsigned int VectorSerie<T>::getColumns() {
181  return dims[1];
182  }
183 
184 }
185 
186 #endif // _TIMESERIE_H_
void getColumn(int column, size_t size, T data[])
Returns the data vector at column column.
Definition: vectorserie.cc:142
std::vector< T > getColumn(const int row)
Definition: vectorserie.h:145
std::vector< T > getRow(const int row)
Definition: vectorserie.h:122
Definition: interface.h:212
unsigned int getColumns()
Returns the number of columns(=number of data elements) in the dataset.
Definition: vectorserie.h:180
std::vector< std::string > getColumnLabel()
Returns the column labels.
Definition: vectorserie.cc:171
void getRow(int row, size_t size, T data[])
Returns the data vector at row row The first row is 0. The last avaliable row ist getRows()-1....
Definition: vectorserie.cc:121
Definition: interface.h:47
Definition: group.h:31
Definition: interface.h:87
Definition: interface.h:273
void getRow(const int row, DataType &data)
Definition: vectorserie.h:116
Serie of vectors.
Definition: vectorserie.h:63
std::string getDescription()
Return the description for the dataset.
Definition: vectorserie.cc:157
void append(const T data[], size_t size)
Append a data vector.
Definition: vectorserie.cc:107
int getRows()
Returns the number of rows in the dataset.
Definition: vectorserie.h:173
void append(const DataType &data)
Definition: vectorserie.h:95
void getColumn(const int column, DataType &data)
Definition: vectorserie.h:139
void setDescription(const std::string &description)
Sets a description for the dataset.
Definition: vectorserie.cc:101