HDF5Serie

Project Page
/home/user/MBSimWindows/hdf5serie/hdf5serie/hdf5serie/vectorserie.h
00001 /* Copyright (C) 2009 Markus Friedrich
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact:
00018  *   friedrich.at.gc@googlemail.com
00019  *
00020  */
00021 
00022 #ifndef _HDF5SERIE_VECTORSERIE_H_
00023 #define _HDF5SERIE_VECTORSERIE_H_
00024 
00025 #include <hdf5serie/interface.h>
00026 #include <hdf5serie/file.h>
00027 #include <vector>
00028 
00029 namespace H5 {
00030 
00031 
00032    
00063   template<class T>
00064   class VectorSerie : public Dataset {
00065     friend class Container<Object, GroupBase>;
00066     private:
00067       hid_t memDataTypeID;
00068       ScopedHID memDataSpaceID;
00069       hsize_t dims[2];
00070     protected:
00071       VectorSerie(int dummy, GroupBase *parent_, const std::string &name_);
00072       VectorSerie(GroupBase *parent_, const std::string &name_, int cols,
00073         int compression=File::getDefaultCompression(), int chunkSize=File::getDefaultChunkSize());
00074       ~VectorSerie();
00075       void close();
00076       void open();
00077 
00078     public:
00083       void setDescription(const std::string& desc);
00084 
00090       void append(const T data[], size_t size);
00091 
00096       template<class DataType>
00097       void append(const DataType &data){
00098         append(&data[0], data.size());
00099       }
00100 
00102       inline int getRows();
00103 
00105       inline unsigned int getColumns();
00106 
00111       void getRow(const int row, size_t size, T data[]);
00112 
00117       template<class DataType>
00118       void getRow(const int row, DataType &data) {
00119         getRow(row, data.size(), &data[0]);
00120       }
00121 
00124       std::vector<T> getRow(const int row) {
00125         std::vector<T> data(dims[1]);
00126         getRow(row, dims[1], &data[0]);
00127         return data;
00128       }
00129 
00134       void getColumn(const int column, size_t size, T data[]);
00135 
00140       template<class DataType>
00141       void getColumn(const int column, DataType &data) {
00142         getColumn(column, data.size(), &data[0]);
00143       }
00144 
00147       std::vector<T> getColumn(const int row) {
00148         size_t rows=getRows();
00149         std::vector<T> data(rows);
00150         getColumn(row, rows, &data[0]);
00151         return data;
00152       }
00153 
00158       std::string getDescription();
00159 
00160       void setColumnLabel(const std::vector<std::string> &columnLabel);
00161 
00167       std::vector<std::string> getColumnLabel();
00168   };
00169 
00170 
00171 
00172   // inline definitions
00173 
00174   template<class T>
00175   int VectorSerie<T>::getRows() {
00176     ScopedHID fileSpaceID(H5Dget_space(id), &H5Sclose);
00177     H5Sget_simple_extent_dims(fileSpaceID, dims, NULL);
00178     return dims[0];
00179   }
00180 
00181   template<class T>
00182   unsigned int VectorSerie<T>::getColumns() {
00183     return dims[1];
00184   }
00185 
00186 }
00187 
00188 #endif // _TIMESERIE_H_