Radium Engine  1.5.0
Ra::Core::Utils::AttribManager Class Reference

The AttribManager provides attributes management by handles. More...

#include <Core/Utils/Attribs.hpp>

+ Inheritance diagram for Ra::Core::Utils::AttribManager:
+ Collaboration diagram for Ra::Core::Utils::AttribManager:

Classes

class  ScopedLockState
 Scope lock state management for attributes. More...
 

Public Types

using value_type = AttribBase
 
using pointer_type = value_type *
 
using smart_pointer_type = std::unique_ptr< value_type >
 
using Container = std::vector< smart_pointer_type >
 
- Public Types inherited from Ra::Core::Utils::Observable< const std::string & >
using Observer = std::function< void(Args...)>
 Observer functor type.
 

Public Member Functions

 AttribManager (const AttribManager &m)=delete
 Copy constructor and assignment operator are forbidden.
 
AttribManageroperator= (const AttribManager &m)=delete
 
 AttribManager (AttribManager &&m)
 
AttribManageroperator= (AttribManager &&m)
 
void copyAttributes (const AttribManager &m)
 Base copy, does nothing.
 
template<class T , class... Handle>
void copyAttributes (const AttribManager &m, const AttribHandle< T > &attr, Handle... attribs)
 
void copyAllAttributes (const AttribManager &m)
 
void clear ()
 clear all attribs, invalidate handles.
 
template<typename T >
bool isValid (const AttribHandle< T > &h) const
 Return true if h correspond to an existing attribute in *this.
 
bool contains (const std::string &name) const
 contains Check if an attribute with the given name exists. More...
 
template<typename T >
AttribHandle< T > findAttrib (const std::string &name) const
 findAttrib Grab an attribute handler by name. More...
 
template<typename T >
Attrib< T >::Container & getDataWithLock (const AttribHandle< T > &h)
 Get the locked data container from the attrib handle. More...
 
template<typename T >
const Attrib< T >::Container & getData (const AttribHandle< T > &h)
 Get read access to the data container from the attrib handle. More...
 
template<typename T >
void unlock (const AttribHandle< T > &h)
 Unlock the handle data. More...
 
template<typename T >
AttribHandle< T > addAttrib (const std::string &name)
 
template<typename T >
void removeAttrib (AttribHandle< T > &h)
 
bool hasSameAttribs (const AttribManager &other)
 
int getNumAttribs () const
 Return the number of attributes.
 
ScopedLockState getScopedLockState ()
 Returns a scope unlocker for managed attribs.
 
template<typename T >
Attrib< T > & getAttrib (const AttribHandle< T > &h)
 
template<typename T >
const Attrib< T > & getAttrib (const AttribHandle< T > &h) const
 
template<typename T >
Attrib< T > * getAttribPtr (const AttribHandle< T > &h)
 
template<typename T >
const Attrib< T > * getAttribPtr (const AttribHandle< T > &h) const
 
template<typename T >
Attrib< T > & getAttrib (const std::string &name)
 
template<typename T >
const Attrib< T > & getAttrib (const std::string &name) const
 
AttribBasegetAttribBase (const std::string &name)
 
const AttribBasegetAttribBase (const std::string &name) const
 
AttribBasegetAttribBase (const Index &idx)
 
const AttribBasegetAttribBase (const Index &idx) const
 
template<typename T >
void setAttrib (const AttribHandle< T > &h, const typename AttribHandle< T >::Container &data)
 
template<typename T >
void setAttrib (const AttribHandle< T > &h, typename AttribHandle< T >::Container &&data)
 
template<typename F >
void for_each_attrib (const F &func) const
 
template<typename F >
void for_each_attrib (const F &func)
 
- Public Member Functions inherited from Ra::Core::Utils::Observable< const std::string & >
 Observable ()=default
 Default constructor ... do nothing ;)
 
 Observable (const Observable &)=delete
 
Observableoperator= (const Observable &)=delete
 
void copyObserversTo (Observable &other) const
 explicit copy of all attached observers the other Observable
 
int attach (Observer observer)
 
int attachMember (T *object, void(T::*observer)(Args...))
 
void notify (Args... p) const
 Notify (i.e. call) each attached observer with argument p.
 
void detachAll ()
 Detach all observers.
 
void detach (int observerId)
 

Friends

class ::Ra::Core::Geometry::TopologicalMesh
 

Detailed Description

The AttribManager provides attributes management by handles.

The AttribManager stores a container of AttribBase *, which can be accessed (getAttrib) and deleted (removeAttrib) using a AttribHandle. Handles are created from an attribute name using addAttrib, and retrieved using findAttrib.

Example of typical use case:

// somewhere: creation
AttribManager mng;
auto inputfattrib = mng.addAttrib<Scalar>("MyAttrib");
...
// somewhere else: access
auto iattribhandler = mng.findAttrib<Scalar>("MyAttrib"); // iattribhandler == inputfattrib
if ( mng.isValid( iattribhandler ) ) { // true
auto &attrib = mng.getAttrib( iattribhandler );
...
}
auto& iattribhandler = mng.findAttrib<Scalar>("InvalidAttrib"); // invalid
if ( mng.isValid( iattribhandler ) ) { // false
...
}
Warning
There is no error check on the handles attribute type.

Definition at line 203 of file Attribs.hpp.

Member Function Documentation

◆ addAttrib()

