Radium Engine  1.5.20
Loading...
Searching...
No Matches
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
 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.
 
template<typename T >
AttribHandle< T > findAttrib (const std::string &name) const
 findAttrib Grab an attribute handler by name.
 
template<typename T >
Attrib< T >::Container & getDataWithLock (const AttribHandle< T > &h)
 Get the locked data container from the attrib handle.
 
template<typename T >
const Attrib< T >::Container & getData (const AttribHandle< T > &h)
 Get read access to the data container from the attrib handle.
 
template<typename T >
void unlock (const AttribHandle< T > &h)
 Unlock the handle data.
 
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
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
...
}
The AttribManager provides attributes management by handles.
Definition Attribs.hpp:204
AttribHandle< T > addAttrib(const std::string &name)
Definition Attribs.hpp:711
Attrib< T > & getAttrib(const AttribHandle< T > &h)
Definition Attribs.hpp:648
bool isValid(const AttribHandle< T > &h) const
Return true if h correspond to an existing attribute in *this.
Definition Attribs.hpp:612
AttribHandle< T > findAttrib(const std::string &name) const
findAttrib Grab an attribute handler by name.
Definition Attribs.hpp:622
Warning
There is no error check on the handles attribute type.

Definition at line 203 of file Attribs.hpp.

Member Typedef Documentation

◆ Container

◆ pointer_type

◆ smart_pointer_type

◆ value_type

Constructor & Destructor Documentation

◆ AttribManager() [1/2]

Ra::Core::Utils::AttribManager::AttribManager ( )
inline

Definition at line 577 of file Attribs.hpp.

◆ AttribManager() [2/2]

Ra::Core::Utils::AttribManager::AttribManager ( AttribManager && m)
inline

Definition at line 579 of file Attribs.hpp.

◆ ~AttribManager()

Ra::Core::Utils::AttribManager::~AttribManager ( )
override

Definition at line 13 of file Attribs.cpp.

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 711 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ clear()

void Ra::Core::Utils::AttribManager::clear ( )

clear all attribs, invalidate handles.

Definition at line 17 of file Attribs.cpp.

+ 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 617 of file Attribs.hpp.

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

◆ copyAttributes() [1/2]

void Ra::Core::Utils::AttribManager::copyAttributes ( const AttribManager & m)
inline

Base copy, does nothing.

Definition at line 591 of file Attribs.hpp.

◆ copyAttributes() [2/2]

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 596 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 622 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ for_each_attrib() [1/2]

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

Definition at line 760 of file Attribs.hpp.

◆ for_each_attrib() [2/2]

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

Perform fun on each attribute.

Definition at line 754 of file Attribs.hpp.

◆ getAttrib() [1/4]

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 648 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ getAttrib() [2/4]

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

Definition at line 653 of file Attribs.hpp.

◆ getAttrib() [3/4]

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 657 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ getAttrib() [4/4]

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

Definition at line 662 of file Attribs.hpp.

◆ getAttribBase() [1/4]

AttribBase * Ra::Core::Utils::AttribManager::getAttribBase ( const Index & idx)
inline

Definition at line 700 of file Attribs.hpp.

◆ getAttribBase() [2/4]

const AttribBase * Ra::Core::Utils::AttribManager::getAttribBase ( const Index & idx) const
inline

Definition at line 705 of file Attribs.hpp.

◆ getAttribBase() [3/4]

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 688 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ getAttribBase() [4/4]

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

Definition at line 694 of file Attribs.hpp.

◆ getAttribPtr() [1/2]

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

Definition at line 667 of file Attribs.hpp.

◆ getAttribPtr() [2/2]

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

Definition at line 672 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 638 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ 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 633 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ getNumAttribs()

int Ra::Core::Utils::AttribManager::getNumAttribs ( ) const
inline

Return the number of attributes.

Definition at line 765 of file Attribs.hpp.

◆ getScopedLockState()

ScopedLockState Ra::Core::Utils::AttribManager::getScopedLockState ( )
inline

Returns a scope unlocker for managed attribs.

Definition at line 429 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.

+ Here is the call graph for this function:

◆ isValid()

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

Return true if h correspond to an existing attribute in *this.

Definition at line 612 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ operator=()

AttribManager & Ra::Core::Utils::AttribManager::operator= ( AttribManager && m)
inline

Definition at line 584 of file Attribs.hpp.

◆ 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 739 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 677 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ 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 683 of file Attribs.hpp.

+ Here is the call graph for this function:

◆ unlock()

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

Unlock the handle data.

Template Parameters
T
Parameters
h

Definition at line 643 of file Attribs.hpp.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ ::Ra::Core::Geometry::TopologicalMesh

Definition at line 440 of file Attribs.hpp.


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