casacore
Loading...
Searching...
No Matches
HDF5Object.h
Go to the documentation of this file.
1//# HDF5Object.h: An abstract base class representing an HDF5 object
2//# Copyright (C) 2008
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_HDF5OBJECT_H
27#define CASA_HDF5OBJECT_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/BasicSL/String.h>
32
33//# Define hid_t and hsize_t if not defined (thus if HDF5 disabled).
34//# They should be the same as used by HDF5.
35//# This is checked by functions check_hid_t and check_hsize_t.
36#ifdef HAVE_HDF5
37# include <hdf5.h>
38#else
39 typedef int64_t hid_t;
40 typedef casacore::uInt64 hsize_t;
41#endif
42
43
44namespace casacore { //# NAMESPACE CASACORE - BEGIN
45
46 // <summary>
47 // An abstract base class representing an HDF5 object
48 // </summary>
49
50 // <use visibility=export>
51
52 // <reviewed reviewer="" date="" tests="tHDF5Dataset.cc">
53 // </reviewed>
54
55 // <synopsis>
56 // This class wraps a basic HDF5 object. It offers several benefits:
57 // <ul>
58 // <li> The most important is resource management. In case of an exception,
59 // the object's hid will automatically be closed by the destructor.
60 // <li> It acts as the base class for the basic objects file, group,
61 // and dataset.
62 // <li> An HDF5 hid is a kind of pointer and should not be copied.
63 // These classes forbid making a copy, but make it possible to use
64 // them in a shared pointer context.
65 // </ul>
66 // </synopsis>
67
69 {
70 public:
71 // Default constructor sets to invalid hid.
73 : itsHid(-1)
74 {}
75
76 // The destructor in a derived class should close the hid appropriately.
77 virtual ~HDF5Object();
78
79 // Copy constructor cannot be used because a HID cannot be copied.
80 HDF5Object (const HDF5Object&) = delete;
81
82 // Assignment cannot be used because a HID cannot be copied .
83 HDF5Object& operator= (const HDF5Object&) = delete;
84
85 // Check if there is HDF5 support compiled in.
87
88 // Close the hid if valid.
89 virtual void close() = 0;
90
91 // Is it a valid hid?
92 bool isValid() const
93 { return itsHid >= 0; }
94
95 // Get the hid.
96 hid_t getHid() const
97 { return itsHid; }
98
99 // Convert automatically to hid_t.
100 operator hid_t() const
101 { return itsHid; }
102
103 // Get or set the name.
104 // <group>
105 void setName (const String& name)
106 { itsName = name; }
107 const String& getName() const
108 { return itsName; }
109 // </group>
110
111 // If no HDF5, throw an exception that HDF5 is not supported.
112 static void throwNoHDF5();
113
114 protected:
115 // Set the hid.
116 void setHid (hid_t hid)
117 { itsHid = hid; }
118
119 // Clear the hid (set to invalid).
120 void clearHid()
121 { itsHid = -1; }
122
123 private:
124 //# Data members
125 //# Define a union to ensure that the object always uses 64 bits, even
126 //# for older HDF5 versions where hid_t is a 32 bit integer.
127 union {
128 hid_t itsHid;
129 int64_t itsDummyHid;
130 };
132 };
133
134
135}
136
137#endif
HDF5Object & operator=(const HDF5Object &)=delete
Assignment cannot be used because a HID cannot be copied.
HDF5Object()
Default constructor sets to invalid hid.
Definition HDF5Object.h:72
virtual ~HDF5Object()
The destructor in a derived class should close the hid appropriately.
virtual void close()=0
Close the hid if valid.
void clearHid()
Clear the hid (set to invalid).
Definition HDF5Object.h:120
static Bool hasHDF5Support()
Check if there is HDF5 support compiled in.
hid_t getHid() const
Get the hid.
Definition HDF5Object.h:96
const String & getName() const
Definition HDF5Object.h:107
static void throwNoHDF5()
If no HDF5, throw an exception that HDF5 is not supported.
void setName(const String &name)
Get or set the name.
Definition HDF5Object.h:105
void setHid(hid_t hid)
Set the hid.
Definition HDF5Object.h:116
bool isValid() const
Is it a valid hid?
Definition HDF5Object.h:92
HDF5Object(const HDF5Object &)=delete
Copy constructor cannot be used because a HID cannot be copied.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
unsigned long long uInt64
Definition aipsxtype.h:37