Back to index

salome-kernel  6.5.0
HDFgroup.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   : HDFgroup.cc
00025 //  Module : SALOME
00026 //
00027 #include "hdfi.h"
00028 #include <string.h>
00029 #include "HDFgroup.hxx"
00030 #include "HDFexception.hxx"
00031 
00032 herr_t group_attr(hid_t loc_id, const char *attr_name, void *operator_data)
00033 {
00034    *(char**)operator_data = new char[strlen(attr_name)+1];
00035    strcpy(*(char**)operator_data, attr_name);
00036    return 1;
00037 }
00038 
00039 HDFgroup::HDFgroup(const char *name, HDFcontainerObject *father)
00040   : HDFcontainerObject(name)
00041 {
00042   _father = father;
00043   _fid = _father->GetId();
00044   _father->AddSon(this);
00045   _mid = -1;
00046   _attribute = NULL;
00047 };
00048 
00049 void HDFgroup::CreateOnDisk()
00050 {
00051   if ((_id = HDFgroupCreate(_fid,_name)) < 0) 
00052     throw HDFexception("Can't create group");
00053 }
00054   
00055 void HDFgroup::OpenOnDisk()
00056 {
00057   if ((_id = HDFgroupOpen(_fid,_name)) < 0)
00058     throw HDFexception("Can't open group");
00059 }
00060   
00061 void HDFgroup::CloseOnDisk()
00062 {
00063   hdf_err ret;
00064 
00065   if ((ret = HDFgroupClose(_id)) < 0)
00066     throw HDFexception("Can't close group");
00067   _id = -1;
00068 }
00069 
00070 HDFcontainerObject *HDFgroup::GetFather()
00071 {
00072   return _father;
00073 }
00074 
00075 hdf_object_type HDFgroup::GetObjectType()
00076 {
00077   return HDF_GROUP;
00078 }
00079 
00080 int HDFgroup::nInternalObjects()
00081 {
00082   int n = 0;
00083   hdf_err ret;   
00084   
00085   if ((ret = HDFnObjects(_fid,_name,&n)) < 0)
00086     throw HDFexception("Can't determine the number of internal objects");
00087 
00088   return  n;  
00089 }
00090 
00091 void HDFgroup::InternalObjectIndentify(int rank, char *object_name)
00092 {
00093   hdf_err ret;
00094 
00095   if ((ret = HDFobjectIdentify(_fid,_name,rank,object_name)) < 0)
00096     throw HDFexception("Can't identify an internal object");
00097 }
00098 
00099 int HDFgroup::ExistInternalObject(const char *object_name)
00100 {
00101   int n,i;
00102   int ret = 0;
00103   char name[HDF_NAME_MAX_LEN+1];
00104 
00105   n = this->nInternalObjects(); 
00106   for (i=0;i<n;i++) 
00107     {
00108       this->InternalObjectIndentify(i,name);
00109       if (!strcmp(name,object_name))
00110        {
00111          ret = 1;
00112          break;
00113        }
00114     }  
00115   return ret;
00116 }
00117 
00118 hdf_object_type HDFgroup::InternalObjectType(char *object_name)
00119 {
00120   hdf_object_type type;
00121   hdf_err ret;
00122   
00123   if ((ret = HDFobjectType(_id,object_name,&type)) < 0)
00124     throw HDFexception("Can't determine internal object type");
00125 
00126   return type;
00127 }
00128 
00129 void HDFgroup::FileMount(char *file,hdf_access_mode mode)
00130 {
00131   hdf_err ret;
00132 
00133   if (_mid != -1)
00134     throw HDFexception("Can't mount the file");    
00135 
00136   if ((_mid = HDFfileOpen(file,mode)) < 0)
00137     throw HDFexception("Can't mount the file");
00138 
00139   if ((ret = HDFfileMount(_fid,_name,_mid)) < 0)
00140     throw HDFexception("Can't mount the file");
00141 }
00142 
00143 void HDFgroup::FileUnMount()
00144 {
00145   hdf_err ret;
00146 
00147   if ((ret = HDFfileUmount(_fid,_name)) < 0)
00148         throw HDFexception("Can't unmount the file");
00149 
00150   if ((ret = HDFfileClose(_mid)) < 0)
00151         throw HDFexception("Can't unmount the file");
00152 
00153   _mid = -1;
00154 }
00155 
00156 int HDFgroup::nAttributes()
00157 {
00158   int nbAttrs = H5Aget_num_attrs(_id);
00159   if(nbAttrs <= 0) nbAttrs = 0;
00160   return nbAttrs; 
00161 }
00162 
00163 char* HDFgroup::GetAttributeName(unsigned idx)
00164 {
00165   int nbAttrs = nAttributes();
00166   if(nbAttrs == 0) return NULL;
00167   H5Aiterate(_id, &idx, group_attr, &_attribute);
00168   return _attribute;
00169 }
00170 
00171 
00172