diff options
Diffstat (limited to 'c++')
-rw-r--r-- | c++/src/H5Attribute.cpp | 31 | ||||
-rw-r--r-- | c++/src/H5Attribute.h | 2 | ||||
-rw-r--r-- | c++/src/H5DataSet.cpp | 26 | ||||
-rw-r--r-- | c++/src/H5DataSet.h | 4 | ||||
-rw-r--r-- | c++/src/H5DataSpace.cpp | 8 | ||||
-rw-r--r-- | c++/src/H5DataType.cpp | 2 | ||||
-rw-r--r-- | c++/src/H5Exception.cpp | 10 | ||||
-rw-r--r-- | c++/src/H5Exception.h | 7 | ||||
-rw-r--r-- | c++/src/H5File.cpp | 2 | ||||
-rw-r--r-- | c++/src/H5Group.cpp | 2 | ||||
-rw-r--r-- | c++/src/H5StrType.cpp | 11 | ||||
-rw-r--r-- | c++/src/H5StrType.h | 3 |
12 files changed, 83 insertions, 25 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 09e53d3..5c9dfb3 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -52,6 +52,33 @@ void Attribute::write( const DataType& mem_type, const void *buf ) const } } +void Attribute::write( const DataType& mem_type, const string& strg ) const +{ + // Convert string to C-string + const char* strg_C; + strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str + + herr_t ret_value = H5Awrite( id, mem_type.getId(), strg_C ); + if( ret_value < 0 ) + { + throw AttributeIException("Attribute::write", "H5Awrite failed"); + } +} + +// Reads data from this attribute. +void Attribute::read( const DataType& mem_type, string& strg ) const +{ + size_t size = mem_type.getSize(); + char* strg_C = new char[size+1]; // temporary C-string for C API + herr_t ret_value = H5Aread( id, mem_type.getId(), strg_C ); + if( ret_value < 0 ) + { + throw AttributeIException("Attribute::read", "H5Aread failed"); + } + strg = strg_C; + delete strg_C; +} + // Reads data from this attribute. void Attribute::read( const DataType& mem_type, void *buf ) const { @@ -109,7 +136,7 @@ ssize_t Attribute::getName( size_t buf_size, string& attr_name ) const throw AttributeIException("Attribute::getName", "H5Aget_name failed"); } // otherwise, convert the C string attribute name and return - attr_name = string( name_C ); + attr_name = name_C; delete name_C; return( name_size ); } @@ -145,7 +172,7 @@ Attribute::~Attribute() try { resetIdComponent( this ); } catch (Exception close_error) { // thrown by p_close - cerr << "Attribute::~Attribute" << close_error.getDetailMsg() << endl; + cerr << "Attribute::~Attribute - " << close_error.getDetailMsg() << endl; } } diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index 2725242..7053f8c 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -24,9 +24,11 @@ class H5_DLLCPP Attribute : public AbstractDs { public: // Writes data to this attribute. void write(const DataType& mem_type, const void *buf ) const; + void write(const DataType& mem_type, const string& strg ) const; // Reads data from this attribute. void read( const DataType& mem_type, void *buf ) const; + void read( const DataType& mem_type, string& strg ) const; // Gets a copy of the dataspace for this attribute. virtual DataSpace getSpace() const; diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index 5eb640c..84bed5c 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -156,6 +156,20 @@ void DataSet::read( void* buf, const DataType& mem_type, const DataSpace& mem_sp } } +void DataSet::read( string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist ) const +{ + // Allocate C character string for reading + size_t size = mem_type.getSize(); + char* strg_C = new char[size+1]; // temporary C-string for C API + + // Use the overloaded member to read + read(strg_C, mem_type, mem_space, file_space, xfer_plist); + + // Get the String and clean up + strg = strg_C; + delete strg_C; +} + // Writes raw data from an application buffer buffer to a dataset, // converting from memory datatype and dataspace to file datatype // and dataspace. @@ -174,6 +188,16 @@ void DataSet::write( const void* buf, const DataType& mem_type, const DataSpace& } } +void DataSet::write( const string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist ) const +{ + // Convert string to C-string + const char* strg_C; + strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str + + // Use the overloaded member + write(strg_C, mem_type, mem_space, file_space, xfer_plist); +} + // 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 ) { @@ -262,7 +286,7 @@ DataSet::~DataSet() try { resetIdComponent( this ); } catch (Exception close_error) { // thrown by p_close - cerr << "DataSet::~DataSet" << close_error.getDetailMsg() << endl; + cerr << "DataSet::~DataSet - " << close_error.getDetailMsg() << endl; } } diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h index c66a21c..9f01eb4 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -33,7 +33,7 @@ class H5_DLLCPP DataSet : public AbstractDs { // Gets the storage size of this dataset. hsize_t getStorageSize() const; - // - C version not yet implemented?? + // not yet implemented?? hsize_t getVlenBufSize( DataType& type, DataSpace& space ) const; void vlenReclaim( DataType& type, DataSpace& space, DSetMemXferPropList& xfer_plist, void* buf ) const; @@ -41,11 +41,13 @@ class H5_DLLCPP DataSet : public AbstractDs { // The memory and file dataspaces and the transferring property list // can be defaults. void read( void* buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; + void read( string& buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; // Writes the buffered data to this dataset. // The memory and file dataspaces and the transferring property list // can be defaults. void write( const void* buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; + void write( const string& buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; // Iterates the selected elements in the specified dataspace - not implemented in C++ style yet int iterateElems( void* buf, const DataType& type, const DataSpace& space, H5D_operator_t op, void* op_data = NULL ); diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp index c6c64a8..5921274 100644 --- a/c++/src/H5DataSpace.cpp +++ b/c++/src/H5DataSpace.cpp @@ -57,7 +57,11 @@ DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : /* Constructor that takes an existing dataspace id Description: - Uses an HDF5 id to create a DataSpace identifier instance. This id can be either an existing dataspace id or a default dataspace id. Design note: in the case of default dataspace, the identifier still has reference counter; the p_close function will take care of not to call H5Sclose on the default id. + Uses an HDF5 id to create a DataSpace identifier instance. + This id can be either an existing dataspace id or a default + dataspace id. Design note: in the case of default dataspace, + the identifier still has reference counter; the p_close function + will take care of not to call H5Sclose on the default id. */ DataSpace::DataSpace( const hid_t space_id ) : IdComponent( space_id ) {} @@ -361,7 +365,7 @@ DataSpace::~DataSpace() try { resetIdComponent( this ); } catch (Exception close_error) { // thrown by p_close - cerr << "DataSpace::~DataSpace" << close_error.getDetailMsg() << endl; + cerr << "DataSpace::~DataSpace - " << close_error.getDetailMsg() << endl; } } diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index aba1949..290ebb7 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -357,7 +357,7 @@ DataType::~DataType() try { resetIdComponent( this ); } catch (Exception close_error) { // thrown by p_close - cerr << "DataType::~DataType" << close_error.getDetailMsg() << endl; + cerr << "DataType::~DataType - " << close_error.getDetailMsg() << endl; } } diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp index d493662..807d703 100644 --- a/c++/src/H5Exception.cpp +++ b/c++/src/H5Exception.cpp @@ -18,7 +18,7 @@ #ifndef H5_NO_NAMESPACE namespace H5 { #ifndef H5_NO_STD - using namespace std; + using namespace std; #endif // H5_NO_STD #endif @@ -206,14 +206,6 @@ IdComponentException::IdComponentException(const string& func_name, const string IdComponentException::IdComponentException(const char* func_name, const char* message) : Exception(func_name, message) {} IdComponentException::~IdComponentException() {} -// The following are from Java API but not done here: -// AtomException, BtreeException, DataFiltersException, -// ExternalFileListException, FunctionEntryExitException, -// HeapException, InternalErrorException, LowLevelIOException, -// MetaDataCacheException, ResourceUnavailableException, -// SymbolTableException, ObjectHeaderException, FunctionArgumentException, -// DataStorageException - #ifndef H5_NO_NAMESPACE } // end namespace #endif diff --git a/c++/src/H5Exception.h b/c++/src/H5Exception.h index a77400e..5f159e8 100644 --- a/c++/src/H5Exception.h +++ b/c++/src/H5Exception.h @@ -167,13 +167,6 @@ class H5_DLLCPP IdComponentException : public Exception { virtual ~IdComponentException(); }; -// The following are from Java API but not done here: -// AtomException, BtreeException, DataFiltersException, -// ExternalFilelistException, FunctionEntryExitException, -// HeapException, InternalErrorException, LowLevelIOException, -// MetaDataCacheException, ResourceUnavailableException, -// SymbolTableException, ObjectHeaderException, FunctionArgumentException, -// DataStorageException #ifndef H5_NO_NAMESPACE } #endif diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index a314693..75c9e55 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -203,7 +203,7 @@ H5File::~H5File() try { resetIdComponent( this ); } catch (Exception close_error) { // thrown by p_close - cerr << "H5File::~H5File" << close_error.getDetailMsg() << endl; + cerr << "H5File::~H5File - " << close_error.getDetailMsg() << endl; } } diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index f805778..279c620 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -156,7 +156,7 @@ Group::~Group() try { resetIdComponent( this ); } catch (Exception close_error) { // thrown by p_close - cerr << "Group::~Group" << close_error.getDetailMsg() << endl; + cerr << "Group::~Group - " << close_error.getDetailMsg() << endl; } } diff --git a/c++/src/H5StrType.cpp b/c++/src/H5StrType.cpp index 5b25be1..683fc0b 100644 --- a/c++/src/H5StrType.cpp +++ b/c++/src/H5StrType.cpp @@ -43,6 +43,17 @@ StrType::StrType( const PredType& pred_type ) : AtomType() copy( pred_type ); } +// Creates a string type with a specified length - 1st argument could +// have been skipped, but this constructor will collide with the one +// that takes an existing id below +StrType::StrType( const PredType& pred_type, const size_t size ) : AtomType() +{ + // use DataType::copy to make a copy of the string predefined type + // then set its length + copy(pred_type); + setSize(size); +} + // Creates a string datatype using an existing id StrType::StrType( const hid_t existing_id ) : AtomType( existing_id ) {} diff --git a/c++/src/H5StrType.h b/c++/src/H5StrType.h index 0ddc748..8d6070c 100644 --- a/c++/src/H5StrType.h +++ b/c++/src/H5StrType.h @@ -28,6 +28,9 @@ class H5_DLLCPP StrType : public AtomType { // Creates a string type using a predefined type StrType( const PredType& pred_type ); + // Creates a string type with specified length + StrType( const PredType& pred_type, const size_t size ); + // Creates a string datatype using an existing id StrType( const hid_t existing_id ); |