The Vish Visualization Shell 0.3
Vish
MemCore::Attributes Class Reference

Attributes are a selection of named MemCore::ChunkBase objects, each of them may carry arbitrary data. More...

#include <elementary/memcore/Attributes.hpp>

Inheritance diagram for MemCore::Attributes:
MemCore::LoaderBase MemCore::LoaderParameters Wizt::ApplicationProperties MemCore::Loader< X >

Classes

struct  Iterator
 Attribute iterator base class. More...

Public Member Functions

 Attributes ()
 Default constructor.
MemCore::RefPtr< MemCore::ChunkBase > getAttribute (const std::string &name) const
 get an attribute by name
const Ageable & getAttributeAge () const
 Get the age of these attributes.
template<class T>
std::pair< bool, T > getAttributeValue (const string &AttributeName, size_t ElementNumber=0) const
 Get a single value from an attribute, use structured binding for most compact syntax such as:
attributes_t & getAttributeValues ()
 allow direct access to internal map
const attributes_t & getAttributeValues () const
 allow direct access to internal map
size_t getNumberOfAttributes () const
 Retrieve the number of attributes.
bool hasAttribute (const std::string &name) const
 Check if an attribute exists.
template<class Functor>
int Iterate (const Functor &L) const
int iterate (Iterator &it) const
 Iterate over attributes and apply iterator's apply function for each attribute, i.e.
template<class Functor>
int iterate_attributes (const Functor &L) const
size_t NumberOfAttributes () const
 Retrieve the number of attributes.
void setAttribute (const std::string &name, const MemCore::RefPtr< MemCore::ChunkBase > &AttribData)
 set an attribute
template<class T>
ResizableChunk< T > & setAttributeValue (const std::string &name, const T &AttribData)
 set a single attribute
template<class T>
ResizableChunk< T > & setAttributeValues (const std::string &name, const std::initializer_list< T > &AttribData)
 set an attribute
template<class T>
const T & setValue (const T &AttribData, const std::string &name)
 Convenience function: set an single attribute, return the value itself.
template<class T>
const T & setValue (const T &AttribData, const std::string &name, const std::string &Comment, const std::string &CommentPrefix="Comment")
 Convenience function: set an single attribute with a comment, return the value itself.
string toString () const
 Convert attributes to string.
const Ageable & touchAttributes () const
 Touch the attribute age to indicate some values in the attributes have been changed.
const Ageable & updateAttributeAge (const Ageable &A) const
 Update the attribute age to another age to indicate some values in the attributes have been changed.
 ~Attributes ()
 Destructor.

Detailed Description

Attributes are a selection of named MemCore::ChunkBase objects, each of them may carry arbitrary data.

The Attributes class supports the '<<' streaming operator to set attributes. To set an attribute of type double named "value" the following syntax can be used:

A << "value" << 3.141593;
Attributes are a selection of named MemCore::ChunkBase objects, each of them may carry arbitrary data...
Definition Attributes.hpp:45

An attribute can contain multiple values in the form of an array. They are stored as a Chunk<>, but for initialization via the streaming operator multiple variants are possible, including the usage of a std::initializer_list :

// Bind an initializer list to an auto definition:
auto i = {1,3,5};
A << "alpha" << i;
// Explicit usage of a std_initializer list:
A << "alpha" << std::initializer_list<int>( {1,3,5} );
// Dynamic addition of values using push_back()
// Note that this variant is least favorable as it
// requires memory re-allocation.
A << "alpha" << 1 << 2 << 3;

Member Function Documentation

◆ getAttributeValue()

template<class T>
std::pair< bool, T > MemCore::Attributes::getAttributeValue ( const string & AttributeName,
size_t ElementNumber = 0 ) const
inline

Get a single value from an attribute, use structured binding for most compact syntax such as:

if (auto [valid, value] = Container.getAttributeValue<double>("AttributeName"); valid )
{
... do something with value ...
}

References getAttribute().

◆ hasAttribute()

bool MemCore::Attributes::hasAttribute ( const std::string & name) const

Check if an attribute exists.

This function will return true even if no data are associated with an attribute.

References getAttribute().

◆ Iterate()

template<class Functor>
int MemCore::Attributes::Iterate ( const Functor & L) const
inline
       Lambda iterator, functor must provide signatur
bool operator()( const std::string& attribute_name,
StrongPtr< Object, ObjectBase > RefPtr
Convenience template typedef to use RefPtr instead of StrongPtr.
Definition RefPtr.hpp:776

Referenced by iterate_attributes().

◆ iterate()

int MemCore::Attributes::iterate ( Attributes::Iterator & it) const

Iterate over attributes and apply iterator's apply function for each attribute, i.e.

its name and its chunk.

◆ iterate_attributes()

template<class Functor>
int MemCore::Attributes::iterate_attributes ( const Functor & L) const
inline
       Lambda iterator, functor must provide signatur
bool operator()( const std::string& attribute_name,

References Iterate().