Geogram  Version 1.9.1
A programming library of geometric algorithms
GEO::ScalarAttributeAdapterBase Class Reference

Access to an attribute as a double regardless its type. More...

#include <geogram/basic/attributes.h>

Inheritance diagram for GEO::ScalarAttributeAdapterBase:
GEO::AttributeStoreObserver GEO::ReadOnlyScalarAttributeAdapter GEO::ReadWriteScalarAttributeAdapter

Classes

class  Accessor
 Accessor class used by ScalarAttributeAdapter to implement indexing operator. More...
 
class  ConstAccessor
 Accessor class used by ScalarAttributeAdapter to implement indexing operator (const version). More...
 

Public Types

enum  ElementType {
  ET_NONE =0 , ET_UINT8 =1 , ET_INT8 =2 , ET_UINT32 =3 ,
  ET_INT32 =4 , ET_FLOAT32 =5 , ET_FLOAT64 =6 , ET_VEC2 =7 ,
  ET_VEC3 =8
}
 Internal representation of the attribute.
 

Public Member Functions

 ScalarAttributeAdapterBase ()
 ScalarAttributeAdapterBase constructor.
 
 ScalarAttributeAdapterBase (const AttributesManager &manager, const std::string &name)
 ScalarAttributeAdapterBase constructor. More...
 
bool is_bound () const
 Tests whether an Attribute is bound. More...
 
void unbind ()
 Unbinds this Attribute. More...
 
void bind_if_is_defined (const AttributesManager &manager, const std::string &name)
 Binds this Attribute to an AttributesManager if it already exists in the AttributesManager. More...
 
 ~ScalarAttributeAdapterBase ()
 ReadonlyScalarAttributeAdapterBase destructor. More...
 
index_t size () const
 Gets the size. More...
 
ElementType element_type () const
 Gets the internal representation of the elements. More...
 
index_t element_index () const
 Gets the element index. More...
 
const AttributeStoreattribute_store () const
 Gets the AttributeStore. More...
 
- Public Member Functions inherited from GEO::AttributeStoreObserver
 AttributeStoreObserver ()
 Creates a new uninitialied AttributeStore.
 
void notify (Memory::pointer base_addr, index_t size, index_t dim)
 Callback function, called by the AttributeStore whenever it is modified. More...
 
index_t size () const
 Gets the size. More...
 
index_t dimension () const
 Gets the dimension. More...
 
index_t nb_elements () const
 Gets the total number of elements. More...
 
void register_me (AttributeStore *store)
 Registers this observer to an AttributeStore. More...
 
void unregister_me (AttributeStore *store)
 Unregisters this observer from an AttributeStore. More...
 
void disconnect ()
 Disconnects this AttributeStoreObserver from its AttributeStore. More...
 

Static Public Member Functions

static bool is_defined (const AttributesManager &manager, const std::string &name)
 Tests whether an attribute with the specified name and with a type that can be converted to double exists in an AttributesManager. More...
 
static bool can_be_bound_to (const AttributeStore *store)
 Tests whether a ScalarAttributeAdapterBase can be bound to a given attribute store. More...
 
static index_t nb_scalar_elements_per_item (const AttributeStore *store)
 Gets the number of scalar components per item in an AttributeStore. More...
 

Protected Member Functions

double get_element_as_double (index_t i) const
 Gets an attribute value. More...
 
template<class T >
get_element (index_t i, index_t multiplier=1) const
 Gets an element. More...
 
double set_element_as_double (index_t i, double value)
 Sets an attribute value. More...
 
template<class T >
void set_element (T value, index_t i, index_t multiplier=1) const
 Sets an element. More...
 

Static Protected Member Functions

static std::string attribute_base_name (const std::string &name)
 Gets the base attribute name from a compound name. More...
 
static index_t attribute_element_index (const std::string &name)
 Gets the base attribute name from a compound name. More...
 
static ElementType element_type (const AttributeStore *store)
 Gets the element type stored in an AttributeStore. More...
 

Protected Attributes

const AttributesManagermanager_
 
const AttributeStorestore_
 
ElementType element_type_
 
index_t element_index_
 
- Protected Attributes inherited from GEO::AttributeStoreObserver
Memory::pointer base_addr_
 
index_t size_
 
index_t dimension_
 
bool disconnected_
 

Detailed Description

Access to an attribute as a double regardless its type.

The attribute can be an element of a vector attribute.

Definition at line 1709 of file attributes.h.

Constructor & Destructor Documentation

◆ ScalarAttributeAdapterBase()

GEO::ScalarAttributeAdapterBase::ScalarAttributeAdapterBase ( const AttributesManager manager,
const std::string &  name 
)
inline

ScalarAttributeAdapterBase constructor.

Retrieves a persistent attribute attached to a given AttributesManager.

Parameters
[in]managera reference to the AttributesManager
[in]namename of the attribute with an optional index, for instance, "foobar[5]" refers to the 5th coordinate of the "foobar" vector attribute.

Definition at line 1794 of file attributes.h.

◆ ~ScalarAttributeAdapterBase()

GEO::ScalarAttributeAdapterBase::~ScalarAttributeAdapterBase ( )
inline

ReadonlyScalarAttributeAdapterBase destructor.

The attribute is not destroyed, it can be retrieved later by binding with the same name. To destroy the attribute, use destroy() instead.

Definition at line 1844 of file attributes.h.

Member Function Documentation

◆ attribute_base_name()

static std::string GEO::ScalarAttributeAdapterBase::attribute_base_name ( const std::string &  name)
staticprotected

Gets the base attribute name from a compound name.

Parameters
[in]namethe string with the attribute name and optional index. For instance, "foobar[5]" refers to the 5th coordinate of the "foobar" vector attribute.
Returns
the attribute name. For instance, for "foobar[5]", it returns "foobar".

◆ attribute_element_index()

static index_t GEO::ScalarAttributeAdapterBase::attribute_element_index ( const std::string &  name)
staticprotected

Gets the base attribute name from a compound name.

Parameters
[in]namethe string with the attribute name and optional index. For instance, "foobar[5]" refers to the 5th coordinate of the "foobar" vector attribute.
Returns
the index or zero if no index was specified. For instance, for "foobar[5]" it returns 5, and for "foobar" it returns 0

◆ attribute_store()

const AttributeStore* GEO::ScalarAttributeAdapterBase::attribute_store ( ) const
inline

Gets the AttributeStore.

Returns
a const pointer to the AttributeStore.

Definition at line 1896 of file attributes.h.

◆ bind_if_is_defined()

void GEO::ScalarAttributeAdapterBase::bind_if_is_defined ( const AttributesManager manager,
const std::string &  name 
)

Binds this Attribute to an AttributesManager if it already exists in the AttributesManager.

Parameters
[in]managera reference to the AttributesManager
[in]namename of the attribute with an optional index, for instance, "foobar[5]" refers to the 5th coordinate of the "foobar" vector attribute.
Precondition
!is_bound()

◆ can_be_bound_to()

static bool GEO::ScalarAttributeAdapterBase::can_be_bound_to ( const AttributeStore store)
inlinestatic

Tests whether a ScalarAttributeAdapterBase can be bound to a given attribute store.

Parameters
[in]storea pointer to the attribute store.
Return values
trueif it can be bound
falseotherwise

Definition at line 1908 of file attributes.h.

◆ element_index()

index_t GEO::ScalarAttributeAdapterBase::element_index ( ) const
inline

Gets the element index.

Returns
the index of the elements accessed in the bound attribute, or 0 if the bound attribute is scalar.

Definition at line 1888 of file attributes.h.

◆ element_type() [1/2]

ElementType GEO::ScalarAttributeAdapterBase::element_type ( ) const
inline

Gets the internal representation of the elements.

Returns
one of ET_NONE (if unbound), ET_UINT8, ET_INT8, ET_UINT32, ET_INT32, ET_FLOAT32, ET_FLOAT64, ET_VEC2, ET_VEC3

Definition at line 1878 of file attributes.h.

◆ element_type() [2/2]

static ElementType GEO::ScalarAttributeAdapterBase::element_type ( const AttributeStore store)
staticprotected

Gets the element type stored in an AttributeStore.

Parameters
[in]storea const pointer to the AttributeStore
Returns
one of ET_UINT8, ET_INT8, ET_UINT32, ET_INT32, ET_FLOAT32, ET_FLOAT64 if the type of the attribute is compatible with those types, or ET_NONE if it is incompatible.

◆ get_element()

template<class T >
T GEO::ScalarAttributeAdapterBase::get_element ( index_t  i,
index_t  multiplier = 1 
) const
inlineprotected

Gets an element.

Stored element type needs to match T, no verification is made

Parameters
[in]iindex of the element
[in]multipliermultiplier applied to the index before fetching the raw pointer.

Definition at line 1999 of file attributes.h.

◆ get_element_as_double()

double GEO::ScalarAttributeAdapterBase::get_element_as_double ( index_t  i) const
inlineprotected

Gets an attribute value.

Parameters
[in]ithe index of the item
Returns
the value of the property, convertex into a double
Precondition
is_bound() && i < size()

Definition at line 1958 of file attributes.h.

◆ is_bound()

bool GEO::ScalarAttributeAdapterBase::is_bound ( ) const
inline

Tests whether an Attribute is bound.

Return values
trueif this Attribute is bound
falseotherwise

Definition at line 1807 of file attributes.h.

◆ is_defined()

static bool GEO::ScalarAttributeAdapterBase::is_defined ( const AttributesManager manager,
const std::string &  name 
)
static

Tests whether an attribute with the specified name and with a type that can be converted to double exists in an AttributesManager.

Parameters
[in]managera reference to the AttributesManager
[in]namethe name of the attribute with an optional index, for instance, "foobar[5]" refers to the 5th coordinate of the "foobar" vector attribute.

◆ nb_scalar_elements_per_item()

static index_t GEO::ScalarAttributeAdapterBase::nb_scalar_elements_per_item ( const AttributeStore store)
static

Gets the number of scalar components per item in an AttributeStore.

Parameters
[in]storea pointer to the attribute store.
Returns
the number of scalar components per item in an AttributeStore.

◆ set_element()

template<class T >
void GEO::ScalarAttributeAdapterBase::set_element ( value,
index_t  i,
index_t  multiplier = 1 
) const
inlineprotected

Sets an element.

Stored element type needs to match T, no verification is made

Parameters
[in]valuethe value of the element to be stored
[in]iindex of the element
[in]multipliermultiplier applied to the index before fetching the raw pointer.

Definition at line 2056 of file attributes.h.

◆ set_element_as_double()

double GEO::ScalarAttributeAdapterBase::set_element_as_double ( index_t  i,
double  value 
)
inlineprotected

Sets an attribute value.

Parameters
[in]ithe index of the element
[in]valuethe new value of the element
Precondition
is_bound() && i < size()

Definition at line 2014 of file attributes.h.

◆ size()

index_t GEO::ScalarAttributeAdapterBase::size ( ) const
inline

Gets the size.

Returns
The number of items in this attribute.

Definition at line 1867 of file attributes.h.

◆ unbind()

void GEO::ScalarAttributeAdapterBase::unbind ( )
inline

Unbinds this Attribute.

Precondition
is_bound()

Definition at line 1815 of file attributes.h.


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