Back to index

salome-kernel  6.5.0
HDFattribute.cc
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
00024 //  File   : HDFattribute.cc
00025 //  Module : SALOME
00026 //
00027 #include "hdfi.h"
00028 #include "HDFexception.hxx"
00029 #include "HDFattribute.hxx"
00030 #include "HDFinternalObject.hxx"
00031 
00032 HDFattribute::HDFattribute(char *name,HDFinternalObject *father,hdf_type type, size_t size)
00033   : HDFobject(name)
00034 {
00035   _father = father;
00036   _fid = _father->GetId();
00037   _type = type;
00038   _size = size;
00039 }
00040 
00041 HDFattribute::HDFattribute(char *name,HDFinternalObject *father)
00042   : HDFobject(name)
00043 {
00044   _father = father;
00045   _fid = _father->GetId();
00046   _type = HDF_NONE;
00047   _size = 0;
00048 }
00049 
00050 void HDFattribute::CreateOnDisk()
00051 {
00052   if ((_id = HDFattrCreate(_fid,_name, _type, _size)) < 0)
00053     throw HDFexception("Can't create attribute");
00054 }
00055 void HDFattribute::OpenOnDisk()
00056 {
00057   if ((_id = HDFattrOpen(_fid,_name)) < 0)
00058     throw HDFexception("Can't open attribute");
00059 }
00060 void HDFattribute::CloseOnDisk()
00061 {
00062   hdf_err ret;
00063 
00064   if ((ret = HDFattrClose(_id)) < 0)
00065       throw HDFexception("Can't close attribute");
00066 }
00067 
00068 void HDFattribute::WriteOnDisk(void *values)
00069 {
00070   hdf_err ret;
00071 
00072   if ((ret = HDFattrWrite(_id,values)) < 0)
00073     throw HDFexception("Can't write attribute");
00074 }
00075 
00076 void HDFattribute::ReadFromDisk(void *values)
00077 {
00078   hdf_err ret; 
00079 
00080   if ((ret = HDFattrRead(_id,values)) < 0)
00081     throw HDFexception("Can't read attribute");
00082 }
00083 
00084 HDFinternalObject * HDFattribute::GetFather()
00085 {
00086   return _father;
00087 }
00088 
00089 hdf_type HDFattribute::GetType()
00090 {
00091  if (_type == HDF_NONE)
00092     if ((_type = HDFattrGetType(_id)) == HDF_NONE)
00093       throw HDFexception("Can't determine the type of data in the attribute");
00094 
00095   return _type;
00096 }
00097 
00098 size_t HDFattribute::GetSize()
00099 {
00100   if(_size == 0) {
00101     if((_size = HDFattrGetSize(_id)) < 0)
00102       throw HDFexception("Can't determine the size of data in the attribute");
00103   }
00104   return _size;
00105 }