HDF5Serie

Project Page
/home/user/MBSimWindows/hdf5serie/hdf5serie/hdf5serie/simpleattribute.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_SIMPLEATTRIBUTE_H_
00023 #define _HDF5SERIE_SIMPLEATTRIBUTE_H_
00024 
00025 #include <H5Cpp.h>
00026 #include <vector>
00027 #include <string>
00028 #include <hdf5serie/toh5type.h>
00029 #include <assert.h>
00030 
00031 namespace H5 {
00032 
00058   template<class T>
00059   class SimpleAttribute : public Attribute {
00060     private:
00061       DataType memDataType;
00062     public:
00064       SimpleAttribute();
00065 
00067       SimpleAttribute(const SimpleAttribute<T>& attribute);
00068 
00084       SimpleAttribute(const H5Object& parent, const std::string& name, bool create=false);
00085 
00090       SimpleAttribute(const H5Object& parent, const std::string& name, const T& data);
00091 
00107       void create(const H5Object& parent, const std::string& name);
00108 
00113       void open(const H5Object& parent, const std::string& name);
00114 
00119       void write(const T& data);
00120 
00125       T read();
00126 
00131       void write(const H5Object& parent, const std::string& name, const T& data);
00132 
00137       T read(const H5Object& parent, const std::string& name);
00138 
00143       static T getData(const H5Object& parent, const std::string& name);
00144 
00149       static void setData(const H5Object& parent, const std::string& name, const T& data);
00150   };
00151 
00152   // a partial specialisation of class SimpleAttribute<T> for T=std::vector<T>
00153   template<class T>
00154   class SimpleAttribute<std::vector<T> > : public Attribute {
00155     private:
00156       DataType memDataType;
00157     public:
00158       SimpleAttribute();
00159       SimpleAttribute(const SimpleAttribute<std::vector<T> >& attribute);
00160       SimpleAttribute(const H5Object& parent, const std::string& name, const int count=0);
00161       SimpleAttribute(const H5Object& parent, const std::string& name, const std::vector<T>& data);
00162       void create(const H5Object& parent, const std::string& name, const int count);
00163       void open(const H5Object& parent, const std::string& name);
00164       void write(const std::vector<T>& data);
00165       std::vector<T> read();
00166       void write(const H5Object& parent, const std::string& name, const std::vector<T>& data);
00167       std::vector<T> read(const H5Object& parent, const std::string& name);
00168       static std::vector<T> getData(const H5Object& parent, const std::string& name);
00169       static void setData(const H5Object& parent, const std::string& name, const std::vector<T>& data);
00170   };
00171 
00172   // a partial specialisation of class SimpleAttribute<T> for T=std::vector<std::vector<T> >
00173   template<class T>
00174   class SimpleAttribute<std::vector<std::vector<T> > > : public Attribute {
00175     private:
00176       DataType memDataType;
00177     public:
00178       SimpleAttribute();
00179       SimpleAttribute(const SimpleAttribute<std::vector<std::vector<T> > >& attribute);
00180       SimpleAttribute(const H5Object& parent, const std::string& name, const int rows=0, const int columns=0);
00181       SimpleAttribute(const H5Object& parent, const std::string& name, const std::vector<std::vector<T> >& data);
00182       void create(const H5Object& parent, const std::string& name, const int rows, const int columns);
00183       void open(const H5Object& parent, const std::string& name);
00184       void write(const std::vector<std::vector<T> >& data);
00185       std::vector<std::vector<T> > read();
00186       void write(const H5Object& parent, const std::string& name, const std::vector<std::vector<T> >& data);
00187       std::vector<std::vector<T> > read(const H5Object& parent, const std::string& name);
00188       static std::vector<std::vector<T> > getData(const H5Object& parent, const std::string& name);
00189       static void setData(const H5Object& parent, const std::string& name, const std::vector<std::vector<T> >& data);
00190   };
00191 
00192 }
00193 
00194 #endif