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

Managers a set of attributes attached to an object. More...

#include <geogram/basic/attributes.h>

Public Member Functions

 AttributesManager ()
 Constructs a new empty AttributesManager.
 
 ~AttributesManager ()
 AttributesManager destructor.
 
index_t nb () const
 Gets the number of attributes. More...
 
void list_attribute_names (vector< std::string > &names) const
 Gets the names of all the attributes in this AttributeStore. More...
 
index_t size () const
 Gets the size. More...
 
index_t capacity () const
 Gets the capacity. More...
 
void resize (index_t new_size)
 Resizes all the attributes managed by this AttributesManager. More...
 
void reserve (index_t new_capacity)
 Pre-allocates memory for a number of items. More...
 
void clear (bool keep_attributes, bool keep_memory=false)
 Clears this AttributesManager. More...
 
void zero ()
 Zeroes all the attributes.
 
void bind_attribute_store (const std::string &name, AttributeStore *as)
 Binds an AttributeStore with the specified name. Ownership of this AttributeStore is transferred to the AttributesManager. More...
 
AttributeStorefind_attribute_store (const std::string &name)
 Finds an AttributeStore by name. More...
 
const AttributeStorefind_attribute_store (const std::string &name) const
 Finds an AttributeStore by name. More...
 
bool is_defined (const std::string &name) const
 Tests whether an attribute is defined. More...
 
void delete_attribute_store (const std::string &name)
 Deletes an AttributeStore by name. More...
 
void delete_attribute_store (AttributeStore *as)
 Deletes an AttributeStore. More...
 
void apply_permutation (const vector< index_t > &permutation)
 Applies a permutation to the stored attributes. More...
 
void compress (const vector< index_t > &old2new)
 Compresses the stored attributes, by applying an index mapping that fills-in the gaps. More...
 
void copy (const AttributesManager &rhs)
 Copies all the attributes from another AttributesManager. More...
 
void copy_item (index_t to, index_t from)
 Copies all the attributes of an item into another one. More...
 
void swap_items (index_t i, index_t j)
 Swaps all the attributes of two items. More...
 
void zero_item (index_t to)
 Sets an item to zero. More...
 
void scale_item (index_t to, double s)
 Scales an item. More...
 
void madd_item (index_t to, double s, index_t from)
 Adds a scaled item to another item \detais item[to] += s * item[from]. More...
 
bool copy_attribute (const std::string &name, const std::string &new_name)
 Copies an attribute. More...
 
bool rename_attribute (const std::string &old_name, const std::string &new_name)
 Renames an attribute. More...
 

Detailed Description

Managers a set of attributes attached to an object.

Definition at line 834 of file attributes.h.

Member Function Documentation

◆ apply_permutation()

void GEO::AttributesManager::apply_permutation ( const vector< index_t > &  permutation)

Applies a permutation to the stored attributes.

Applying a permutation to the data is equivalent to:

for(i=0; i<permutation.size(); i++) {
data2[i] = data[permutation[i]]
}
data = data2 ;

But it is done in-place.

Parameters
[in]permutationthe permutation. It is temporarily changed during execution of the function, but identical to the input on exit.

◆ bind_attribute_store()

void GEO::AttributesManager::bind_attribute_store ( const std::string &  name,
AttributeStore as 
)

Binds an AttributeStore with the specified name. Ownership of this AttributeStore is transferred to the AttributesManager.

Parameters
[in]namethe name
[in]asa pointer to the AttributeStore to be bound
Precondition
No AttributeStore is already bound to the same name

◆ capacity()

index_t GEO::AttributesManager::capacity ( ) const
inline

Gets the capacity.

Returns
the number of items that can be stored without doing a reallocation.

Definition at line 878 of file attributes.h.

◆ clear()

void GEO::AttributesManager::clear ( bool  keep_attributes,
bool  keep_memory = false 
)

Clears this AttributesManager.

Parameters
[in]keep_attributesif true, then all attributes are resized to 0 but their names are kept.
[in]keep_memoryif true, allocated memory is kept reserved.

◆ compress()

void GEO::AttributesManager::compress ( const vector< index_t > &  old2new)

Compresses the stored attributes, by applying an index mapping that fills-in the gaps.

This is equivalent to:

