Nektar++
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:
[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
void Close ()
 
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 ()
 
virtual void v_Close ()=0
 
- 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 259 of file H5.h.

Member Function Documentation

◆ attr_begin()

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

Definition at line 346 of file H5.cpp.

347{
348 // Have to use dynamic because of virtual inheritance
350 std::dynamic_pointer_cast<CanHaveAttributes>(shared_from_this());
351 return CanHaveAttributes::AttrIterator(thisSh);
352}
std::shared_ptr< CanHaveAttributes > CanHaveAttributesSharedPtr
Definition: H5.h:80

◆ attr_end()

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

Definition at line 353 of file H5.cpp.

354{
355 // Have to use dynamic because of virtual inheritance
357 std::dynamic_pointer_cast<CanHaveAttributes>(shared_from_this());
358 return CanHaveAttributes::AttrIterator(thisSh, GetNumAttr());
359}

◆ CreateAttribute()

AttributeSharedPtr Nektar::LibUtilities::H5::CanHaveAttributes::CreateAttribute ( const std::string &  name,
DataTypeSharedPtr  type,
DataSpaceSharedPtr  space 
)

Definition at line 327 of file H5.cpp.

330{
331 return Attribute::Create(m_Id, name, type, space);
332}
static AttributeSharedPtr Create(hid_t parent, const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:591

References Nektar::LibUtilities::H5::Attribute::Create(), Nektar::LibUtilities::H5::Object::m_Id, and CellMLToNektar.pycml::name.

Referenced by SetAttribute().

◆ GetAttribute() [1/2]

template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::GetAttribute ( const std::string &  name,
std::vector< T > &  value 
)

Definition at line 776 of file H5.h.

778{
779 typedef std::vector<
781 Vec;
782 Vec converted_vals;
785 DataSpaceSharedPtr space = attr->GetSpace();
786 ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
787 "vector data not 1D");
788 hsize_t len, maxdim;
789 H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
790
791 value.resize(len);
792 void *converted_buf = nullptr;
794 {
795 converted_vals.resize(len);
796 converted_buf = &converted_vals[0];
797 }
798 else
799 {
800 converted_buf = &value[0];
801 }
802
803 H5_CALL(H5Aread, (attr->GetId(), type->GetId(), converted_buf));
804
806 {
807 typename Vec::iterator src = converted_vals.begin(),
808 end = converted_vals.end();
809 typename std::vector<T>::iterator dest = value.begin();
810 for (; src != end; ++src, ++dest)
811 {
812 *dest = DataTypeTraits<T>::Deconvert(*src);
813 }
814 }
815}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#define H5_CALL(func, args)
Definition: H5.h:58
AttributeSharedPtr OpenAttribute(const std::string &name)
Definition: H5.cpp:334
std::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:78
std::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:74
std::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:82
static DataTypeSharedPtr GetType()
Definition: H5.h:661
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:687

References ASSERTL0, Nektar::LibUtilities::H5::DataTypeTraits< T >::Deconvert(), Nektar::LibUtilities::H5::DataTypeTraits< T >::GetType(), H5_CALL, CellMLToNektar.pycml::name, and OpenAttribute().

◆ GetAttribute() [2/2]

template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::GetAttribute ( const std::string &  name,
T &  value 
)

◆ GetNumAttr()

int Nektar::LibUtilities::H5::CanHaveAttributes::GetNumAttr ( ) const

Definition at line 339 of file H5.cpp.

340{
341 H5O_info_t info;
342 H5_CALL(H5Oget_info, (m_Id, &info));
343 return info.num_attrs;
344}

References H5_CALL, and Nektar::LibUtilities::H5::Object::m_Id.

◆ OpenAttribute()

AttributeSharedPtr Nektar::LibUtilities::H5::CanHaveAttributes::OpenAttribute ( const std::string &  name)

Definition at line 334 of file H5.cpp.

335{
336 return Attribute::Open(m_Id, name);
337}
static AttributeSharedPtr Open(hid_t parent, const std::string &name)
Definition: H5.cpp:602

References Nektar::LibUtilities::H5::Object::m_Id, CellMLToNektar.pycml::name, and Nektar::LibUtilities::H5::Attribute::Open().

Referenced by GetAttribute().

◆ SetAttribute() [1/2]

template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::SetAttribute ( const std::string &  name,
const std::vector< T > &  value 
)

Definition at line 732 of file H5.h.

734{
735 typedef std::vector<
737 Vec;
738 Vec converted_vals;
740 DataSpaceSharedPtr space = DataSpace::OneD(value.size());
741 AttributeSharedPtr attr = CreateAttribute(name, type, space);
742
743 const void *converted_buf = nullptr;
745 {
746 converted_vals.resize(value.size());
747 for (size_t i = 0; i < value.size(); ++i)
748 {
749 converted_vals[i] = DataTypeConversionPolicy<T>::Convert(value[i]);
750 }
751 converted_buf = &converted_vals[0];
752 }
753 else
754 {
755 converted_buf = &value[0];
756 }
757
758 H5_CALL(H5Awrite, (attr->GetId(), type->GetId(), converted_buf));
759}
AttributeSharedPtr CreateAttribute(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:327
static DataSpaceSharedPtr OneD(hsize_t size)
Definition: H5.cpp:411
static ConvertedType Convert(const T &obj)
Definition: H5.h:649

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

◆ SetAttribute() [2/2]

template<typename T >
void Nektar::LibUtilities::H5::CanHaveAttributes::SetAttribute ( const std::string &  name,
const T &  value 
)