@@ -102,20 +102,20 @@ File::File(const char *filename, const NXaccess access) : m_filename(filename),
102
102
}
103
103
104
104
File::File (File const &f)
105
- : m_filename(f.m_filename), m_access(f.m_access), m_file_id (f.m_file_id ), m_close_handle(false ) {}
105
+ : m_filename(f.m_filename), m_access(f.m_access), m_pfile_id (f.m_pfile_id ), m_close_handle(false ) {}
106
106
107
107
File::File (File const *const pf)
108
- : m_filename(pf->m_filename), m_access(pf->m_access), m_file_id (pf->m_file_id ), m_close_handle(false ) {}
108
+ : m_filename(pf->m_filename), m_access(pf->m_access), m_pfile_id (pf->m_pfile_id ), m_close_handle(false ) {}
109
109
110
110
File::File (std::shared_ptr<File> pf)
111
- : m_filename(pf->m_filename), m_access(pf->m_access), m_file_id (pf->m_file_id ), m_close_handle(false ) {}
111
+ : m_filename(pf->m_filename), m_access(pf->m_access), m_pfile_id (pf->m_pfile_id ), m_close_handle(false ) {}
112
112
113
113
File &File::operator =(File const &f) {
114
114
if (this == &f) {
115
115
} else {
116
116
this ->m_filename = f.m_filename ;
117
117
this ->m_access = f.m_access ;
118
- this ->m_file_id = f.m_file_id ;
118
+ this ->m_pfile_id = f.m_pfile_id ;
119
119
this ->m_close_handle = f.m_close_handle ;
120
120
}
121
121
return *this ;
@@ -126,18 +126,21 @@ void File::initOpenFile(const string &filename, const NXaccess access) {
126
126
throw Exception (" Filename specified is empty constructor" );
127
127
}
128
128
129
- NXstatus status = NXopen (filename.c_str (), access, &(this ->m_file_id ));
129
+ NXhandle temp;
130
+ NXstatus status = NXopen (filename.c_str (), access, &(temp));
130
131
if (status != NXstatus::NX_OK) {
131
132
stringstream msg;
132
133
msg << " NXopen(" << filename << " , " << access << " ) failed" ;
133
134
throw Exception (msg.str (), status);
135
+ } else {
136
+ this ->m_pfile_id = std::make_shared<NXhandle>(temp);
134
137
}
135
138
}
136
139
137
140
File::~File () {
138
- if (m_close_handle && m_file_id != NULL ) {
139
- NXstatus status = NXclose (&(this ->m_file_id ));
140
- this ->m_file_id = NULL ;
141
+ if (m_close_handle && m_pfile_id != NULL ) {
142
+ NXstatus status = NXclose (&(* this ->m_pfile_id ));
143
+ this ->m_pfile_id = NULL ;
141
144
if (status != NXstatus::NX_OK) {
142
145
stringstream msg;
143
146
msg << " NXclose failed with status: " << status << " \n " ;
@@ -147,17 +150,17 @@ File::~File() {
147
150
}
148
151
149
152
void File::close () {
150
- if (this ->m_file_id != NULL ) {
151
- NXstatus status = NXclose (&(this ->m_file_id ));
152
- this ->m_file_id = NULL ;
153
+ if (this ->m_pfile_id != NULL ) {
154
+ NXstatus status = NXclose (&(* this ->m_pfile_id ));
155
+ this ->m_pfile_id = NULL ;
153
156
if (status != NXstatus::NX_OK) {
154
157
throw Exception (" NXclose failed" , status);
155
158
}
156
159
}
157
160
}
158
161
159
162
void File::flush () {
160
- NXstatus status = NXflush (&(this ->m_file_id ));
163
+ NXstatus status = NXflush (&(* this ->m_pfile_id ));
161
164
if (status != NXstatus::NX_OK) {
162
165
throw Exception (" NXflush failed" , status);
163
166
}
@@ -170,7 +173,7 @@ void File::makeGroup(const string &name, const string &class_name, bool open_gro
170
173
if (class_name.empty ()) {
171
174
throw Exception (" Supplied empty class name to makeGroup" );
172
175
}
173
- NXstatus status = NXmakegroup (this ->m_file_id , name.c_str (), class_name.c_str ());
176
+ NXstatus status = NXmakegroup (*( this ->m_pfile_id ) , name.c_str (), class_name.c_str ());
174
177
if (status != NXstatus::NX_OK) {
175
178
stringstream msg;
176
179
msg << " NXmakegroup(" << name << " , " << class_name << " ) failed" ;
@@ -188,7 +191,7 @@ void File::openGroup(const string &name, const string &class_name) {
188
191
if (class_name.empty ()) {
189
192
throw Exception (" Supplied empty class name to openGroup" );
190
193
}
191
- NXstatus status = NXopengroup (this ->m_file_id , name.c_str (), class_name.c_str ());
194
+ NXstatus status = NXopengroup (*( this ->m_pfile_id ) , name.c_str (), class_name.c_str ());
192
195
if (status != NXstatus::NX_OK) {
193
196
stringstream msg;
194
197
msg << " NXopengroup(" << name << " , " << class_name << " ) failed" ;
@@ -200,7 +203,7 @@ void File::openPath(const string &path) {
200
203
if (path.empty ()) {
201
204
throw Exception (" Supplied empty path to openPath" );
202
205
}
203
- NXstatus status = NXopenpath (this ->m_file_id , path.c_str ());
206
+ NXstatus status = NXopenpath (*( this ->m_pfile_id ) , path.c_str ());
204
207
if (status != NXstatus::NX_OK) {
205
208
stringstream msg;
206
209
msg << " NXopenpath(" << path << " ) failed" ;
@@ -212,7 +215,7 @@ void File::openGroupPath(const string &path) {
212
215
if (path.empty ()) {
213
216
throw Exception (" Supplied empty path to openGroupPath" );
214
217
}
215
- NXstatus status = NXopengrouppath (this ->m_file_id , path.c_str ());
218
+ NXstatus status = NXopengrouppath (*( this ->m_pfile_id ) , path.c_str ());
216
219
if (status != NXstatus::NX_OK) {
217
220
stringstream msg;
218
221
msg << " NXopengrouppath(" << path << " ) failed" ;
@@ -224,7 +227,7 @@ std::string File::getPath() {
224
227
char cPath[2048 ];
225
228
226
229
memset (cPath, 0 , sizeof (cPath));
227
- NXstatus status = NXgetpath (this ->m_file_id , cPath, sizeof (cPath) - 1 );
230
+ NXstatus status = NXgetpath (*( this ->m_pfile_id ) , cPath, sizeof (cPath) - 1 );
228
231
if (status != NXstatus::NX_OK) {
229
232
stringstream msg;
230
233
msg << " NXgetpath() failed" ;
@@ -234,7 +237,7 @@ std::string File::getPath() {
234
237
}
235
238
236
239
void File::closeGroup () {
237
- NXstatus status = NXclosegroup (this ->m_file_id );
240
+ NXstatus status = NXclosegroup (*( this ->m_pfile_id . get ()) );
238
241
if (status != NXstatus::NX_OK) {
239
242
throw Exception (" NXclosegroup failed" , status);
240
243
}
@@ -244,7 +247,7 @@ void File::makeData(const string &name, NXnumtype type, const vector<int> &dims,
244
247
this ->makeData (name, type, toDimSize (dims), open_data);
245
248
}
246
249
247
- void File::makeData (const string &name, NXnumtype type, const vector< int64_t > &dims, bool open_data) {
250
+ void File::makeData (const string &name, NXnumtype type, const DimVector &dims, bool open_data) {
248
251
// error check the parameters
249
252
if (name.empty ()) {
250
253
throw Exception (" Supplied empty label to makeData" );
@@ -254,7 +257,7 @@ void File::makeData(const string &name, NXnumtype type, const vector<int64_t> &d
254
257
}
255
258
256
259
// do the work
257
- NXstatus status = NXmakedata64 (this ->m_file_id , name.c_str (), type, static_cast <int >(dims.size ()),
260
+ NXstatus status = NXmakedata64 (*( this ->m_pfile_id ) , name.c_str (), type, static_cast <int >(dims.size ()),
258
261
const_cast <int64_t *>(&(dims[0 ])));
259
262
// report errors
260
263
if (status != NXstatus::NX_OK) {
@@ -360,7 +363,7 @@ void File::makeCompData(const string &name, const NXnumtype type, const vector<i
360
363
}
361
364
362
365
void File::makeCompData (const string &name, const NXnumtype type, const DimVector &dims, const NXcompression comp,
363
- const vector< int64_t > &bufsize, bool open_data) {
366
+ const DimSizeVector &bufsize, bool open_data) {
364
367
// error check the parameters
365
368
if (name.empty ()) {
366
369
throw Exception (" Supplied empty name to makeCompData" );
@@ -381,7 +384,7 @@ void File::makeCompData(const string &name, const NXnumtype type, const DimVecto
381
384
// do the work
382
385
int i_type = static_cast <int >(type);
383
386
int i_comp = static_cast <int >(comp);
384
- NXstatus status = NXcompmakedata64 (this ->m_file_id , name.c_str (), type, static_cast <int >(dims.size ()),
387
+ NXstatus status = NXcompmakedata64 (*( this ->m_pfile_id ) , name.c_str (), type, static_cast <int >(dims.size ()),
385
388
const_cast <int64_t *>(&(dims[0 ])), i_comp, const_cast <int64_t *>(&(bufsize[0 ])));
386
389
387
390
// report errors
@@ -414,14 +417,14 @@ void File::openData(const string &name) {
414
417
if (name.empty ()) {
415
418
throw Exception (" Supplied empty name to openData" );
416
419
}
417
- NXstatus status = NXopendata (this ->m_file_id , name.c_str ());
420
+ NXstatus status = NXopendata (*( this ->m_pfile_id ) , name.c_str ());
418
421
if (status != NXstatus::NX_OK) {
419
422
throw Exception (" NXopendata(" + name + " ) failed" , status);
420
423
}
421
424
}
422
425
423
426
void File::closeData () {
424
- NXstatus status = NXclosedata (this ->m_file_id );
427
+ NXstatus status = NXclosedata (*( this ->m_pfile_id ). get () );
425
428
if (status != NXstatus::NX_OK) {
426
429
throw Exception (" NXclosedata() failed" , status);
427
430
}
@@ -431,7 +434,7 @@ void File::putData(const void *data) {
431
434
if (data == NULL ) {
432
435
throw Exception (" Data specified as null in putData" );
433
436
}
434
- NXstatus status = NXputdata (this ->m_file_id , const_cast <void *>(data));
437
+ NXstatus status = NXputdata (*( this ->m_pfile_id ) , const_cast <void *>(data));
435
438
if (status != NXstatus::NX_OK) {
436
439
throw Exception (" NXputdata(void *) failed" , status);
437
440
}
@@ -451,7 +454,7 @@ void File::putAttr(const AttrInfo &info, const void *data) {
451
454
if (info.name .empty ()) {
452
455
throw Exception (" Supplied empty name to putAttr" );
453
456
}
454
- NXstatus status = NXputattr (this ->m_file_id , info.name .c_str (), data, static_cast <int >(info.length ), info.type );
457
+ NXstatus status = NXputattr (*( this ->m_pfile_id ) , info.name .c_str (), data, static_cast <int >(info.length ), info.type );
455
458
if (status != NXstatus::NX_OK) {
456
459
stringstream msg;
457
460
msg << " NXputattr(" << info.name << " , data, " << info.length << " , " << info.type << " ) failed" ;
@@ -509,7 +512,7 @@ void File::putSlab(const void *data, const DimSizeVector &start, const DimSizeVe
509
512
msg << " Supplied start rank=" << start.size () << " must match supplied size rank=" << size.size () << " in putSlab" ;
510
513
throw Exception (msg.str ());
511
514
}
512
- NXstatus status = NXputslab64 (this ->m_file_id , data, &(start[0 ]), &(size[0 ]));
515
+ NXstatus status = NXputslab64 (*( this ->m_pfile_id ) , data, &(start[0 ]), &(size[0 ]));
513
516
if (status != NXstatus::NX_OK) {
514
517
stringstream msg;
515
518
msg << " NXputslab64(data, " << toString (start) << " , " << toString (size) << " ) failed" ;
@@ -542,7 +545,7 @@ template <typename NumT> void File::putSlab(const vector<NumT> &data, dimsize_t
542
545
543
546
NXlink File::getDataID () {
544
547
NXlink link;
545
- NXstatus status = NXgetdataID (this ->m_file_id , &link);
548
+ NXstatus status = NXgetdataID (*( this ->m_pfile_id ) , &link);
546
549
if (status != NXstatus::NX_OK) {
547
550
throw Exception (" NXgetdataID failed" , status);
548
551
}
@@ -551,7 +554,7 @@ NXlink File::getDataID() {
551
554
552
555
bool File::isDataSetOpen () {
553
556
NXlink id;
554
- if (NXgetdataID (this ->m_file_id , &id) == NXstatus::NX_ERROR) {
557
+ if (NXgetdataID (*( this ->m_pfile_id ) , &id) == NXstatus::NX_ERROR) {
555
558
return false ;
556
559
} else {
557
560
return true ;
@@ -560,7 +563,7 @@ bool File::isDataSetOpen() {
560
563
/* ----------------------------------------------------------------------*/
561
564
562
565
void File::makeLink (NXlink &link) {
563
- NXstatus status = NXmakelink (this ->m_file_id , &link);
566
+ NXstatus status = NXmakelink (*( this ->m_pfile_id ) , &link);
564
567
if (status != NXstatus::NX_OK) {
565
568
throw Exception (" NXmakelink failed" , status);
566
569
}
@@ -570,7 +573,7 @@ void File::getData(void *data) {
570
573
if (data == NULL ) {
571
574
throw Exception (" Supplied null pointer to getData" );
572
575
}
573
- NXstatus status = NXgetdata (this ->m_file_id , data);
576
+ NXstatus status = NXgetdata (*( this ->m_pfile_id ) , data);
574
577
if (status != NXstatus::NX_OK) {
575
578
throw Exception (" NXgetdata failed" , status);
576
579
}
@@ -728,7 +731,7 @@ Info File::getInfo() {
728
731
int64_t dims[NX_MAXRANK];
729
732
NXnumtype type;
730
733
int rank;
731
- NXstatus status = NXgetinfo64 (this ->m_file_id , &rank, dims, &type);
734
+ NXstatus status = NXgetinfo64 (*( this ->m_pfile_id ) , &rank, dims, &type);
732
735
if (status != NXstatus::NX_OK) {
733
736
throw Exception (" NXgetinfo failed" , status);
734
737
}
@@ -745,7 +748,7 @@ Entry File::getNextEntry() {
745
748
NXname name, class_name;
746
749
NXnumtype datatype;
747
750
748
- NXstatus status = NXgetnextentry (this ->m_file_id , name, class_name, &datatype);
751
+ NXstatus status = NXgetnextentry (*( this ->m_pfile_id ) , name, class_name, &datatype);
749
752
if (status == NXstatus::NX_OK) {
750
753
string str_name (name);
751
754
string str_class (class_name);
@@ -796,7 +799,7 @@ void File::getSlab(void *data, const DimSizeVector &start, const DimSizeVector &
796
799
throw Exception (msg.str ());
797
800
}
798
801
799
- NXstatus status = NXgetslab64 (this ->m_file_id , data, &(start[0 ]), &(size[0 ]));
802
+ NXstatus status = NXgetslab64 (*( this ->m_pfile_id ) , data, &(start[0 ]), &(size[0 ]));
800
803
if (status != NXstatus::NX_OK) {
801
804
throw Exception (" NXgetslab failed" , status);
802
805
}
@@ -809,7 +812,7 @@ AttrInfo File::getNextAttr() {
809
812
810
813
int rank;
811
814
int dim[NX_MAXRANK];
812
- NXstatus status = NXgetnextattra (this ->m_file_id , name, &rank, dim, &type);
815
+ NXstatus status = NXgetnextattra (*( this ->m_pfile_id ) , name, &rank, dim, &type);
813
816
if (status == NXstatus::NX_OK) {
814
817
AttrInfo info;
815
818
info.type = type;
@@ -859,7 +862,7 @@ void File::getAttr(const AttrInfo &info, void *data, int length) {
859
862
if (length < 0 ) {
860
863
length = static_cast <int >(info.length );
861
864
}
862
- NXstatus status = NXgetattr (this ->m_file_id , name, data, &length, &type);
865
+ NXstatus status = NXgetattr (*( this ->m_pfile_id ) , name, data, &length, &type);
863
866
if (status != NXstatus::NX_OK) {
864
867
throw Exception (" NXgetattr(" + info.name + " ) failed" , status);
865
868
}
@@ -952,22 +955,22 @@ bool File::hasAttr(const std::string &name) {
952
955
953
956
NXlink File::getGroupID () {
954
957
NXlink link;
955
- NXstatus status = NXgetgroupID (this ->m_file_id , &link);
958
+ NXstatus status = NXgetgroupID (*( this ->m_pfile_id ) , &link);
956
959
if (status != NXstatus::NX_OK) {
957
960
throw Exception (" NXgetgroupID failed" , status);
958
961
}
959
962
return link;
960
963
}
961
964
962
965
void File::initGroupDir () {
963
- NXstatus status = NXinitgroupdir (this ->m_file_id );
966
+ NXstatus status = NXinitgroupdir (*( this ->m_pfile_id ) );
964
967
if (status != NXstatus::NX_OK) {
965
968
throw Exception (" NXinitgroupdir failed" , status);
966
969
}
967
970
}
968
971
969
972
void File::initAttrDir () {
970
- NXstatus status = NXinitattrdir (this ->m_file_id );
973
+ NXstatus status = NXinitattrdir (*( this ->m_pfile_id ) );
971
974
if (status != NXstatus::NX_OK) {
972
975
throw Exception (" NXinitattrdir failed" , status);
973
976
}
0 commit comments