[svn-r13200] Purpose: Adding wrappers and fixing a bug

Description:
    - Added overloaded function DataType::copy to take a DataSet
    - Added overloaded DataType::commit
    - Fixed bugzilla 797
    - Fixed a warning in DataSpace::operator=
    - Set PropList parameter to default in DataType::convert

Platforms tested
    AIX 5.1 (copper)
    SunOS 5.8 64-bit (sol)
    HPUX 11.00 (kelgia)
This commit is contained in:
Binh-Minh Ribler 2007-01-26 00:34:10 -05:00
parent 73b8819a42
commit 134352c456
6 changed files with 116 additions and 25 deletions

View File

@ -983,8 +983,8 @@ H5std_string CommonFG::getObjnameByIdx(hsize_t idx) const
}
// now, allocate C buffer to get the name
char* name_C = new char[name_len];
name_len = H5Gget_objname_by_idx(getLocId(), idx, name_C, name_len);
char* name_C = new char[name_len+1];
name_len = H5Gget_objname_by_idx(getLocId(), idx, name_C, name_len+1);
// clean up and return the string
H5std_string name = H5std_string(name_C);

View File

@ -136,10 +136,8 @@ void DataSpace::copy( const DataSpace& like_space )
DataSpace& DataSpace::operator=( const DataSpace& rhs )
{
if (this != &rhs)
{
copy(rhs);
return(*this);
}
copy(rhs);
return(*this);
}
//--------------------------------------------------------------------------

View File

