Hdf4Attribute Class Reference

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

#include <Hdf4Attribute.h>

List of all members.

Public Member Functions

virtual const std::string & getName () const
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

 Hdf4Attribute (const std::string &name, const DataVariant &value)
virtual ~Hdf4Attribute ()


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 Hdf4Dataset.

The Hdf4Attribute class CANNOT be created by itself. Only an Hdf4Element 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 Hdf4Group
 // create a complex attribute
 Hdf4Attribute* 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 Hdf4Group
 // create a vector<int> attribute
 // since this is a built-in type, the attribute allocates the memory for us
 Hdf4Attribute* 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:
Hdf4Dataset::addAttribute(), Hdf4File::addAttribute()

Definition at line 47 of file Hdf4Attribute.h.


Constructor & Destructor Documentation

Hdf4Attribute::Hdf4Attribute ( 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 Hdf4Element::addAttribute() to add an attribute to an Hdf4Element.

Parameters:
name The name of the attribute.
value The current value of the attribute.

virtual Hdf4Attribute::~Hdf4Attribute (  )  [protected, virtual]

Destroys an Hdf4Attribute object.

Use Hdf4Element::removeAttribute() to delete an Hdf4Attribute from an Hdf4Element.


Member Function Documentation

virtual const std::string& Hdf4Attribute::getName (  )  const [virtual]

Gets the attribute name.

Returns:
Returns the name of the attribute.

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

Sets the value of the attribute.

Parameters:
var A variant holding the attribute value.

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

Returns a reference to the object.

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

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

Returns a reference to the object.

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

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

Retrieves the value.

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

Definition at line 85 of file Hdf4Attribute.h.

template<class T>
const T* Hdf4Attribute::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 96 of file Hdf4Attribute.h.


Software Development Kit - Opticks 4.9.0 Build 16218