template<typename T >
AttribHandle< T > Ra::Core::Utils::AttribManager::addAttrib ( const std::string &  name)

Add attribute by name. notify(name) is called to trigger the observers

Note
If an attribute with the same name already exists, just returns a AttribHandle to it.
Complexity:
\( O(n) \)

Definition at line 712 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ contains()

bool Ra::Core::Utils::AttribManager::contains ( const std::string &  name) const
inline

contains Check if an attribute with the given name exists.

Parameters
nameName of the attribute.
Warning
There is no error check on the attribute type.
Complexity:
\( O(\log(n)) \)

Definition at line 618 of file Attribs.hpp.

◆ copyAllAttributes()

void Ra::Core::Utils::AttribManager::copyAllAttributes ( const AttribManager m)

Copy all attributes from m.

Note
If some attrib already exists, it will be replaced.
Todo:
allow to copy all attributes, even those with non-standard type

Definition at line 23 of file Attribs.cpp.

◆ copyAttributes()

template<class T , class... Handle>
void Ra::Core::Utils::AttribManager::copyAttributes ( const AttribManager m,
const AttribHandle< T > &  attr,
Handle...  attribs 
)

Copy the given attributes from m.

Note
If some attrib already exists, it will be replaced.
Invalid handles are ignored.

Definition at line 597 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ findAttrib()

template<typename T >
AttribHandle< T > Ra::Core::Utils::AttribManager::findAttrib ( const std::string &  name) const
inline

findAttrib Grab an attribute handler by name.

Parameters
nameName of the attribute.
Returns
Attribute handler if found, an invalid handler otherwise.
Warning
There is no error check on the attribute type.
Complexity:
\( O(\log(n)) \)

Definition at line 623 of file Attribs.hpp.

◆ for_each_attrib()

template<typename F >
void Ra::Core::Utils::AttribManager::for_each_attrib ( const F &  func) const

Perform fun on each attribute.

Definition at line 755 of file Attribs.hpp.

◆ getAttrib() [1/2]

template<typename T >
Attrib< T > & Ra::Core::Utils::AttribManager::getAttrib ( const AttribHandle< T > &  h)
inline

Get attribute by handle.

Complexity:
\( O(1) \)
Warning
There is no check on the handle validity. Attrib is statically cast to T without other checks.

Definition at line 649 of file Attribs.hpp.

◆ getAttrib() [2/2]

template<typename T >
Attrib< T > & Ra::Core::Utils::AttribManager::getAttrib ( const std::string &  name)
inline

Get attribute by name. First search name to index correpondance

Complexity:
\( O(getNumAttribs()) \)
Warning
There is no check on the name validity. Attrib is statically cast to T without other checks.

Definition at line 658 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ getAttribBase()

AttribBase * Ra::Core::Utils::AttribManager::getAttribBase ( const std::string &  name)
inline

Return a AttribBase ptr to the attrib identified by name. to give access to AttribBase method, regardless of the type of element stored in the attrib.

Definition at line 689 of file Attribs.hpp.

◆ getData()

template<typename T >
const Attrib< T >::Container & Ra::Core::Utils::AttribManager::getData ( const AttribHandle< T > &  h)

Get read access to the data container from the attrib handle.

Template Parameters
TThe type of the attribute data
Parameters
hthe attribute handle
Returns
the attribute's data container

Definition at line 639 of file Attribs.hpp.

◆ getDataWithLock()

template<typename T >
Attrib< T >::Container & Ra::Core::Utils::AttribManager::getDataWithLock ( const AttribHandle< T > &  h)

Get the locked data container from the attrib handle.

Template Parameters
TThe type of the attribute data
Parameters
hthe attribute handle
Returns
the attribute's data container

Definition at line 634 of file Attribs.hpp.

◆ hasSameAttribs()

bool Ra::Core::Utils::AttribManager::hasSameAttribs ( const AttribManager other)

Return true if *this and other have the same attributes, same amount and same names.

Warning
There is no check on the attribute type nor data.

Definition at line 33 of file Attribs.cpp.

◆ removeAttrib()

template<typename T >
void Ra::Core::Utils::AttribManager::removeAttrib ( AttribHandle< T > &  h)

Remove attribute by handle, invalidates the handle. notify(name) is called to trigger the observers

Warning
If a new attribute is added, old invalidated handles may lead to the new attribute.
Complexity:
\( O(\log(n)) \)

Definition at line 740 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ setAttrib() [1/2]

template<typename T >
void Ra::Core::Utils::AttribManager::setAttrib ( const AttribHandle< T > &  h,
const typename AttribHandle< T >::Container &  data 
)
inline

Set the data of the attrib h.

Warning
h has to be a valid attrib handle, this is not checked.

Definition at line 678 of file Attribs.hpp.

◆ setAttrib() [2/2]

template<typename T >
void Ra::Core::Utils::AttribManager::setAttrib ( const AttribHandle< T > &  h,
typename AttribHandle< T >::Container &&  data 
)
inline
See also
setAttrib

Definition at line 684 of file Attribs.hpp.

◆ unlock()

template<typename T >
void Ra::Core::Utils::AttribManager::unlock ( const AttribHandle< T > &  h)

Unlock the handle data.

Template Parameters
T
Parameters
h
Returns

Definition at line 644 of file Attribs.hpp.


The documentation for this class was generated from the following files: