1 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
32 #include "HDFgroup.hxx"
33 #include "HDFexception.hxx"
36 herr_t group_attr(hid_t loc_id, const char *attr_name, void *operator_data)
38 *(char**)operator_data = new char[strlen(attr_name)+1];
39 strcpy(*(char**)operator_data, attr_name);
43 HDFgroup::HDFgroup(char *name, HDFcontainerObject *father)
44 : HDFcontainerObject(name)
47 _fid = _father->GetId();
48 _father->AddSon(this);
53 void HDFgroup::CreateOnDisk()
55 if ((_id = HDFgroupCreate(_fid,_name)) < 0)
56 throw HDFexception("Can't create group");
59 void HDFgroup::OpenOnDisk()
61 if ((_id = HDFgroupOpen(_fid,_name)) < 0)
62 throw HDFexception("Can't open group");
65 void HDFgroup::CloseOnDisk()
69 if ((ret = HDFgroupClose(_id)) < 0)
70 throw HDFexception("Can't close group");
74 HDFcontainerObject *HDFgroup::GetFather()
79 hdf_object_type HDFgroup::GetObjectType()
84 int HDFgroup::nInternalObjects()
89 if ((ret = HDFnObjects(_fid,_name,&n)) < 0)
90 throw HDFexception("Can't determine the number of internal objects");
95 void HDFgroup::InternalObjectIndentify(int rank, char *object_name)
99 if ((ret = HDFobjectIdentify(_fid,_name,rank,object_name)) < 0)
100 throw HDFexception("Can't identify an internal object");
103 int HDFgroup::ExistInternalObject(char *object_name)
107 char name[HDF_NAME_MAX_LEN+1];
109 n = this->nInternalObjects();
112 this->InternalObjectIndentify(i,name);
113 if (!strcmp(name,object_name))
122 hdf_object_type HDFgroup::InternalObjectType(char *object_name)
124 hdf_object_type type;
127 if ((ret = HDFobjectType(_id,object_name,&type)) < 0)
128 throw HDFexception("Can't determine internal object type");
133 void HDFgroup::FileMount(char *file,hdf_access_mode mode)
138 throw HDFexception("Can't mount the file");
140 if ((_mid = HDFfileOpen(file,mode)) < 0)
141 throw HDFexception("Can't mount the file");
143 if ((ret = HDFfileMount(_fid,_name,_mid)) < 0)
144 throw HDFexception("Can't mount the file");
147 void HDFgroup::FileUnMount()
151 if ((ret = HDFfileUmount(_fid,_name)) < 0)
152 throw HDFexception("Can't unmount the file");
154 if ((ret = HDFfileClose(_mid)) < 0)
155 throw HDFexception("Can't unmount the file");
160 int HDFgroup::nAttributes()
162 int nbAttrs = H5Aget_num_attrs(_id);
163 if(nbAttrs <= 0) nbAttrs = 0;
167 char* HDFgroup::GetAttributeName(unsigned idx)
169 int nbAttrs = nAttributes();
170 if(nbAttrs == 0) return NULL;
171 H5Aiterate(_id, &idx, group_attr, &_attribute);