CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
src
opt
hdf5
lib
h5_file.cc
Go to the documentation of this file.
1
// -*- C++ -*-
12
#include "
h5_file.h
"
13
#include <fstream>
14
15
namespace
CNORXZ
16
{
17
namespace
hdf5
18
{
19
File::File
(
const
String
&
fname
,
bool
_ro
) :
20
Group
(
fname
,
nullptr
),
21
mRo(
_ro
)
22
{}
23
24
File::~File
()
25
{
26
this->
close
();
27
}
28
29
ContentType
File::type
()
const
30
{
31
return
ContentType::FILE
;
32
}
33
34
bool
File::ro
()
const
35
{
36
return
mRo;
37
}
38
39
File
&
File::open
()
40
{
41
if
(
isOpen
()){
42
return
*
this
;
43
}
44
Int
ex
= this->
exists
();
45
const
String
fn
= this->
filename
();
46
CXZ_ASSERT
(
ishdf5
(),
"tried to open non-h5 file '"
<< fn <<
"'"
);
47
if
(mRo){
48
CXZ_ASSERT
(
ex
== 1,
"could not open file as read-only: '"
49
<<
fn
<<
"' does not exist'"
);
50
mId
=
H5Fopen
(
fn
.c_str(),
H5F_ACC_RDONLY
,
H5P_DEFAULT
);
51
}
52
else
{
53
if
(
ex
== 1){
54
mId
=
H5Fopen
(
fn
.c_str(),
H5F_ACC_RDWR
,
H5P_DEFAULT
);
55
}
56
else
{
57
mId
=
H5Fcreate
(
fn
.c_str(),
H5F_ACC_TRUNC
,
H5P_DEFAULT
,
H5P_DEFAULT
);
58
}
59
}
60
CXZ_ASSERT
(
mId
> 0,
"error while opening file '"
<<
fn
<<
"'"
);
61
this->
mkCont
();
62
return
*
this
;
63
}
64
65
File
&
File::close
()
66
{
67
if
(
mCont
.
range
() !=
nullptr
){
68
for
(
auto
& x:
mCont
){
69
if
(x !=
nullptr
){
70
x->
close
();
71
}
72
}
73
}
74
if
(
mId
!= 0){
75
H5Fclose
(
mId
);
76
}
77
mId
= 0;
78
return
*
this
;
79
}
80
81
String
File::path
()
const
82
{
83
return
""
;
84
}
85
86
String
File::filename
()
const
87
{
88
return
name
();
89
}
90
91
bool
File::exists
()
const
92
{
93
bool
ex
=
false
;
94
std::ifstream
fs
(this->
filename
().
c_str
(), std::ios_base::binary);
95
if
(
fs
.good()){
96
ex
=
true
;
// file exists
97
}
98
fs
.close();
99
return
ex
;
100
}
101
102
bool
File::ishdf5
()
const
103
{
104
if
(
exists
()){
105
if
(
H5Fis_hdf5
(this->
filename
().
c_str
()) <= 0){
106
return
false
;
107
}
108
}
109
return
true
;
// a non-existing file can be created in hdf5 format
110
}
111
}
112
}
CXZ_ASSERT
#define CXZ_ASSERT(statement, errmsg)
Definition
assert.h:40
CNORXZ::CArrayBase::range
virtual RangePtr range() const
Definition
array_base.cc.h:102
CNORXZ::hdf5::ContentBase::name
const String & name() const
Definition
h5_content_base.cc:24
CNORXZ::hdf5::ContentBase::mId
hid_t mId
Definition
h5_content_base.h:142
CNORXZ::hdf5::ContentBase::isOpen
bool isOpen() const
Definition
h5_content_base.cc:39
CNORXZ::hdf5::File
Definition
h5_file.h:29
CNORXZ::hdf5::File::close
virtual File & close() override final
Definition
h5_file.cc:65
CNORXZ::hdf5::File::type
virtual ContentType type() const override final
Definition
h5_file.cc:29
CNORXZ::hdf5::File::ishdf5
bool ishdf5() const
Definition
h5_file.cc:102
CNORXZ::hdf5::File::open
virtual File & open() override final
Definition
h5_file.cc:39
CNORXZ::hdf5::File::exists
virtual bool exists() const override final
Definition
h5_file.cc:91
CNORXZ::hdf5::File::filename
virtual String filename() const override final
Definition
h5_file.cc:86
CNORXZ::hdf5::File::ro
virtual bool ro() const override final
Definition
h5_file.cc:34
CNORXZ::hdf5::File::~File
~File()
Definition
h5_file.cc:24
CNORXZ::hdf5::File::File
File(const String &fname, bool _ro=true)
Definition
h5_file.cc:19
CNORXZ::hdf5::File::path
virtual String path() const override final
Definition
h5_file.cc:81
CNORXZ::hdf5::Group
Definition
h5_group.h:26
CNORXZ::hdf5::Group::mCont
MArray< ContentPtr > mCont
Definition
h5_group.h:148
CNORXZ::hdf5::Group::mkCont
void mkCont()
Definition
h5_group.cc:219
h5_file.h
Group declaration.
CNORXZ::hdf5::ContentType
ContentType
Definition
h5_content_base.h:29
CNORXZ::hdf5::ContentType::FILE
@ FILE
CNORXZ
Definition
aindex.cc.h:18
CNORXZ::String
std::string String
Definition
types.h:42
CNORXZ::Int
int32_t Int
Definition
types.h:36
CNORXZ::rangeCast
Sptr< Range > rangeCast(const RangePtr r)
Definition
range_base.cc.h:53
Generated by
1.10.0