for(i=0; i<size(); i++) {
if(old2new[i] != index_t(-1)) {
data2[old2new[i]] = data[i];
}
}
data = data2 ;
index_t size() const
Gets the size.
Definition: attributes.h:869
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Parameters
[in]old2newthe index mapping to be applied.
Precondition
old2new[i] <= i || old2new[i] == index_t(-1)

◆ copy()

void GEO::AttributesManager::copy ( const AttributesManager rhs)

Copies all the attributes from another AttributesManager.

Previous content of this AttributesManager is erased.

◆ copy_attribute()

bool GEO::AttributesManager::copy_attribute ( const std::string &  name,
const std::string &  new_name 
)

Copies an attribute.

Parameters
[in]namethe attribute to copy
[in]new_namenew name of the attribute
Return values

◆ copy_item()

void GEO::AttributesManager::copy_item ( index_t  to,
index_t  from 
)

Copies all the attributes of an item into another one.

Parameters
[in]toindex of the destination item
[in]fromindex of the source item
Note
This function is not efficient.

◆ delete_attribute_store() [1/2]

void GEO::AttributesManager::delete_attribute_store ( AttributeStore as)

Deletes an AttributeStore.

Parameters
[in]asa pointer to the attribute store to be deleted.

◆ delete_attribute_store() [2/2]

void GEO::AttributesManager::delete_attribute_store ( const std::string &  name)

Deletes an AttributeStore by name.

Parameters
[in]namethe name of the attribute store to be deleted.

◆ find_attribute_store() [1/2]

AttributeStore* GEO::AttributesManager::find_attribute_store ( const std::string &  name)

Finds an AttributeStore by name.

Parameters
[in]namethe name under which the AttributeStore was bound
Returns
a pointer to the attribute store or nullptr if is is undefined.

◆ find_attribute_store() [2/2]

const AttributeStore* GEO::AttributesManager::find_attribute_store ( const std::string &  name) const

Finds an AttributeStore by name.

Parameters
[in]namethe name under which the AttributeStore was bound
Returns
a const pointer to the attribute store or nullptr if is is undefined.

◆ is_defined()

bool GEO::AttributesManager::is_defined ( const std::string &  name) const
inline

Tests whether an attribute is defined.

Parameters
[in]namename of the attribute
Return values
trueif an attribute with the specified name exists
falseotherwise

Definition at line 949 of file attributes.h.

◆ list_attribute_names()

void GEO::AttributesManager::list_attribute_names ( vector< std::string > &  names) const

Gets the names of all the attributes in this AttributeStore.

Parameters
[out]namesa vector of all attribute names

◆ madd_item()

void GEO::AttributesManager::madd_item ( index_t  to,
double  s,
index_t  from 
)

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

◆ nb()

index_t GEO::AttributesManager::nb ( ) const
inline

Gets the number of attributes.

Returns
The number of attributes managed by this AttributesManager.

Definition at line 852 of file attributes.h.

◆ rename_attribute()

bool GEO::AttributesManager::rename_attribute ( const std::string &  old_name,
const std::string &  new_name 
)

Renames an attribute.

Parameters
[in]old_namecurrent name of the attribute
[in]new_namenew name of the attribute
Return values

◆ reserve()

void GEO::AttributesManager::reserve ( index_t  new_capacity)

Pre-allocates memory for a number of items.

Has effect only if new_capacity is larger than current capacity.

Parameters
[in]new_capacitythe number of items.

◆ resize()

void GEO::AttributesManager::resize ( index_t  new_size)

Resizes all the attributes managed by this AttributesManager.

Parameters
[in]new_sizethe new number of items for all attributes.

◆ scale_item()

void GEO::AttributesManager::scale_item ( index_t  to,
double  s 
)

Scales an item.

item[to] *= s

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

default implementation does nothing

◆ size()

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

Gets the size.

All attributes stored in an AttributesManager have the same number of items.

Returns
the number of items of each attribute.

Definition at line 869 of file attributes.h.

◆ swap_items()

void GEO::AttributesManager::swap_items ( index_t  i,
index_t  j 
)

Swaps all the attributes of two items.

Parameters
[in]i,jthe indices of the two items to be swapped
Note
This function is not efficient.

◆ zero_item()

void GEO::AttributesManager::zero_item ( index_t  to)

Sets an item to zero.

Parameters
[in]toindex of the item

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