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