1 // Copyright (C) 2007-2008 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.
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
22 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
31 #include "HDFgroup.hxx"
32 #include "HDFexception.hxx"
35 herr_t group_attr(hid_t loc_id, const char *attr_name, void *operator_data)
37 *(char**)operator_data = new char[strlen(attr_name)+1];
38 strcpy(*(char**)operator_data, attr_name);
42 HDFgroup::HDFgroup(const char *name, HDFcontainerObject *father)
43 : HDFcontainerObject(name)
46 _fid = _father->GetId();
47 _father->AddSon(this);
52 void HDFgroup::CreateOnDisk()
54 if ((_id = HDFgroupCreate(_fid,_name)) < 0)
55 throw HDFexception("Can't create group");
58 void HDFgroup::OpenOnDisk()
60 if ((_id = HDFgroupOpen(_fid,_name)) < 0)
61 throw HDFexception("Can't open group");
64 void HDFgroup::CloseOnDisk()
68 if ((ret = HDFgroupClose(_id)) < 0)
69 throw HDFexception("Can't close group");
73 HDFcontainerObject *HDFgroup::GetFather()
78 hdf_object_type HDFgroup::GetObjectType()
83 int HDFgroup::nInternalObjects()
88 if ((ret = HDFnObjects(_fid,_name,&n)) < 0)
89 throw HDFexception("Can't determine the number of internal objects");
94 void HDFgroup::InternalObjectIndentify(int rank, char *object_name)
98 if ((ret = HDFobjectIdentify(_fid,_name,rank,object_name)) < 0)
99 throw HDFexception("Can't identify an internal object");
102 int HDFgroup::ExistInternalObject(const char *object_name)
106 char name[HDF_NAME_MAX_LEN+1];
108 n = this->nInternalObjects();
111 this->InternalObjectIndentify(i,name);
112 if (!strcmp(name,object_name))
121 hdf_object_type HDFgroup::InternalObjectType(char *object_name)
123 hdf_object_type type;
126 if ((ret = HDFobjectType(_id,object_name,&type)) < 0)
127 throw HDFexception("Can't determine internal object type");
132 void HDFgroup::FileMount(char *file,hdf_access_mode mode)
137 throw HDFexception("Can't mount the file");
139 if ((_mid = HDFfileOpen(file,mode)) < 0)
140 throw HDFexception("Can't mount the file");
142 if ((ret = HDFfileMount(_fid,_name,_mid)) < 0)
143 throw HDFexception("Can't mount the file");
146 void HDFgroup::FileUnMount()
150 if ((ret = HDFfileUmount(_fid,_name)) < 0)
151 throw HDFexception("Can't unmount the file");
153 if ((ret = HDFfileClose(_mid)) < 0)
154 throw HDFexception("Can't unmount the file");
159 int HDFgroup::nAttributes()
161 int nbAttrs = H5Aget_num_attrs(_id);
162 if(nbAttrs <= 0) nbAttrs = 0;
166 char* HDFgroup::GetAttributeName(unsigned idx)
168 int nbAttrs = nAttributes();
169 if(nbAttrs == 0) return NULL;
170 H5Aiterate(_id, &idx, group_attr, &_attribute);