summaryrefslogtreecommitdiffstats
path: root/c++/src/H5Object.C
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2000-11-14 21:30:12 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2000-11-14 21:30:12 (GMT)
commit92041a68656c59813619ae1f26ed211b7f028e86 (patch)
treeaaa3256c9a9f0adde21570eac9254f7ce00450b1 /c++/src/H5Object.C
parent36acd5381e3977164e0d6d666f8ce97cc53f9387 (diff)
downloadhdf5-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/H5Object.C')
-rw-r--r--c++/src/H5Object.C168
1 files changed, 168 insertions, 0 deletions
diff --git a/c++/src/H5Object.C b/c++/src/H5Object.C
new file mode 100644
index 0000000..82f7849
--- /dev/null
+++ b/c++/src/H5Object.C
@@ -0,0 +1,168 @@
+#include <string>
+
+#include "H5Include.h"
+#include "H5RefCounter.h"
+#include "H5Exception.h"
+#include "H5IdComponent.h"
+#include "H5Idtemplates.h"
+#include "H5PropList.h"
+#include "H5Object.h"
+#include "H5DataType.h"
+#include "H5DataSpace.h"
+#include "H5AbstractDs.h"
+#include "H5Attribute.h"
+
+#ifndef H5_NO_NAMESPACE
+namespace H5 {
+#endif
+
+// userAttrOpWrpr simply interfaces between the user's function and the
+// C library function H5Aiterate; used to resolve the different prototype
+// problem. May be moved to Iterator later.
+extern "C" herr_t userAttrOpWrpr( hid_t loc_id, const char* attr_name, void* op_data )
+{
+ string s_attr_name = string( attr_name );
+ UserData4Aiterate* myData = static_cast <UserData4Aiterate *> (op_data);
+ myData->op( *myData->object, s_attr_name, myData->opData );
+ return 0;
+}
+
+// Default constructor - set id to 0 by default here but may be set
+// to a valid HDF5 id, if any, by a subclass constructor.
+H5Object::H5Object() : IdComponent() {}
+
+// Constructs an object from an existing HDF5 id
+H5Object::H5Object( hid_t object_id ) : IdComponent( object_id ) {}
+
+// Copy constructor: makes a copy of the original H5Object instance
+H5Object::H5Object( const H5Object& original ) : IdComponent( original ) {}
+
+// Creates an attribute for a group, dataset, or named datatype.
+Attribute H5Object::createAttribute( const char* name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist ) const
+{
+ hid_t type_id = data_type.getId();
+ hid_t space_id = data_space.getId();
+ hid_t plist_id = create_plist.getId();
+ hid_t attr_id = H5Acreate( id, name, type_id, space_id, plist_id );
+
+ // If the attribute id is valid, create and return the Attribute object
+ if( attr_id > 0 )
+ {
+ Attribute attr( attr_id );
+ return( attr );
+ }
+ else
+ {
+ throw AttributeIException();
+ }
+}
+
+// Creates an attribute for a group, dataset, or named datatype.
+Attribute H5Object::createAttribute( const string& name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist ) const
+{
+ return( createAttribute( name.c_str(), data_type, data_space, create_plist ));
+}
+
+// Opens an attribute given its name; name is given as char*
+Attribute H5Object::openAttribute( const char* name ) const
+{
+ hid_t attr_id = H5Aopen_name( id, name );
+ if( attr_id > 0 )
+ {
+ Attribute attr( attr_id );
+ return( attr );
+ }
+ else
+ {
+ throw AttributeIException();
+ }
+}
+
+// Opens an attribute given its name; name is given as string
+Attribute H5Object::openAttribute( const string& name ) const
+{
+ return( openAttribute( name.c_str()) );
+}
+
+// Opens an attribute given its index.
+Attribute H5Object::openAttribute( unsigned int idx ) const
+{
+ hid_t attr_id = H5Aopen_idx( id, idx );
+ if( attr_id > 0 )
+ {
+ Attribute attr( attr_id );
+ return( attr );
+ }
+ else
+ {
+ throw AttributeIException();
+ }
+}
+
+// Iterates a user's function over all the attributes of the dataset
+int H5Object::iterateAttrs( attr_operator_t user_op, unsigned * idx, void *op_data )
+{
+ // store the user's function and data
+ UserData4Aiterate* userData = new UserData4Aiterate;
+ userData->opData = op_data;
+ userData->idx = idx;
+ userData->op = user_op;
+ userData->object = this;
+
+ // call the C library routine H5Aiterate to iterate the attributes
+ int ret_value = H5Aiterate( id, idx, userAttrOpWrpr, (void *) userData );
+ // release memory
+ delete userData;
+
+ if( ret_value >= 0 )
+ return( ret_value );
+ else // raise exception when H5Aiterate returns a negative value
+ {
+ throw AttributeIException();
+ }
+}
+
+// Determines the number of attributes attached to
+int H5Object::getNumAttrs() const
+{
+ int num_attrs = H5Aget_num_attrs( id );
+ if( num_attrs < 0 )
+ {
+ throw AttributeIException();
+ }
+ else
+ return( num_attrs );
+}
+
+// Removes the named attribute from this object.
+void H5Object::removeAttr( const char* name ) const
+{
+ herr_t ret_value = H5Adelete( id, name );
+ if( ret_value < 0 )
+ {
+ throw AttributeIException();
+ }
+}
+void H5Object::removeAttr( const string& name ) const
+{
+ removeAttr( name.c_str() );
+}
+
+// Flushes all buffers associated with a file to disk.
+void H5Object::flush(H5F_scope_t scope ) const
+{
+ herr_t ret_value = H5Fflush( id, scope );
+ if( ret_value < 0 )
+ {
+ throw FileIException();
+ }
+}
+
+// each subclass' destructor calls the template function resetIdComponent()
+// to reset the corresponding IdComponent object and close the HDF5 object
+// where appropriate.
+H5Object::~H5Object() {}
+
+#ifndef H5_NO_NAMESPACE
+} // end namespace
+#endif