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
39typedef int64_t hid_t;
40typedef casacore::uInt64 hsize_t;
41#endif
42
43namespace casacore { // # NAMESPACE CASACORE - BEGIN
44
45// <summary>
46// An abstract base class representing an HDF5 object
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="" date="" tests="tHDF5Dataset.cc">
52// </reviewed>
53
54// <synopsis>
55// This class wraps a basic HDF5 object. It offers several benefits:
56// <ul>
57// <li> The most important is resource management. In case of an exception,
58// the object's hid will automatically be closed by the destructor.
59// <li> It acts as the base class for the basic objects file, group,
60// and dataset.
61// <li> An HDF5 hid is a kind of pointer and should not be copied.
62// These classes forbid making a copy, but make it possible to use
63// them in a shared pointer context.
64// </ul>
65// </synopsis>
66
68 public:
69 // Default constructor sets to invalid hid.
70 HDF5Object() : itsHid(-1) {}
71
72 // The destructor in a derived class should close the hid appropriately.
73 virtual ~HDF5Object();
74
75 // Copy constructor cannot be used because a HID cannot be copied.
76 HDF5Object(const HDF5Object&) = delete;
77
78 // Assignment cannot be used because a HID cannot be copied .
79 HDF5Object& operator=(const HDF5Object&) = delete;
80
81 // Check if there is HDF5 support compiled in.
83
84 // Close the hid if valid.
85 virtual void close() = 0;
86
87 // Is it a valid hid?
88 bool isValid() const { return itsHid >= 0; }
89
90 // Get the hid.
91 hid_t getHid() const { return itsHid; }
92
93 // Convert automatically to hid_t.
94 operator hid_t() const { return itsHid; }
95
96 // Get or set the name.
97 // <group>
98 void setName(const String& name) { itsName = name; }
99 const String& getName() const { return itsName; }
100 // </group>
101
102 // If no HDF5, throw an exception that HDF5 is not supported.
103 static void throwNoHDF5();
104
105 protected:
106 // Set the hid.
107 void setHid(hid_t hid) { itsHid = hid; }
108
109 // Clear the hid (set to invalid).
110 void clearHid() { itsHid = -1; }
111
112 private:
113 // # Data members
114 // # Define a union to ensure that the object always uses 64 bits, even
115 // # for older HDF5 versions where hid_t is a 32 bit integer.
116 union {
117 hid_t itsHid;
118 int64_t itsDummyHid;
119 };
121};
122
123} // namespace casacore
124
125#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:70
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:110
static Bool hasHDF5Support()
Check if there is HDF5 support compiled in.
hid_t getHid() const
Get the hid.
Definition HDF5Object.h:91
const String & getName() const
Definition HDF5Object.h:99
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:98
void setHid(hid_t hid)
Set the hid.
Definition HDF5Object.h:107
bool isValid() const
Is it a valid hid?
Definition HDF5Object.h:88
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
String name() const
Return the name of the field.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
unsigned long long uInt64
Definition aipsxtype.h:37