diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2007-02-01 04:05:12 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2007-02-01 04:05:12 (GMT) |
commit | f6c6e676eceb1ab51ab9906ac6607463f06fece4 (patch) | |
tree | dce12011f0c3c8a8d07bc5013fe5911207aa822a | |
parent | 4319dc561b19a9a71c1b9f7585155b60578b05c5 (diff) | |
download | hdf5-f6c6e676eceb1ab51ab9906ac6607463f06fece4.zip hdf5-f6c6e676eceb1ab51ab9906ac6607463f06fece4.tar.gz hdf5-f6c6e676eceb1ab51ab9906ac6607463f06fece4.tar.bz2 |
[svn-r13227] Purpose: Adding wrappers
Description:
- Added overloaded function DataType::copy to take a DataSet
- Added overloaded DataType::commit
- Set PropList parameter to default in DataType::convert
Platforms tested
AIX 5.1 (copper)
SunOS 5.8 64-bit (sol)
Linux 2.6 (kagiso)
-rw-r--r-- | c++/src/H5DataType.cpp | 104 | ||||
-rw-r--r-- | c++/src/H5DataType.h | 17 | ||||
-rw-r--r-- | c++/src/H5PredType.cpp | 12 | ||||
-rw-r--r-- | c++/src/H5PredType.h | 2 |
4 files changed, 114 insertions, 21 deletions
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 348c037..0fe7684 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -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 { @@ -112,7 +118,7 @@ DataType::DataType(const DataType& original) : H5Object(original) {} // Programmer Binh-Minh Ribler - 2000 // Modification // - Replaced resetIdComponent() with decRefCount() to use C -// library ID reference counting mechanism - BMR, Feb 20, 2005 +// library ID reference counting mechanism - BMR, Jun 1, 2004 // - Replaced decRefCount with close() to let the C library // handle the reference counting - BMR, Jun 1, 2006 //-------------------------------------------------------------------------- @@ -133,6 +139,31 @@ void DataType::copy( const DataType& like_type ) } //-------------------------------------------------------------------------- +// 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 ///\param rhs - IN: Reference to the existing datatype @@ -175,24 +206,67 @@ 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 + p_commit(loc.getLocId(), 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("commit"), "H5Tcommit failed"); - } +//-------------------------------------------------------------------------- +// 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(H5File& loc, const H5std_string& name) +{ + 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); } //-------------------------------------------------------------------------- @@ -202,16 +276,16 @@ 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(H5Object& loc, const H5std_string& name) { - commit( loc, name.c_str() ); + p_commit(loc.getId(), name.c_str()); } //-------------------------------------------------------------------------- // Function: DataType::committed ///\brief Determines whether a datatype is a named type or a /// transient type. -///\return \c true if the datatype is a named type, and \c false, +///\return \c true if the datatype is a named type, and \c false, /// otherwise. ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 @@ -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(); @@ -702,7 +776,7 @@ void DataType::close() // Programmer Binh-Minh Ribler - 2000 // Modification // - Replaced resetIdComponent() with decRefCount() to use C -// library ID reference counting mechanism - BMR, Feb 20, 2005 +// library ID reference counting mechanism - BMR, Jun 1, 2004 // - Replaced decRefCount with close() to let the C library // handle the reference counting - BMR, Jun 1, 2006 //-------------------------------------------------------------------------- diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 60313d4..588dd2a 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -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 ); @@ -124,6 +129,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 } diff --git a/c++/src/H5PredType.cpp b/c++/src/H5PredType.cpp index bb0b688..eb55914 100644 --- a/c++/src/H5PredType.cpp +++ b/c++/src/H5PredType.cpp @@ -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 ) diff --git a/c++/src/H5PredType.h b/c++/src/H5PredType.h index 3699348..73e105c 100644 --- a/c++/src/H5PredType.h +++ b/c++/src/H5PredType.h @@ -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(); |