casacore
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: aips2-request@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//# $Id$
27
28#ifndef CASA_HDF5OBJECT_H
29#define CASA_HDF5OBJECT_H
30
31//# Includes
32#include <casacore/casa/aips.h>
33#include <casacore/casa/BasicSL/String.h>
34
35//# Define hid_t and hsize_t if not defined (thus if HDF5 disabled).
36//# They should be the same as used by HDF5.
37//# This is checked by functions check_hid_t and check_hsize_t.
38#ifdef HAVE_HDF5
39# include <hdf5.h>
40#else
41 typedef int64_t hid_t;
42 typedef casacore::uInt64 hsize_t;
43#endif
44
45
46namespace casacore { //# NAMESPACE CASACORE - BEGIN
47
48 // <summary>
49 // An abstract base class representing an HDF5 object
50 // </summary>
51
52 // <use visibility=export>
53
54 // <reviewed reviewer="" date="" tests="tHDF5Dataset.cc">
55 // </reviewed>
56
57 // <synopsis>
58 // This class wraps a basic HDF5 object. It offers several benefits:
59 // <ul>
60 // <li> The most important is resource management. In case of an exception,
61 // the object's hid will automatically be closed by the destructor.
62 // <li> It acts as the base class for the basic objects file, group,
63 // and dataset.
64 // <li> An HDF5 hid is a kind of pointer and should not be copied.
65 // These classes forbid making a copy, but make it possible to use
66 // them in a shared pointer context.
67 // </ul>
68 // </synopsis>
69
71 {
72 public:
73 // Default constructor sets to invalid hid.
75 : itsHid(-1)
76 {}
77
78 // The destructor in a derived class should close the hid appropriately.
79 virtual ~HDF5Object();
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
89 { return itsHid >= 0; }
90
91 // Get the hid.
92 hid_t getHid() const
93 { return itsHid; }
94
95 // Convert automatically to hid_t.
96 operator hid_t() const
97 { return itsHid; }
98
99 // Get or set the name.
100 // <group>
101 void setName (const String& name)
102 { itsName = name; }
103 const String& getName() const
104 { return itsName; }
105 // </group>
106
107 // If no HDF5, throw an exception that HDF5 is not supported.
108 static void throwNoHDF5();
109
110 protected:
111 // Set the hid.
112 void setHid (hid_t hid)
113 { itsHid = hid; }
114
115 // Clear the hid (set to invalid).
116 void clearHid()
117 { itsHid = -1; }
118
119 private:
120 //# Data members
121 //# Define a union to ensure that the object always uses 64 bits, even
122 //# for older HDF5 versions where hid_t is a 32 bit integer.
123 union {
124 hid_t itsHid;
125 int64_t itsDummyHid;
126 };
128
129 private:
130 // Copy constructor cannot be used.
131 HDF5Object (const HDF5Object& that);
132 // Assignment cannot be used.
134 };
135
136
137}
138
139#endif
HDF5Object(const HDF5Object &that)
Copy constructor cannot be used.
HDF5Object()
Default constructor sets to invalid hid.
Definition: HDF5Object.h:74
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:116
static Bool hasHDF5Support()
Check if there is HDF5 support compiled in.
hid_t getHid() const
Get the hid.
Definition: HDF5Object.h:92
const String & getName() const
Definition: HDF5Object.h:103
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:101
void setHid(hid_t hid)
Set the hid.
Definition: HDF5Object.h:112
HDF5Object & operator=(const HDF5Object &that)
Assignment cannot be used.
bool isValid() const
Is it a valid hid?
Definition: HDF5Object.h:88
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
unsigned long long uInt64
Definition: aipsxtype.h:39