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 )
29 #include "HDFgroup.hxx"
30 #include "HDFexception.hxx"
32 herr_t group_attr(hid_t loc_id, const char *attr_name, void *operator_data)
34 *(char**)operator_data = new char[strlen(attr_name)+1];
35 strcpy(*(char**)operator_data, attr_name);
39 HDFgroup::HDFgroup(const char *name, HDFcontainerObject *father)
40 : HDFcontainerObject(name)
43 _fid = _father->GetId();
44 _father->AddSon(this);
49 void HDFgroup::CreateOnDisk()
51 if ((_id = HDFgroupCreate(_fid,_name)) < 0)
52 throw HDFexception("Can't create group");
55 void HDFgroup::OpenOnDisk()
57 if ((_id = HDFgroupOpen(_fid,_name)) < 0)
58 throw HDFexception("Can't open group");
61 void HDFgroup::CloseOnDisk()
65 if ((ret = HDFgroupClose(_id)) < 0)
66 throw HDFexception("Can't close group");
70 HDFcontainerObject *HDFgroup::GetFather()
75 hdf_object_type HDFgroup::GetObjectType()
80 int HDFgroup::nInternalObjects()
85 if ((ret = HDFnObjects(_fid,_name,&n)) < 0)
86 throw HDFexception("Can't determine the number of internal objects");
91 void HDFgroup::InternalObjectIndentify(int rank, char *object_name)
95 if ((ret = HDFobjectIdentify(_fid,_name,rank,object_name)) < 0)
96 throw HDFexception("Can't identify an internal object");
99 int HDFgroup::ExistInternalObject(const char *object_name)
103 char name[HDF_NAME_MAX_LEN+1];
105 n = this->nInternalObjects();
108 this->InternalObjectIndentify(i,name);
109 if (!strcmp(name,object_name))
118 hdf_object_type HDFgroup::InternalObjectType(char *object_name)
120 hdf_object_type type;
123 if ((ret = HDFobjectType(_id,object_name,&type)) < 0)
124 throw HDFexception("Can't determine internal object type");
129 void HDFgroup::FileMount(char *file,hdf_access_mode mode)
134 throw HDFexception("Can't mount the file");
136 if ((_mid = HDFfileOpen(file,mode)) < 0)
137 throw HDFexception("Can't mount the file");
139 if ((ret = HDFfileMount(_fid,_name,_mid)) < 0)
140 throw HDFexception("Can't mount the file");
143 void HDFgroup::FileUnMount()
147 if ((ret = HDFfileUmount(_fid,_name)) < 0)
148 throw HDFexception("Can't unmount the file");
150 if ((ret = HDFfileClose(_mid)) < 0)
151 throw HDFexception("Can't unmount the file");
156 int HDFgroup::nAttributes()
158 int nbAttrs = H5Aget_num_attrs(_id);
159 if(nbAttrs <= 0) nbAttrs = 0;
163 char* HDFgroup::GetAttributeName(unsigned idx)
165 int nbAttrs = nAttributes();
166 if(nbAttrs == 0) return NULL;
167 H5Aiterate(_id, &idx, group_attr, &_attribute);