Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Public Member Functions | List of all members
Nektar::LibUtilities::H5::CanHaveAttributes Class Reference

Mixin for objects that can have attributes (Group, DataSet, DataType) More...

#include <H5.h>

Inheritance diagram for Nektar::LibUtilities::H5::CanHaveAttributes:
Inheritance graph
[legend]
Collaboration diagram for Nektar::LibUtilities::H5::CanHaveAttributes:
Collaboration graph
[legend]

Classes

class  AttrIterator
 

Public Member Functions

AttributeSharedPtr CreateAttribute (const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
 
AttributeSharedPtr OpenAttribute (const std::string &name)
 
template<class T >
void SetAttribute (const std::string &name, const T &value)
 
template<class T >
void SetAttribute (const std::string &name, const std::vector< T > &value)
 
template<class T >
void GetAttribute (const std::string &name, T &value)
 
template<class T >
void GetAttribute (const std::string &name, std::vector< T > &value)
 
int GetNumAttr () const
 
AttrIterator attr_begin ()
 
AttrIterator attr_end ()
 
- Public Member Functions inherited from Nektar::LibUtilities::H5::Object
virtual void Close ()=0
 
hid_t GetId () const
 
 operator hid_t () const
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::LibUtilities::H5::Object
 Object ()
 
 Object (hid_t id)
 
virtual ~Object ()
 
- Protected Attributes inherited from Nektar::LibUtilities::H5::Object
hid_t m_Id
 

Detailed Description

Mixin for objects that can have attributes (Group, DataSet, DataType)

Definition at line 253 of file H5.h.

Member Function Documentation

CanHaveAttributes::AttrIterator Nektar::LibUtilities::H5::CanHaveAttributes::attr_begin ( )

Definition at line 338 of file H5.cpp.

339 {
340  // Have to use dynamic because of virtual inheritance
342  boost::dynamic_pointer_cast<CanHaveAttributes>(shared_from_this());
343  return CanHaveAttributes::AttrIterator(thisSh);
344 }
boost::shared_ptr< CanHaveAttributes > CanHaveAttributesSharedPtr
Definition: H5.h:90
CanHaveAttributes::AttrIterator Nektar::LibUtilities::H5::CanHaveAttributes::attr_end ( )

Definition at line 345 of file H5.cpp.

346 {
347  // Have to use dynamic because of virtual inheritance
349  boost::dynamic_pointer_cast<CanHaveAttributes>(shared_from_this());
350  return CanHaveAttributes::AttrIterator(thisSh, GetNumAttr());
351 }
boost::shared_ptr< CanHaveAttributes > CanHaveAttributesSharedPtr
Definition: H5.h:90
AttributeSharedPtr Nektar::LibUtilities::H5::CanHaveAttributes::CreateAttribute ( const std::string &  name,
DataTypeSharedPtr  type,
DataSpaceSharedPtr  space 
)

Definition at line 319 of file H5.cpp.

References Nektar::LibUtilities::H5::Attribute::Create().

Referenced by SetAttribute().

322 {
323  return Attribute::Create(m_Id, name, type, space);
324 }
static AttributeSharedPtr Create(hid_t parent, const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:520
template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::GetAttribute ( const std::string &  name,
T &  value 
)

Definition at line 640 of file H5.h.

References Nektar::LibUtilities::H5::DataTypeTraits< T >::Deconvert(), Nektar::LibUtilities::H5::DataTypeTraits< T >::GetAddress(), Nektar::LibUtilities::H5::DataTypeTraits< T >::GetType(), H5_CALL, OpenAttribute(), and Nektar::LibUtilities::H5::DataSpace::Scalar().

641 {
644  AttributeSharedPtr attr = OpenAttribute(name);
645 
646  typename DataTypeTraits<T>::ConvertedType conv;
647 
648  H5_CALL(
649  H5Aread,
650  (attr->GetId(), type->GetId(), DataTypeTraits<T>::GetAddress(conv)));
651  value = DataTypeTraits<T>::Deconvert(conv);
652 }
#define H5_CALL(func, args)
Definition: H5.h:68
static const void * GetAddress(const ConvertedType &obj)
static DataTypeSharedPtr GetType()
Definition: H5.h:538
boost::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:86
boost::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:88
boost::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:92
static DataSpaceSharedPtr Scalar()
Definition: H5.cpp:397
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:564
AttributeSharedPtr OpenAttribute(const std::string &name)
Definition: H5.cpp:326
template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::GetAttribute ( const std::string &  name,
std::vector< T > &  value 
)

Definition at line 655 of file H5.h.

References ASSERTL0, Nektar::LibUtilities::H5::DataTypeTraits< T >::Deconvert(), dest, Nektar::LibUtilities::H5::DataTypeTraits< T >::GetType(), H5_CALL, Nektar::iterator, and OpenAttribute().

657 {
658  typedef std::vector<
659  typename DataTypeConversionPolicy<T>::ConvertedVectorElemType>
660  Vec;
661  Vec converted_vals;
663  AttributeSharedPtr attr = OpenAttribute(name);
664  DataSpaceSharedPtr space = attr->GetSpace();
665  ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
666  "vector data not 1D");
667  hsize_t len, maxdim;
668  H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
669 
670  value.resize(len);
671  void *converted_buf = NULL;
672  if (DataTypeConversionPolicy<T>::MustConvert)
673  {
674  converted_vals.resize(len);
675  converted_buf = &converted_vals[0];
676  }
677  else
678  {
679  converted_buf = &value[0];
680  }
681 
682  H5_CALL(H5Aread, (attr->GetId(), type->GetId(), converted_buf));
683 
684  if (DataTypeConversionPolicy<T>::MustConvert)
685  {
686  typename Vec::iterator src = converted_vals.begin(),
687  end = converted_vals.end();
688  typename std::vector<T>::iterator dest = value.begin();
689  for (; src != end; ++src, ++dest)
690  {
691  *dest = DataTypeTraits<T>::Deconvert(*src);
692  }
693  }
694 }
#define H5_CALL(func, args)
Definition: H5.h:68
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static DataTypeSharedPtr GetType()
Definition: H5.h:538
boost::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:86
boost::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:88
boost::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:92
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:564
#define dest(otri, vertexptr)
AttributeSharedPtr OpenAttribute(const std::string &name)
Definition: H5.cpp:326
int Nektar::LibUtilities::H5::CanHaveAttributes::GetNumAttr ( ) const

Definition at line 331 of file H5.cpp.

References H5_CALL.

332 {
333  H5O_info_t info;
334  H5_CALL(H5Oget_info, (m_Id, &info));
335  return info.num_attrs;
336 }
#define H5_CALL(func, args)
Definition: H5.h:68
AttributeSharedPtr Nektar::LibUtilities::H5::CanHaveAttributes::OpenAttribute ( const std::string &  name)

Definition at line 326 of file H5.cpp.

References Nektar::LibUtilities::H5::Attribute::Open().

Referenced by GetAttribute().

327 {
328  return Attribute::Open(m_Id, name);
329 }
static AttributeSharedPtr Open(hid_t parent, const std::string &name)
Definition: H5.cpp:530
template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::SetAttribute ( const std::string &  name,
const T &  value 
)

Definition at line 596 of file H5.h.

References Nektar::LibUtilities::H5::DataTypeTraits< T >::Convert(), CreateAttribute(), Nektar::LibUtilities::H5::DataTypeTraits< T >::GetAddress(), Nektar::LibUtilities::H5::DataTypeTraits< T >::GetType(), H5_CALL, and Nektar::LibUtilities::H5::DataSpace::Scalar().

597 {
600  AttributeSharedPtr attr = CreateAttribute(name, type, space);
601 
602  typename DataTypeTraits<T>::ConvertedType conv =
604  H5_CALL(
605  H5Awrite,
606  (attr->GetId(), type->GetId(), DataTypeTraits<T>::GetAddress(conv)));
607 }
#define H5_CALL(func, args)
Definition: H5.h:68
static const void * GetAddress(const ConvertedType &obj)
static DataTypeSharedPtr GetType()
Definition: H5.h:538
boost::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:86
boost::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:88
static ConvertedType Convert(const T &obj)
Definition: H5.h:557
boost::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:92
static DataSpaceSharedPtr Scalar()
Definition: H5.cpp:397
AttributeSharedPtr CreateAttribute(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:319
template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::SetAttribute ( const std::string &  name,
const std::vector< T > &  value 
)

Definition at line 610 of file H5.h.

References Nektar::LibUtilities::H5::DataTypeConversionPolicy< T >::Convert(), CreateAttribute(), Nektar::LibUtilities::H5::DataTypeTraits< T >::GetType(), H5_CALL, and Nektar::LibUtilities::H5::DataSpace::OneD().

612 {
613  typedef std::vector<
614  typename DataTypeConversionPolicy<T>::ConvertedVectorElemType>
615  Vec;
616  Vec converted_vals;
618  DataSpaceSharedPtr space = DataSpace::OneD(value.size());
619  AttributeSharedPtr attr = CreateAttribute(name, type, space);
620 
621  const void *converted_buf = NULL;
622  if (DataTypeConversionPolicy<T>::MustConvert)
623  {
624  converted_vals.resize(value.size());
625  for (size_t i = 0; i < value.size(); ++i)
626  {
627  converted_vals[i] = DataTypeConversionPolicy<T>::Convert(value[i]);
628  }
629  converted_buf = &converted_vals[0];
630  }
631  else
632  {
633  converted_buf = &value[0];
634  }
635 
636  H5_CALL(H5Awrite, (attr->GetId(), type->GetId(), converted_buf));
637 }
#define H5_CALL(func, args)
Definition: H5.h:68
static ConvertedType Convert(const T &obj)
Definition: H5.h:526
static DataTypeSharedPtr GetType()
Definition: H5.h:538
boost::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:86
boost::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:88
static DataSpaceSharedPtr OneD(hsize_t size)
Definition: H5.cpp:403
boost::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:92
AttributeSharedPtr CreateAttribute(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:319