Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / HDFPersist / HDFfile.cc
1 using namespace std;
2 extern "C"
3 {
4 #include "hdfi.h"
5 #include <unistd.h>
6 #include <string.h>
7 }
8 #include <iostream.h>
9 #include "HDFfile.hxx"
10 #include "HDFexception.hxx"
11
12 HDFfile::HDFfile(char *name)
13   : HDFcontainerObject(name) 
14 {}
15
16 void HDFfile::CreateOnDisk()
17 {
18   if ((_id = HDFfileCreate(_name)) < 0) 
19     throw HDFexception("Can't create HDF file");
20 }
21
22 void HDFfile::OpenOnDisk(hdf_access_mode access_mode)
23 {
24   _access_mode = access_mode;
25
26   switch (_access_mode)
27     {
28     case HDF_RDWR :
29       if (access(_name,F_OK))
30         {
31           if ((_id = HDFfileCreate(_name)) < 0) 
32             throw HDFexception("Can't open HDF file");
33         }
34       else
35         if ((_id = HDFfileOpen(_name,_access_mode)) < 0)
36           throw HDFexception("Can't open HDF file");
37       break;
38       
39     case HDF_RDONLY :
40       if ((_id = HDFfileOpen(_name,_access_mode)) < 0)
41         throw HDFexception("Can't open HDF file");
42       break;
43       
44     default :
45       throw HDFexception("Can't open HDF file : bad acces option");
46     }
47 }
48
49 void HDFfile::CloseOnDisk()
50 {
51   hdf_err ret;
52
53   if ((ret = HDFfileClose(_id)) < 0) 
54     throw HDFexception("Can't close HDF file");
55   _id = -1;
56 }
57   
58
59 hdf_access_mode HDFfile::GetAccessMode()
60 {
61   return _access_mode;
62 }
63
64 hdf_object_type HDFfile::GetObjectType()
65 {
66   return HDF_FILE;
67 }
68
69 int HDFfile::nInternalObjects()
70 {
71   int n;
72   hdf_err ret;   
73
74   if ((ret = HDFnObjects(_id,"/",&n)) < 0)
75     throw HDFexception("Can't determine the number of internal objects");
76
77   return  n;
78 }
79
80 void HDFfile::InternalObjectIndentify(int rank, char *object_name)
81 {
82   hdf_err ret;
83
84   if ((ret = HDFobjectIdentify(_id,"/",rank,object_name)) < 0)
85     throw HDFexception("Can't identify an internal object");
86 }
87
88 int HDFfile::ExistInternalObject(char *object_name)
89 {
90   int n,i;
91   int ret = 0;
92   char name[HDF_NAME_MAX_LEN+1];
93
94   n = this->nInternalObjects(); 
95   for (i=0;i<n;i++) 
96     {
97       this->InternalObjectIndentify(i,name);
98       if (!strcmp(name,object_name))
99         {
100           ret = 1;
101           break;
102         }
103     }  
104   return ret;
105 }
106
107 hdf_object_type HDFfile::InternalObjectType(char *object_name)
108 {
109   hdf_object_type type;
110   hdf_err ret;
111   
112   if ((ret = HDFobjectType(_id,object_name,&type)) < 0)
113     throw HDFexception("Can't determine internal object type");
114
115   return type;
116 }