ug4
|
Handles data which has been attached to the pipe using callbacks for the element. More...
#include <attachment_pipe.h>
Public Types | |
typedef attachment_traits< TElem, TElemHandler > | atraits |
typedef std::list< AttachmentEntry > | AttachmentEntryContainer |
typedef AttachmentEntryContainer::iterator | AttachmentEntryIterator |
typedef Hash< uint, AttachmentEntryIterator > | AttachmentEntryIteratorHash |
typedef AttachmentEntryContainer::const_iterator | ConstAttachmentEntryIterator |
typedef TElem | element |
typedef TElemHandler | ElementHandler |
Public Member Functions | |
AttachmentPipe () | |
AttachmentPipe (typename atraits::ElemHandlerPtr pHandler) | |
ConstAttachmentEntryIterator | attachments_begin () const |
ConstAttachmentEntryIterator | attachments_end () const |
void | clear () |
calls both clear_elements and clear_attachments. More... | |
void | clear_attachments () |
clears registered attachments and associated data but keeps existing elements. More... | |
void | clear_elements () |
clears elements and associated data but keeps registered attachments More... | |
void | defragment () |
void | detach (IAttachment &attachment) |
Removes the data associated with the given attachment from the pipe. More... | |
template<class TAttachment > | |
TAttachment::ValueType * | get_data_array (TAttachment &attachment) |
Lets you access the raw data array associated with the given attachment. More... | |
atraits::ElemHandlerPtr | get_elem_handler () |
bool | has_attachment (IAttachment &attachment) const |
Returns true if the given attachment is currently attached to the pipe. More... | |
bool | is_fragmented () const |
Returns whether the attachment pipe is fragmented. More... | |
size_t | num_data_entries () const |
Returns the size of the associated data arrays. More... | |
size_t | num_elements () const |
Returns the number of registered elements. More... | |
void | register_element (TElem elem) |
Registers a new element at the attachment pipe. More... | |
void | reserve (size_t numElems) |
Reserves memory for element- and data-entries. More... | |
void | reset_values (size_t dataIndex) |
fills the attached data at the given index with the default values. More... | |
void | unregister_element (const TElem &elem) |
Unregisters the given element. More... | |
~AttachmentPipe () | |
template<class TAttachment > | |
void | attach (TAttachment &attachment, const typename TAttachment::ValueType &defaultValue, uint options) |
attaches a new data-array to the pipe. More... | |
void | attach (IAttachment &attachment, uint options=0) |
attaches a new data-array to the pipe. More... | |
IAttachmentDataContainer * | get_data_container (IAttachment &attachment) const |
Returns the data container managing the data array for the given attachment. More... | |
template<class TAttachment > | |
TAttachment::ContainerType * | get_data_container (TAttachment &attachment) |
Returns the data container managing the data array for the given attachment. More... | |
Protected Types | |
typedef std::stack< size_t > | UINTStack |
Protected Member Functions | |
size_t | get_container_size () |
void | grow_attachment_containers (size_t newMinSize) |
void | resize_attachment_containers (size_t newSize) |
Protected Attributes | |
AttachmentEntryContainer | m_attachmentEntryContainer |
AttachmentEntryIteratorHash | m_attachmentEntryIteratorHash |
size_t | m_containerSize |
total size of containers. More... | |
size_t | m_numDataEntries |
size_t | m_numElements |
atraits::ElemHandlerPtr | m_pHandler |
UINTStack | m_stackFreeEntries |
holds indices to free entries. More... | |
Handles data which has been attached to the pipe using callbacks for the element.
The AttachmentPipe can be used to attach data to a collection of elements. Elements have to be registered at the AttachmentPipe. Using the methods defined in the attachment_traits template class, registered elements are associated with their data-entries.
TODO: enum Options : CopyAllowed
typedef attachment_traits<TElem, TElemHandler> ug::AttachmentPipe< TElem, TElemHandler >::atraits |
typedef std::list<AttachmentEntry> ug::AttachmentPipe< TElem, TElemHandler >::AttachmentEntryContainer |
typedef AttachmentEntryContainer::iterator ug::AttachmentPipe< TElem, TElemHandler >::AttachmentEntryIterator |
typedef Hash<uint, AttachmentEntryIterator> ug::AttachmentPipe< TElem, TElemHandler >::AttachmentEntryIteratorHash |
typedef AttachmentEntryContainer::const_iterator ug::AttachmentPipe< TElem, TElemHandler >::ConstAttachmentEntryIterator |
typedef TElem ug::AttachmentPipe< TElem, TElemHandler >::element |
typedef TElemHandler ug::AttachmentPipe< TElem, TElemHandler >::ElementHandler |
|
protected |
ug::AttachmentPipe< TElem, TElemHandler >::AttachmentPipe |
ug::AttachmentPipe< TElem, TElemHandler >::AttachmentPipe | ( | typename atraits::ElemHandlerPtr | pHandler | ) |
ug::AttachmentPipe< TElem, TElemHandler >::~AttachmentPipe |
void ug::AttachmentPipe< TElem, TElemHandler >::attach | ( | IAttachment & | attachment, |
uint | options = 0 |
||
) |
attaches a new data-array to the pipe.
Attachs a new attachment and creates a container which holds the data associated with the elements through this attachment. Several overloads exist: You may pass an attachment together with a default value and with an option constant or simply the attachment together with an optional option constant. Not that in the first case the concrete type of the attachment has to be known, whereas in the second case only the interface IAttachment has to be specified.
The option constant is not used by the attachment system but may be used by a user to store a constant with each attachment.
References ug::IAttachment::clone(), ug::IAttachment::create_container(), ug::UID::id(), and ug::IAttachmentDataContainer::resize().
void ug::AttachmentPipe< TElem, TElemHandler >::attach | ( | TAttachment & | attachment, |
const typename TAttachment::ValueType & | defaultValue, | ||
uint | options | ||
) |
attaches a new data-array to the pipe.
Attachs a new attachment and creates a container which holds the data associated with the elements through this attachment. Several overloads exist: You may pass an attachment together with a default value and with an option constant or simply the attachment together with an optional option constant. Not that in the first case the concrete type of the attachment has to be known, whereas in the second case only the interface IAttachment has to be specified.
The option constant is not used by the attachment system but may be used by a user to store a constant with each attachment.
References ug::IAttachment::clone(), ug::UID::id(), and ug::IAttachmentDataContainer::resize().
|
inline |
Referenced by ug::Grid::clear_attachments(), and ug::PrintAttachmentInfo().
|
inline |
Referenced by ug::Grid::clear_attachments(), and ug::PrintAttachmentInfo().
void ug::AttachmentPipe< TElem, TElemHandler >::clear |
calls both clear_elements and clear_attachments.
References clear_attachments().
void ug::AttachmentPipe< TElem, TElemHandler >::clear_attachments |
clears registered attachments and associated data but keeps existing elements.
void ug::AttachmentPipe< TElem, TElemHandler >::clear_elements |
clears elements and associated data but keeps registered attachments
void ug::AttachmentPipe< TElem, TElemHandler >::defragment |
Aligns data with elements and removes unused data-memory.
References ug::INVALID_ATTACHMENT_INDEX.
void ug::AttachmentPipe< TElem, TElemHandler >::detach | ( | IAttachment & | attachment | ) |
Removes the data associated with the given attachment from the pipe.
References ug::UID::id().
Referenced by ug::Grid::clear_attachments().
|
inlineprotected |
TAttachment::ValueType * ug::AttachmentPipe< TElem, TElemHandler >::get_data_array | ( | TAttachment & | attachment | ) |
Lets you access the raw data array associated with the given attachment.
If you access several arrays through this method, it is guaranteed that the data associated with one specific object are found at the same indices in those arrays.
Note that if you access the data arrays after a call to defragment, then the i-th data-entry corresponds to the i-th element.
Please not that the pointer may be invalidated through the following operations:
IAttachmentDataContainer * ug::AttachmentPipe< TElem, TElemHandler >::get_data_container | ( | IAttachment & | attachment | ) | const |
Returns the data container managing the data array for the given attachment.
References ug::UID::id().
Referenced by ug::AttachmentAccessor< TElem, TAttachment, TElemHandler >::access(), and ug::AttachmentAccessor< TElem, TAttachment, TElemHandler >::AttachmentAccessor().
TAttachment::ContainerType * ug::AttachmentPipe< TElem, TElemHandler >::get_data_container | ( | TAttachment & | attachment | ) |
Returns the data container managing the data array for the given attachment.
|
inline |
|
protected |
bool ug::AttachmentPipe< TElem, TElemHandler >::has_attachment | ( | IAttachment & | attachment | ) | const |
Returns true if the given attachment is currently attached to the pipe.
References ug::UID::id().
Referenced by ug::AttachmentAccessor< TElem, TAttachment, TElemHandler >::access().
|
inline |
Returns whether the attachment pipe is fragmented.
The pipe gets fragmented whenever elements are erased. Through the creation of new elements the pipe may be automatically defragmented. Through a call to defragment() the pipe can be defragmented at any time.
|
inline |
Returns the size of the associated data arrays.
Note: If the pipe is fragmented, then num_elements and num_data_entries differ. If the pipe however isn't fragmented, then both values are the same.
Referenced by ug::Grid::edge_fragmentation(), ug::Grid::face_fragmentation(), ug::Grid::vertex_fragmentation(), and ug::Grid::volume_fragmentation().
|
inline |
Returns the number of registered elements.
Referenced by ug::Grid::edge_fragmentation(), ug::Grid::face_fragmentation(), ug::Grid::vertex_fragmentation(), and ug::Grid::volume_fragmentation().
void ug::AttachmentPipe< TElem, TElemHandler >::register_element | ( | TElem | elem | ) |
Registers a new element at the attachment pipe.
Registers the element and reserves memory for all registered attachments. Note that this method may be faster if memory has previously been reserved using reserve_new.
void ug::AttachmentPipe< TElem, TElemHandler >::reserve | ( | size_t | numElems | ) |
Reserves memory for element- and data-entries.
This method reserves memory for data and elements. Note that numElems specifies the total amount of elements for which data shall be reserved. If numElems is smaller than num_elements, then nothing will be done. Note that a call to reserve does not change num_elements nor num_data_entries.
If you want to reserve space for additional N elements, please call reserve with numElems = num_elements() + N.
Note that reserve is optional and only serves performance benefits.
void ug::AttachmentPipe< TElem, TElemHandler >::reset_values | ( | size_t | dataIndex | ) |
fills the attached data at the given index with the default values.
|
protected |
void ug::AttachmentPipe< TElem, TElemHandler >::unregister_element | ( | const TElem & | elem | ) |
Unregisters the given element.
Unregisters the given element but does not yet clear associated data. Indeed the memory is kept until defragment is called or new elements reuse the memory.
|
protected |
|
protected |
|
protected |
total size of containers.
|
protected |
|
protected |
|
protected |
|
protected |
holds indices to free entries.