summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c++/src/H5CommonFG.cpp4
-rw-r--r--c++/src/H5DataSpace.cpp6
-rw-r--r--c++/src/H5DataType.cpp98
-rw-r--r--c++/src/H5DataType.h17
-rw-r--r--c++/src/H5PredType.cpp12
-rw-r--r--c++/src/H5PredType.h2
6 files changed, 115 insertions, 24 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index cad625a..0d29b6c 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -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);
diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp
index 42c31ec..69834f6 100644
--- a/c++/src/H5DataSpace.cpp
+++ b/c++/src/H5DataSpace.cpp
@@ -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);
}
//--------------------------------------------------------------------------
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp
index 52c9bf2..c8ddc7e 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 {
@@ -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,9 +276,9 @@ 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());
}
//--------------------------------------------------------------------------
@@ -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();
diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h
index bb9b317..2d5e475 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 );
@@ -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
}
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();