@ -25,12 +25,18 @@
#include "H5PropList.h"
#include "H5DataSpace.h"
#include "H5Object.h"
#include "H5FaccProp.h"
#include "H5FcreatProp.h"
#include "H5DcreatProp.h"
#include "H5DxferProp.h"
#include "H5CommonFG.h"
#include "H5DataType.h"
#include "H5AtomType.h"
#include "H5PredType.h"
#include "H5private.h"
#include "H5AbstractDs.h"
#include "H5DataSet.h"
#include "H5File.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
@ -132,6 +138,31 @@ void DataType::copy( const DataType& like_type )
throw DataTypeIException(inMemFunc("copy"), "H5Tcopy failed");
}
//--------------------------------------------------------------------------
// Function: DataType::copy
///\brief Copies the datatype of the given dataset to this datatype object
///\param dset - IN: Dataset
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - Jan, 2007
///\parDescription
/// The resulted dataset will be transient and modifiable.
//--------------------------------------------------------------------------
void DataType::copy(const DataSet& dset)
{
// close the current data type before copying dset's datatype to this object
try {
close();
}
catch (Exception close_error) {
throw DataTypeIException(inMemFunc("copy"), close_error.getDetailMsg());
}
// call C routine to copy the datatype
id = H5Tcopy( dset.getId() );
if( id < 0 )
throw DataTypeIException(inMemFunc("copy"), "H5Tcopy failed");
}
//--------------------------------------------------------------------------
// Function: DataType::operator=
///\brief Assignment operator
@ -174,25 +205,42 @@ bool DataType::operator==(const DataType& compared_type ) const
}
}
//--------------------------------------------------------------------------
// Function: DataType::p_commit (private)
//\brief Commits a transient datatype to a file, creating a new
// named datatype
//\param loc_id - IN: The id of either a file, group, dataset, named
// datatype, or attribute.
//\param name - IN: Name of the datatype
//\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
// Modification:
// Copied from DataType::commit and made into private function
// to be commonly used by several overloads of DataType::commit.
// BMR - Jan, 2007
//--------------------------------------------------------------------------
void DataType::p_commit(hid_t loc_id, const char* name)
{
// Call C routine to commit the transient datatype
herr_t ret_value = H5Tcommit(loc_id, name, id);
if( ret_value < 0 )
{
throw DataTypeIException(inMemFunc("p_commit"), "H5Tcommit failed");
}
}
//--------------------------------------------------------------------------
// Function: DataType::commit
///\brief Commits a transient datatype to a file, creating a new
/// named datatype
///\param loc - IN: Either a file or a group
///\param loc - IN: A file
///\param name - IN: Name of the datatype
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DataType::commit(CommonFG& loc, const char* name) const
void DataType::commit(H5File& loc, const char* name)
{
hid_t loc_id = loc.getLocId(); // get location id for C API
// Call C routine to commit the transient datatype
herr_t ret_value = H5Tcommit( loc_id, name, id );
if( ret_value < 0 )
{
throw DataTypeIException(inMemFunc("commit"), "H5Tcommit failed");
}
p_commit(loc.getLocId(), name);
}
//--------------------------------------------------------------------------
@ -202,9 +250,35 @@ void DataType::commit(CommonFG& loc, const char* name) const
/// argument \a name.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DataType::commit(CommonFG& loc, const H5std_string& name) const
void DataType::commit(H5File& loc, const H5std_string& name)
{
commit( loc, name.c_str() );
p_commit(loc.getLocId(), name.c_str());
}
//--------------------------------------------------------------------------
// Function: DataType::commit
///\brief Commits a transient datatype to a file, creating a new
/// named datatype
///\param loc - IN: Either a group, dataset, named datatype, or attribute.
///\param name - IN: Name of the datatype
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - Jan, 2007
//--------------------------------------------------------------------------
void DataType::commit(H5Object& loc, const char* name)
{
p_commit(loc.getId(), name);
}
//--------------------------------------------------------------------------
// Function: DataType::commit
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in the type of the
/// argument \a name.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DataType::commit(H5Object& loc, const H5std_string& name)
{
p_commit(loc.getId(), name.c_str());
}
//--------------------------------------------------------------------------
@ -264,7 +338,7 @@ H5T_conv_t DataType::find( const DataType& dest, H5T_cdata_t **pcdata ) const
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void DataType::convert( const DataType& dest, size_t nelmts, void *buf, void *background, PropList& plist ) const
void DataType::convert( const DataType& dest, size_t nelmts, void *buf, void *background, const PropList& plist ) const
{
// Get identifiers for C API
hid_t dest_id = dest.getId();

View File

@ -34,16 +34,21 @@ class H5_DLLCPP DataType : public H5Object {
// Closes this datatype.
virtual void close();
// Copies an existing datatype to this datatype object
void copy( const DataType& like_type );
// Copies an existing datatype to this datatype object.
void copy(const DataType& like_type);
// Copies the datatype of dset to this datatype object.
void copy(const DataSet& dset);
// Returns the datatype class identifier.
H5T_class_t getClass() const;
// Commits a transient datatype to a file; this datatype becomes
// a named datatype which can be accessed from the location.
void commit( CommonFG& loc, const char* name ) const;
void commit( CommonFG& loc, const H5std_string& name ) const;
void commit( H5File& loc, const char* name);
void commit( H5File& loc, const H5std_string& name);
void commit( H5Object& loc, const char* name);
void commit( H5Object& loc, const H5std_string& name);
// Determines whether this datatype is a named datatype or
// a transient datatype.
@ -54,7 +59,7 @@ class H5_DLLCPP DataType : public H5Object {
H5T_conv_t find( const DataType& dest, H5T_cdata_t **pcdata ) const;
// Converts data from between specified datatypes.
void convert( const DataType& dest, size_t nelmts, void *buf, void *background, PropList& plist ) const;
void convert( const DataType& dest, size_t nelmts, void *buf, void *background, const PropList& plist=PropList::DEFAULT) const;
// Assignment operator
DataType& operator=( const DataType& rhs );
@ -118,6 +123,8 @@ class H5_DLLCPP DataType : public H5Object {
// Destructor: properly terminates access to this datatype.
virtual ~DataType();
private:
void p_commit(hid_t loc_id, const char* name);
};
#ifndef H5_NO_NAMESPACE
}

View File

@ -265,9 +265,19 @@ PredType& PredType::operator=( const PredType& rhs )
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// These dummy functions do not inherit from DataType - they'll
// throw an DataTypeIException if invoked.
void PredType::commit( H5File& loc, const char* name )
{
throw DataTypeIException("PredType::commit", "Error: Attempted to commit a predefined datatype. Invalid operation!" );
}
void PredType::commit( H5File& loc, const H5std_string& name )
{
commit( loc, name.c_str());
}
void PredType::commit( H5Object& loc, const char* name )
{
throw DataTypeIException("PredType::commit", "Attempting to commit a predefined datatype. This operation is invalid" );
throw DataTypeIException("PredType::commit", "Error: Attempted to commit a predefined datatype. Invalid operation!" );
}
void PredType::commit( H5Object& loc, const H5std_string& name )

View File

@ -220,6 +220,8 @@ class H5_DLLCPP PredType : public AtomType {
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// These dummy functions do not inherit from DataType - they'll
// throw a DataTypeIException if invoked.
void commit( H5File& loc, const H5std_string& name );
void commit( H5File& loc, const char* name );
void commit( H5Object& loc, const H5std_string& name );
void commit( H5Object& loc, const char* name );
bool committed();