4#include <Core/Containers/VectorArray.hpp>
5#include <Core/RaCore.hpp>
6#include <Core/Utils/ContainerIntrospectionInterface.hpp>
7#include <Core/Utils/Index.hpp>
8#include <Core/Utils/Observable.hpp>
44 bool inline operator==(
const AttribBase& rhs );
69 bool inline isLocked()
const;
77 void inline lock(
bool isLocked =
true );
84 bool m_isLocked {
false };
101 void resize(
size_t s )
override;
109 size_t getSize()
const override;
113 const void*
dataPtr()
const override;
130 template <
typename U>
134 auto ptr = std::make_unique<Attrib<T>>(
getName() );
135 ptr->m_data = m_data;
148 using value_type = T;
153 template <
typename U>
159 Index
idx()
const {
return m_idx; }
166 Index m_idx = Index::Invalid();
228 template <
class T,
class... Handle>
240 template <
typename T>
249 inline bool contains(
const std::string& name )
const;
258 template <
typename T>
267 template <
typename T>
276 template <
typename T>
284 template <
typename T>
293 template <
typename T>
295 template <
typename T>
297 template <
typename T>
299 template <
typename T>
308 template <
typename T>
310 template <
typename T>
320 inline AttribBase* getAttribBase(
const Index& idx );
321 inline const AttribBase* getAttribBase(
const Index& idx )
const;
327 template <
typename T>
329 const typename AttribHandle<T>::Container& data );
332 template <
typename T>
333 inline void setAttrib(
const AttribHandle<T>& h,
typename AttribHandle<T>::Container&& data );
341 template <
typename T>
349 template <
typename T>
360 template <
typename F>
361 void for_each_attrib(
const F& func )
const;
364 template <
typename F>
365 void for_each_attrib(
const F& func );
369 inline int getNumAttribs()
const;
411 return ( v.push_back(
std::make_pair( attr, attr->isLocked() ) ) );
419 for (
auto& p : v ) {
420 if ( !p.second && p.first->isLocked() ) { p.first->unlock(); }
440 friend class ::Ra::Core::Geometry::TopologicalMesh;
443 int m_numAttribs { 0 };
446AttribBase::AttribBase(
const std::string& name ) : m_name { name } {}
457 return m_name == rhs.
getName();
467 return static_cast<const Attrib<T>&
>( *this );
478void AttribBase::lock(
bool isLocked ) {
479 CORE_ASSERT(
isLocked != m_isLocked,
"double (un)lock" );
481 if ( !m_isLocked )
notify();
506 return m_data.dataPtr();
511 CORE_ASSERT( !isLocked(),
"try to set onto locked data" );
518 CORE_ASSERT( !isLocked(),
"try to set onto locked data" );
530 return m_data.getSize();
535 return m_data.getStride();
540 return m_data.getBufferSize();
572 return m_data.getNumberOfComponents();
577AttribManager::AttribManager() {}
580 m_attribs(
std::move( m.m_attribs ) ),
581 m_attribsIndex(
std::move( m.m_attribsIndex ) ),
582 m_numAttribs(
std::move( m.m_numAttribs ) ) {}
586 m_attribsIndex =
std::move( m.m_attribsIndex );
587 m_numAttribs =
std::move( m.m_numAttribs );
592 m_numAttribs = m.m_numAttribs;
595template <
class T,
class... Handle>
598 Handle... attribs ) {
614 return h.m_idx != Index::Invalid() && itr != m_attribsIndex.
end() && itr->second == h.m_idx;
618 return m_attribsIndex.
find( name ) != m_attribsIndex.
end();
623 auto c = m_attribsIndex.
find( name );
625 if ( c != m_attribsIndex.
end() ) {
626 handle.m_idx = c->second;
627 handle.m_name = c->first;
678 const typename AttribHandle<T>::Container& data ) {
684 typename AttribHandle<T>::Container&& data ) {
689 auto c = m_attribsIndex.
find( name );
690 if ( c != m_attribsIndex.
end() )
return m_attribs[c->second].get();
695 auto c = m_attribsIndex.
find( name );
696 if ( c != m_attribsIndex.
end() )
return m_attribs[c->second].get();
701 if ( idx.isValid() )
return m_attribs[idx].get();
706 if ( idx.isValid() )
return m_attribs[idx].get();
721 m_attribs.
begin(), m_attribs.
end(), [](
const auto& attr ) { return !attr; } );
722 if ( it != m_attribs.
end() ) {
728 h.m_idx = m_attribs.
size() - 1;
730 m_attribsIndex[name] = h.m_idx;
740 auto c = m_attribsIndex.
find( h.m_name );
741 if ( c != m_attribsIndex.
end() ) {
742 Index idx = c->second;
743 m_attribs[idx].reset(
nullptr );
744 m_attribsIndex.
erase( c );
746 h.m_idx = Index::Invalid();
747 auto name = h.m_name;
755 for (
const auto& attr : m_attribs )
756 if ( attr !=
nullptr ) func( attr.get() );
761 for (
auto& attr : m_attribs )
762 if ( attr !=
nullptr ) func( attr.get() );
virtual bool isFloat() const =0
Return true if the attribute content is of Scalar type, false otherwise.
virtual bool isVector3() const =0
Return true if the attribute content is of Vector3 type, false otherwise.
virtual bool isVector4() const =0
Return true if the attribute content is of Vector4 type, false otherwise.
virtual bool isVector2() const =0
Return true if the attribute content is of Vector2 type, false otherwise.
virtual void resize(size_t s)=0
Resize the attribute's array.
void unlock()
Unlock data so another one can gain write access.
Attrib< T > & cast()
Downcast from AttribBase to Attrib<T>.
bool operator==(const AttribBase &rhs)
Return true if *this and rhs have the same name.
std::string getName() const
Return the attribute's name.
void setName(const std::string &name)
Set the attribute's name.
An attrib handle basically store an Index and a name.
std::string attribName() const
bool operator==(const AttribHandle< U > &lhs) const
Index idx() const
return the index of the attrib.
Scope lock state management for attributes.
ScopedLockState(AttribManager *a)
Constructor, save lock state of all attribs from attribManager.
~ScopedLockState()
Destructor, unlock all attribs whose have been locked after the initialization of the Unlocker.
The AttribManager provides attributes management by handles.
void setAttrib(const AttribHandle< T > &h, const typename AttribHandle< T >::Container &data)
AttribBase * getAttribBase(const std::string &name)
int getNumAttribs() const
Return the number of attributes.
ScopedLockState getScopedLockState()
Returns a scope unlocker for managed attribs.
AttribManager(const AttribManager &m)=delete
Copy constructor and assignment operator are forbidden.
Attrib< T >::Container & getDataWithLock(const AttribHandle< T > &h)
Get the locked data container from the attrib handle.
void unlock(const AttribHandle< T > &h)
Unlock the handle data.
AttribHandle< T > addAttrib(const std::string &name)
void copyAttributes(const AttribManager &m)
Base copy, does nothing.
bool contains(const std::string &name) const
contains Check if an attribute with the given name exists.
Attrib< T > & getAttrib(const AttribHandle< T > &h)
bool isValid(const AttribHandle< T > &h) const
Return true if h correspond to an existing attribute in *this.
void removeAttrib(AttribHandle< T > &h)
void for_each_attrib(const F &func) const
const Attrib< T >::Container & getData(const AttribHandle< T > &h)
Get read access to the data container from the attrib handle.
AttribHandle< T > findAttrib(const std::string &name) const
findAttrib Grab an attribute handler by name.
size_t getSize() const override
void setData(const Container &data)
size_t getNumberOfComponents() const override
bool isType()
check if attrib is a given type, as in attr.isType<MyMatrix>()
bool isVector4() const override
Return true if the attribute content is of Vector4 type, false otherwise.
const void * dataPtr() const override
Container & getDataWithLock()
const Container & data() const
Read-only acccess to the attribute content.
bool isVector2() const override
Return true if the attribute content is of Vector2 type, false otherwise.
bool isVector3() const override
Return true if the attribute content is of Vector3 type, false otherwise.
size_t getBufferSize() const override
int getStride() const override
void resize(size_t s) override
Resize the container (value_type must have a default ctor).
bool isFloat() const override
Return true if the attribute content is of Scalar type, false otherwise.
This class defines the introspection interface a container need to implement.
void notify(Args... p) const
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet