Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::TypedAttributeStore< T > Class Template Reference

Stores an array of elements of a given type, and notifies a set of AttributeStoreObservers each time the storead array changes size and/or base address. More...

#include <geogram/basic/attributes.h>

Inheritance diagram for GEO::TypedAttributeStore< T >:
GEO::AttributeStore

Public Member Functions

 TypedAttributeStore (index_t dim=1)
 Creates a new empty attribute store. More...
 
void resize (index_t new_size) override
 Resizes this AttributeStore. More...
 
void reserve (index_t new_capacity) override
 Reserves memory. More...
 
void clear (bool keep_memory=false) override
 Resizes this AttributeStore to 0. More...
 
void redim (index_t dim) override
 Sets the dimension. More...
 
bool elements_type_matches (const std::string &type_name) const override
 Tests whether this AttributeStore stores elements of a given type. More...
 
std::string element_typeid_name () const override
 Gets the typeid name of the element type stored in this AttributeStore. More...
 
AttributeStoreclone () const override
 Creates a new AttributeStore that is a carbon copy of this AttributeStore. More...
 
vector< T > & get_vector ()
 
void scale_item (index_t to, double s) override
 Scales an item. More...
 
void madd_item (index_t to, double s, index_t from) override
 Adds a scaled item to another item \detais item[to] += s * item[from]. More...
 
- Public Member Functions inherited from GEO::AttributeStore
 AttributeStore (index_t elemsize, index_t dim=1)
 AttributeStore constructor. More...
 
virtual ~AttributeStore ()
 AttributeStore destructor.
 
index_t size () const
 Gets the size. More...
 
index_t capacity () const
 Gets the capacity. More...
 
bool has_observers () const
 Tests whether observers listen to this AttributeStore. More...
 
index_t dimension () const
 Gets the dimension. More...
 
virtual void apply_permutation (const vector< index_t > &permutation)
 Applies a permutation to the stored attributes. More...
 
virtual void compress (const vector< index_t > &old2new)
 Compresses the stored attributes, by applying an index mapping that fills-in the gaps. More...
 
virtual void zero ()
 Zeroes all the memory associated with this AttributeStore. More...
 
void copy_item (index_t to, index_t from)
 Copies an item. More...
 
void zero_item (index_t to)
 Sets an item to zero. More...
 
void swap_items (index_t i, index_t j)
 Swaps two items. More...
 
void * data ()
 Gets a pointer to the stored data. More...
 
const void * data () const
 Gets a pointer to the stored data. More...
 
size_t element_size () const
 Gets the element size. More...
 

Protected Member Functions

void notify (Memory::pointer base_addr, index_t size, index_t dim) override
 If size or base address differ from the cached values, notify all the observers, and update the cached base address and size. More...
 
- Protected Member Functions inherited from GEO::AttributeStore
void register_observer (AttributeStoreObserver *observer)
 Registers an observer. More...
 
void unregister_observer (AttributeStoreObserver *observer)
 Unregisters an observer. More...
 

Static Protected Member Functions

template<class TT >
static void scale_value (TT &to, double s)
 
static void scale_value (uint8_t &to, double s)
 
static void scale_value (int32_t &to, double s)
 
static void scale_value (uint32_t &to, double s)
 
static void scale_value (float &to, double s)
 
static void scale_value (double &to, double s)
 
template<class TT >
static void madd_value (TT &to, double s, TT &from)
 
static void madd_value (uint8_t &to, double s, uint8_t &from)
 
static void madd_value (int32_t &to, double s, int32_t &from)
 
static void madd_value (uint32_t &to, double s, uint32_t &from)
 
static void madd_value (float &to, double s, float &from)
 
static void madd_value (double &to, double s, double &from)
 

Additional Inherited Members

- Static Public Member Functions inherited from GEO::AttributeStore
static bool element_type_name_is_known (const std::string &element_type_name)
 Tests whether a given element type is registered in the system. More...
 
static bool element_typeid_name_is_known (const std::string &element_typeid_name)
 Tests whether a given element type is registered in the system. More...
 
static AttributeStorecreate_attribute_store_by_element_type_name (const std::string &element_type_name, index_t dimension)
 Creates an attribute store of a given type. More...
 
static std::string element_type_name_by_element_typeid_name (const std::string &element_typeid_name)
 Gets an element type name from its mangled name. More...
 
static std::string element_typeid_name_by_element_type_name (const std::string &element_type_name)
 Gets an element mangled type name from its C++ name. More...
 
static void register_attribute_creator (AttributeStoreCreator *creator, const std::string &element_type_name, const std::string &element_typeid_name)
 Registers a new element type. More...
 
- Protected Attributes inherited from GEO::AttributeStore
index_t element_size_
 
index_t dimension_
 
Memory::pointer cached_base_addr_
 
index_t cached_size_
 
index_t cached_capacity_
 
std::set< AttributeStoreObserver * > observers_
 
Process::spinlock lock_
 
- Static Protected Attributes inherited from GEO::AttributeStore
static std::map< std::string, AttributeStoreCreator_vartype_name_to_creator_
 
static std::map< std::string, std::string > typeid_name_to_type_name_
 
static std::map< std::string, std::string > type_name_to_typeid_name_
 

Detailed Description

template<class T>
class GEO::TypedAttributeStore< T >

Stores an array of elements of a given type, and notifies a set of AttributeStoreObservers each time the storead array changes size and/or base address.

Definition at line 607 of file attributes.h.

Constructor & Destructor Documentation

◆ TypedAttributeStore()

template<class T >
GEO::TypedAttributeStore< T >::TypedAttributeStore ( index_t  dim = 1)
inline

Creates a new empty attribute store.

Parameters
[in]dimnumber of elements in each item, default value is 1, can be greater for vector attributes.

Definition at line 616 of file attributes.h.

Member Function Documentation

◆ clear()

template<class T >
void GEO::TypedAttributeStore< T >::clear ( bool  keep_memory = false)
inlineoverridevirtual

Resizes this AttributeStore to 0.

Parameters
[in]keep_memoryif true, then memory is kept reserved for future use.

Implements GEO::AttributeStore.

Definition at line 641 of file attributes.h.

◆ clone()

template<class T >
AttributeStore* GEO::TypedAttributeStore< T >::clone ( ) const
inlineoverridevirtual

Creates a new AttributeStore that is a carbon copy of this AttributeStore.

Only the data is copied, observers are not copied.

Implements GEO::AttributeStore.

Definition at line 681 of file attributes.h.

◆ element_typeid_name()

template<class T >
std::string GEO::TypedAttributeStore< T >::element_typeid_name ( ) const
inlineoverridevirtual

Gets the typeid name of the element type stored in this AttributeStore.

Returns
the typeid name, as a string.

Implements GEO::AttributeStore.

Definition at line 677 of file attributes.h.

◆ elements_type_matches()

template<class T >
bool GEO::TypedAttributeStore< T >::elements_type_matches ( const std::string &  type_name) const
inlineoverridevirtual

Tests whether this AttributeStore stores elements of a given type.

Parameters
[in]type_namethe name of the type, as given by typeid(T).name()
Return values
trueif this AttributeStore stores elements of type type_name
falseotherwise

Implements GEO::AttributeStore.

Definition at line 671 of file attributes.h.

◆ madd_item()

template<class T >
void GEO::TypedAttributeStore< T >::madd_item ( index_t  to,
double  s,
index_t  from 
)
inlineoverridevirtual

Adds a scaled item to another item \detais item[to] += s * item[from].

Parameters
[in]tothe item
[in]sthe scaling factor
[in]fromthe item to be scaled and added

default implementation does nothing

Reimplemented from GEO::AttributeStore.

Definition at line 700 of file attributes.h.

◆ notify()

template<class T >
void GEO::TypedAttributeStore< T >::notify ( Memory::pointer  base_addr,
index_t  size,
index_t  dim 
)
inlineoverrideprotectedvirtual

If size or base address differ from the cached values, notify all the observers, and update the cached base address and size.

Parameters
[in]base_addrthe new base address
[in]sizethe new size
[in]dimthe new dimension

Reimplemented from GEO::AttributeStore.

Definition at line 711 of file attributes.h.

◆ redim()

template<class T >
void GEO::TypedAttributeStore< T >::redim ( index_t  dim)
inlineoverridevirtual

Sets the dimension.

The dimension is 1 for standard attributes and can be greater for vector attributes. The existing fields are kept. If the new dimension is greater than the old one, then new fields are initialized to the default value for the attribute type.

Parameters
[in]dimthe new dimension

Implements GEO::AttributeStore.

Definition at line 651 of file attributes.h.

◆ reserve()

template<class T >
void GEO::TypedAttributeStore< T >::reserve ( index_t  new_capacity)
inlineoverridevirtual

Reserves memory.

Parameters
[in]new_capacitytotal number of items to be stored.

Implements GEO::AttributeStore.

Definition at line 629 of file attributes.h.

◆ resize()

template<class T >
void GEO::TypedAttributeStore< T >::resize ( index_t  new_size)
inlineoverridevirtual

Resizes this AttributeStore.

Parameters
[in]new_sizenew number of items

Implements GEO::AttributeStore.

Definition at line 620 of file attributes.h.

◆ scale_item()

template<class T >
void GEO::TypedAttributeStore< T >::scale_item ( index_t  to,
double  s 
)
inlineoverridevirtual

Scales an item.

item[to] *= s

Parameters
[in]tothe index of the item
[in]sthe scaling factor

default implementation does nothing

Reimplemented from GEO::AttributeStore.

Definition at line 693 of file attributes.h.


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