2#include <Core/Containers/VectorArray.hpp>
3#include <Core/CoreMacros.hpp>
4#include <Core/RaCore.hpp>
5#include <Core/Utils/ContainerIntrospectionInterface.hpp>
6#include <Core/Utils/Index.hpp>
7#include <Core/Utils/Observable.hpp>
52 bool inline operator==(
const AttribBase& rhs );
77 bool inline isLocked()
const;
85 void inline lock(
bool isLocked =
true );
92 bool m_isLocked {
false };
102 using value_type = T;
109 void resize(
size_t s )
override;
117 size_t getSize()
const override;
121 const void*
dataPtr()
const override;
138 template <
typename U>
142 auto ptr = std::make_unique<Attrib<T>>(
getName() );
143 ptr->m_data = m_data;
156 using value_type = T;
161 template <
typename U>
167 Index
idx()
const {
return m_idx; }
174 Index m_idx = Index::Invalid();
236 template <
class T,
class... Handle>
248 template <
typename T>
257 inline bool contains(
const std::string& name )
const;
266 template <
typename T>
275 template <
typename T>
284 template <
typename T>
292 template <
typename T>
301 template <
typename T>
303 template <
typename T>
305 template <
typename T>
307 template <
typename T>
316 template <
typename T>
318 template <
typename T>
328 inline AttribBase* getAttribBase(
const Index& idx );
329 inline const AttribBase* getAttribBase(
const Index& idx )
const;
335 template <
typename T>
337 const typename AttribHandle<T>::Container& data );
340 template <
typename T>
341 inline void setAttrib(
const AttribHandle<T>& h,
typename AttribHandle<T>::Container&& data );
349 template <
typename T>
357 template <
typename T>
368 template <
typename F>
369 void for_each_attrib(
const F& func )
const;
372 template <
typename F>
373 void for_each_attrib(
const F& func );
377 inline int getNumAttribs()
const;
419 return ( v.push_back(
std::make_pair( attr, attr->isLocked() ) ) );
427 for (
auto& p : v ) {
428 if ( !p.second && p.first->isLocked() ) { p.first->unlock(); }
448 friend class ::Ra::Core::Geometry::TopologicalMesh;
451 int m_numAttribs { 0 };
454AttribBase::AttribBase(
const std::string& name ) : m_name { name } {}
465 return m_name == rhs.
getName();
475 return static_cast<const Attrib<T>&
>( *this );
486void AttribBase::lock(
bool isLocked ) {
487 CORE_ASSERT(
isLocked != m_isLocked,
"double (un)lock" );
489 if ( !m_isLocked )
notify();
514 return m_data.dataPtr();
519 CORE_ASSERT( !isLocked(),
"try to set onto locked data" );
526 CORE_ASSERT( !isLocked(),
"try to set onto locked data" );
538 return m_data.getSize();
543 return m_data.getStride();
548 return m_data.getBufferSize();
580 return m_data.getNumberOfComponents();
585AttribManager::AttribManager() {}
588 m_attribs(
std::move( m.m_attribs ) ),
589 m_attribsIndex(
std::move( m.m_attribsIndex ) ),
590 m_numAttribs(
std::move( m.m_numAttribs ) ) {}
594 m_attribsIndex =
std::move( m.m_attribsIndex );
595 m_numAttribs =
std::move( m.m_numAttribs );
600 m_numAttribs = m.m_numAttribs;
603template <
class T,
class... Handle>
606 Handle... attribs ) {
622 return h.m_idx != Index::Invalid() && itr != m_attribsIndex.
end() && itr->second == h.m_idx;
626 return m_attribsIndex.
find( name ) != m_attribsIndex.
end();
631 auto c = m_attribsIndex.
find( name );
633 if ( c != m_attribsIndex.
end() ) {
634 handle.m_idx = c->second;
635 handle.m_name = c->first;
686 const typename AttribHandle<T>::Container& data ) {
692 typename AttribHandle<T>::Container&& data ) {
697 auto c = m_attribsIndex.
find( name );
698 if ( c != m_attribsIndex.
end() )
return m_attribs[c->second].get();
703 auto c = m_attribsIndex.
find( name );
704 if ( c != m_attribsIndex.
end() )
return m_attribs[c->second].get();
709 if ( idx.isValid() )
return m_attribs[idx].get();
714 if ( idx.isValid() )
return m_attribs[idx].get();
729 m_attribs.
begin(), m_attribs.
end(), [](
const auto& attr ) { return !attr; } );
730 if ( it != m_attribs.
end() ) {
736 h.m_idx = m_attribs.
size() - 1;
738 m_attribsIndex[name] = h.m_idx;
748 auto c = m_attribsIndex.
find( h.m_name );
749 if ( c != m_attribsIndex.
end() ) {
750 Index idx = c->second;
751 m_attribs[idx].reset(
nullptr );
752 m_attribsIndex.
erase( c );
754 h.m_idx = Index::Invalid();
755 auto name = h.m_name;
763 for (
const auto& attr : m_attribs )
764 if ( attr !=
nullptr ) func( attr.get() );
769 for (
auto& attr : m_attribs )
770 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