diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2000-11-14 21:30:12 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2000-11-14 21:30:12 (GMT) |
commit | 92041a68656c59813619ae1f26ed211b7f028e86 (patch) | |
tree | aaa3256c9a9f0adde21570eac9254f7ce00450b1 /c++/src/H5DataSet.C | |
parent | 36acd5381e3977164e0d6d666f8ce97cc53f9387 (diff) | |
download | hdf5-92041a68656c59813619ae1f26ed211b7f028e86.zip hdf5-92041a68656c59813619ae1f26ed211b7f028e86.tar.gz hdf5-92041a68656c59813619ae1f26ed211b7f028e86.tar.bz2 |
[svn-r2897] Purpose:
C++ API for 1.3.x branch
Description:
The *.C and *.h files named different than those in 1.2.x.
They are in the form: 'H5' + classname, or just classname if
the classname is already prefixed with 'H5' to avoid ambiguity
in documentation context. This version has several hidden bugs
fixed and an improvement on the reference counting approach.
The classes and their inheritance structure are listed below:
---------------------------------------
H5Library
Exception
RefCounter
IdComponent
H5File
DataSpace
H5Object
Group
AbstractDs
DataSet
Attribute
DataType
PredType
EnumType
CompType
AtomType
StrType
IntType
FloatType
PropList
FileCreatPropList
FileAccPropList
DSetCreatPropList
DSetMemXferPropList
---------------------------------------
IdComponent uses RefCounter to keep track of opened objects
so proper termination of HDF5 objects can be maintained.
Each class has a .h file containing the class declaration and
a .C file containing its definition. In addition to the classes
files, the following files do not have class information:
- H5Cpp.h: header file to be included in user's application
- H5Idtemplates.h: contains a template function used by several classes
- H5Classes.h: contains forward class declarations
- H5CommonFG.*: contains common code used by classes H5File and Group
- H5Include.h: contains the hdf5.h header file and the #undef RCSID
to work around the problem: multiple defined RcsId
- H5Alltypes.h: simply serves as a container to hold the header
files of all datatypes to simplify the header file inclusion
Platforms:
Solaris (arabica) and Linux
Diffstat (limited to 'c++/src/H5DataSet.C')
-rw-r--r-- | c++/src/H5DataSet.C | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/c++/src/H5DataSet.C b/c++/src/H5DataSet.C new file mode 100644 index 0000000..1cc66a2 --- /dev/null +++ b/c++/src/H5DataSet.C @@ -0,0 +1,207 @@ +#include <string> + +#include "H5Include.h" +#include "H5RefCounter.h" +#include "H5Exception.h" +#include "H5IdComponent.h" +#include "H5Idtemplates.h" +#include "H5PropList.h" +#include "H5Object.h" +#include "H5PropList.h" +#include "H5DxferProp.h" +#include "H5DataType.h" +#include "H5DcreatProp.h" +#include "H5DataSpace.h" +#include "H5AbstractDs.h" +#include "H5DataSet.h" + +#ifndef H5_NO_NAMESPACE +namespace H5 { +#endif + +// Default constructor +DataSet::DataSet() : AbstractDs() {} + +// Creates a copy of DataSet using an existing id +DataSet::DataSet( const hid_t dataset_id ) : AbstractDs( dataset_id ) {} + +// Copy constructor makes a copy of the original object by using base +// class' copy constructors +DataSet::DataSet( const DataSet& original ) : AbstractDs( original ) {} + +// Gets a copy of the dataspace of this dataset +DataSpace DataSet::getSpace() const +{ + // Calls C function H5Dget_space to get the id of the dataspace + hid_t dataspace_id = H5Dget_space( id ); + + // If the dataspace id is invalid, throw an exception + if( dataspace_id <= 0 ) + { + throw DataSetIException(); + } + //create dataspace object using the existing id then return the object + DataSpace data_space( dataspace_id ); + return( data_space ); +} + +// This private member function calls the C API to get the identifier +// of the datatype that is used by this dataset. It is used +// by the various AbstractDs functions to get the specific datatype. +hid_t DataSet::p_getType() const +{ + hid_t type_id = H5Dget_type( id ); + if( type_id > 0 ) + return( type_id ); + else + { + throw DataSetIException(); + } +} + +// Gets the dataset creation property list +DSetCreatPropList DataSet::getCreatePlist() const +{ + hid_t create_plist_id = H5Dget_create_plist( id ); + if( create_plist_id <= 0 ) + { + throw DataSetIException(); + } + // create and return the DSetCreatPropList object + DSetCreatPropList create_plist( create_plist_id ); + return( create_plist ); +} + +// Returns the amount of storage required for a dataset. +hsize_t DataSet::getStorageSize() const +{ + hsize_t storage_size = H5Dget_storage_size( id ); + + if( storage_size > 0 ) + return( storage_size ); + else + { + throw DataSetIException(); + } +} + +// Returns the number of bytes required to store VL data. +hsize_t DataSet::getVlenBufSize( DataType& type, DataSpace& space ) const +{ + //herr_t ret_value; + // Obtain identifiers for C API + //hid_t type_id = type.getId(); + //hid_t space_id = space.getId(); + //hsize_t size; + + throw DataSetIException( "getVlenBufSize: Currently not implemented yet."); + //ret_value = H5Dget_vlen_buf_size( id, type_id, space_id, &size ); + //if( ret_value >= 0 ) + // return( size ); + //else + //{ + //throw DataSetIException(); + //} +} + +// Reclaims VL datatype memory buffers. +void DataSet::vlenReclaim( DataType& type, DataSpace& space, DSetMemXferPropList& xfer_plist, void* buf ) const +{ + herr_t ret_value; + // Obtain identifiers for C API + hid_t type_id = type.getId(); + hid_t space_id = space.getId(); + hid_t xfer_plist_id = xfer_plist.getId(); + + ret_value = H5Dvlen_reclaim( type_id, space_id, xfer_plist_id, buf ); + if( ret_value < 0 ) + { + throw DataSetIException(); + } +} + +// Reads raw data from the specified dataset into buf, converting from +// file datatype and dataspace to memory datatype and dataspace. +void DataSet::read( void* buf, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist ) const +{ + // Obtain identifiers for C API + hid_t mem_type_id = mem_type.getId(); + hid_t mem_space_id = mem_space.getId(); + hid_t file_space_id = file_space.getId(); + hid_t xfer_plist_id = xfer_plist.getId(); + + herr_t ret_value = H5Dread( id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, buf ); + if( ret_value < 0 ) + { + throw DataSetIException(); + } +} + +// Writes raw data from an application buffer buffer to a dataset, +// converting from memory datatype and dataspace to file datatype +// and dataspace. +void DataSet::write( const void* buf, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist ) const +{ + // Obtain identifiers for C API + hid_t mem_type_id = mem_type.getId(); + hid_t mem_space_id = mem_space.getId(); + hid_t file_space_id = file_space.getId(); + hid_t xfer_plist_id = xfer_plist.getId(); + + herr_t ret_value = H5Dwrite( id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, buf ); + if( ret_value < 0 ) + { + throw DataSetIException(); + } +} + +// Iterates over all selected elements in a dataspace. +int DataSet::iterateElems( void* buf, const DataType& type, const DataSpace& space, H5D_operator_t op, void* op_data ) +{ + // Obtain identifiers for C API + hid_t type_id = type.getId(); + hid_t space_id = space.getId(); + herr_t ret_value = H5Diterate( buf, type_id, space_id, op, op_data ); + if( ret_value >= 0 ) + return( ret_value ); + else // raise exception when H5Diterate returns a negative value + { + throw DataSetIException(); + } +} + +// Extends a dataset with unlimited dimension. +void DataSet::extend( const hsize_t* size ) const +{ + herr_t ret_value = H5Dextend( id, size ); + if( ret_value < 0 ) // raise exception when H5Dextend returns a neg value + { + throw DataSetIException(); + } +} + +// This private function calls the C API H5Dclose to close this dataset. +// Used by IdComponent::reset +void DataSet::p_close() const +{ + herr_t ret_value = H5Dclose( id ); + if( ret_value < 0 ) + { + throw DataSetIException(); + } +} + +// The destructor of this instance calls IdComponent::reset to +// reset its identifier - no longer true +// Older compilers (baldric) don't support template member functions +// and IdComponent::reset is one; so at this time, the resetId is not +// a member function so it can be template to work around that problem. +DataSet::~DataSet() +{ + // The dataset id will be closed properly + resetIdComponent( this ); +} + +#ifndef H5_NO_NAMESPACE +} // end namespace +#endif |