1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
33 #define access _access
37 #include "HDFfile.hxx"
38 #include "HDFexception.hxx"
40 herr_t file_attr(hid_t loc_id, const char *attr_name, void *operator_data)
42 *(char**)operator_data = new char[strlen(attr_name)+1];
43 strcpy(*(char**)operator_data, attr_name);
47 HDFfile::HDFfile(char *name)
48 : HDFcontainerObject(name)
53 void HDFfile::CreateOnDisk()
55 if ((_id = HDFfileCreate(_name)) < 0)
56 throw HDFexception("Can't create HDF file");
59 void HDFfile::OpenOnDisk(hdf_access_mode access_mode)
61 _access_mode = access_mode;
66 if (access(_name,F_OK))
68 if ((_id = HDFfileCreate(_name)) < 0)
69 throw HDFexception("Can't open HDF file");
72 if ((_id = HDFfileOpen(_name,_access_mode)) < 0)
73 throw HDFexception("Can't open HDF file");
77 if ((_id = HDFfileOpen(_name,_access_mode)) < 0)
78 throw HDFexception("Can't open HDF file");
82 throw HDFexception("Can't open HDF file : bad acces option");
86 void HDFfile::CloseOnDisk()
90 if ((ret = HDFfileClose(_id)) < 0)
91 throw HDFexception("Can't close HDF file");
96 hdf_access_mode HDFfile::GetAccessMode()
101 hdf_object_type HDFfile::GetObjectType()
106 int HDFfile::nInternalObjects()
111 if ((ret = HDFnObjects(_id,"/",&n)) < 0)
112 throw HDFexception("Can't determine the number of internal objects");
117 void HDFfile::InternalObjectIndentify(int rank, char *object_name)
121 if ((ret = HDFobjectIdentify(_id,"/",rank,object_name)) < 0)
122 throw HDFexception("Can't identify an internal object");
125 int HDFfile::ExistInternalObject(const char *object_name)
129 char name[HDF_NAME_MAX_LEN+1];
131 n = this->nInternalObjects();
134 this->InternalObjectIndentify(i,name);
135 if (!strcmp(name,object_name))
144 hdf_object_type HDFfile::InternalObjectType(char *object_name)
146 hdf_object_type type;
149 if ((ret = HDFobjectType(_id,object_name,&type)) < 0)
150 throw HDFexception("Can't determine internal object type");
155 int HDFfile::nAttributes()
157 int nbAttrs = H5Aget_num_attrs(_id);
158 if(nbAttrs <= 0) nbAttrs = 0;
162 char* HDFfile::GetAttributeName(unsigned idx)
164 int nbAttrs = nAttributes();
165 if(nbAttrs == 0) return NULL;
166 H5Aiterate(_id, &idx, file_attr, &_attribute);