Hdf5Attribute Class Reference

The HDF Attribute class is designed to provide an abstraction for the HDF Attribute data type. More...

#include <Hdf5Attribute.h>

Inheritance diagram for Hdf5Attribute:

Inheritance graph

List of all members.

Public Member Functions

virtual void setVariant (const DataVariant &var)
virtual const DataVariantgetVariant () const
virtual DataVariantgetVariant ()
template<class T>
bool getValueAs (T &value) const
template<class T>
const T * getValueAsPointer () const

Protected Member Functions

 Hdf5Attribute (Hdf5Node *pParent, const std::string &name, const DataVariant &value)
 ~Hdf5Attribute ()
Hdf5Data::DataReader * createReader () const


Detailed Description

The HDF Attribute class is designed to provide an abstraction for the HDF Attribute data type.

Attributes are small metadata elements that are associated with an Hdf5Dataset.

The Hdf5Attribute class CANNOT be created by itself. Only an Hdf5Element can create or destroy them. Currently supported are all basic types and vectors of basic types. Any other types must have their memory allocated manually. Examples:

 // assume pDataset exists and is a member of some Hdf5Group
 // create a complex attribute
 Hdf5Attribute* pAttr = pDataset->addAttribute("complex", 2);
 IntegerComplex* pCompl = new IntegerComplex[2];
 // set pCompl
 pAttr->setValue(pCompl); // pAttr now owns this memory

 // assume pDataset exists and is a member of some Hdf5Group
 // create a vector<int> attribute
 // since this is a built-in type, the attribute allocates the memory for us
 Hdf5Attribute* pAttr = pDataset->addAttribute("vector<int>", 2);
 int* pVector = pAttr->getFirstValue(); // get a pointer to the first value in the vector and start writing
 fread(pVector, sizeof(int), 2, pInputFile); // read directly from file into attribute

See also:
Hdf5Dataset::addAttribute(), Hdf5File::addAttribute()

Definition at line 49 of file Hdf5Attribute.h.


Constructor & Destructor Documentation

Hdf5Attribute::Hdf5Attribute ( Hdf5Node pParent,
const std::string &  name,
const DataVariant value 
) [protected]

Creates an attribute with a given type and number of elements.

This method cannot be called directly. Use Hdf5Element::addAttribute() to add an attribute to an Hdf5Element.

Parameters:
pParent The Hdf5Node that this attribute belongs to.
name The name of the attribute.
value The current value of the attribute.

Hdf5Attribute::~Hdf5Attribute (  )  [protected]

Destroys an Hdf5Attribute object.

Use Hdf5Element::removeAttribute() to delete an Hdf5Attribute from an Hdf5Element.


Member Function Documentation

virtual void Hdf5Attribute::setVariant ( const DataVariant var  )  [virtual]

Sets the value of the attribute.

Parameters:
var A variant holding the attribute value.

virtual const DataVariant& Hdf5Attribute::getVariant (  )  const [virtual]

Returns a reference to the object.

Returns:
Returns a reference to the member value representing the attribute.

virtual DataVariant& Hdf5Attribute::getVariant (  )  [virtual]

Returns a reference to the object.

Returns:
Returns a reference to the member value representing the attribute.

template<class T>
bool Hdf5Attribute::getValueAs ( T &  value  )  const

Retrieves the value.

Returns:
true if the value was successfully retrieved or valse otherwise.

Definition at line 80 of file Hdf5Attribute.h.

template<class T>
const T* Hdf5Attribute::getValueAsPointer (  )  const

Returns a pointer to the value or NULL if the type does not match.

Returns:
Returns the pointer value representing the attribute.

Definition at line 92 of file Hdf5Attribute.h.

Hdf5Data::DataReader* Hdf5Attribute::createReader (  )  const [protected, virtual]

Implements Hdf5Data.


Software Development Kit - Opticks 4.9.0 Build 16218