ug4
ug::AttachmentPipe< TElem, TElemHandler > Class Template Reference

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< AttachmentEntryAttachmentEntryContainer
 
typedef AttachmentEntryContainer::iterator AttachmentEntryIterator
 
typedef Hash< uint, AttachmentEntryIteratorAttachmentEntryIteratorHash
 
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...
 
IAttachmentDataContainerget_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...
 

Detailed Description

template<class TElem, class TElemHandler>
class ug::AttachmentPipe< TElem, TElemHandler >

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

  • copy_values(TElem from, TElem to)
  • swap_entry_indices()?!?

Member Typedef Documentation

◆ atraits

template<class TElem , class TElemHandler >
typedef attachment_traits<TElem, TElemHandler> ug::AttachmentPipe< TElem, TElemHandler >::atraits

◆ AttachmentEntryContainer

template<class TElem , class TElemHandler >
typedef std::list<AttachmentEntry> ug::AttachmentPipe< TElem, TElemHandler >::AttachmentEntryContainer

◆ AttachmentEntryIterator

template<class TElem , class TElemHandler >
typedef AttachmentEntryContainer::iterator ug::AttachmentPipe< TElem, TElemHandler >::AttachmentEntryIterator

◆ AttachmentEntryIteratorHash

template<class TElem , class TElemHandler >
typedef Hash<uint, AttachmentEntryIterator> ug::AttachmentPipe< TElem, TElemHandler >::AttachmentEntryIteratorHash

◆ ConstAttachmentEntryIterator

template<class TElem , class TElemHandler >
typedef AttachmentEntryContainer::const_iterator ug::AttachmentPipe< TElem, TElemHandler >::ConstAttachmentEntryIterator

◆ element

template<class TElem , class TElemHandler >
typedef TElem ug::AttachmentPipe< TElem, TElemHandler >::element

◆ ElementHandler

template<class TElem , class TElemHandler >
typedef TElemHandler ug::AttachmentPipe< TElem, TElemHandler >::ElementHandler

◆ UINTStack

template<class TElem , class TElemHandler >
typedef std::stack<size_t> ug::AttachmentPipe< TElem, TElemHandler >::UINTStack
protected

Constructor & Destructor Documentation

◆ AttachmentPipe() [1/2]

template<class TElem , class TElemHandler >
ug::AttachmentPipe< TElem, TElemHandler >::AttachmentPipe

◆ AttachmentPipe() [2/2]

template<class TElem , class TElemHandler >
ug::AttachmentPipe< TElem, TElemHandler >::AttachmentPipe ( typename atraits::ElemHandlerPtr  pHandler)

◆ ~AttachmentPipe()

template<class TElem , class TElemHandler >
ug::AttachmentPipe< TElem, TElemHandler >::~AttachmentPipe

Member Function Documentation

◆ attach() [1/2]

template<class TElem , class TElemHandler >
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().

◆ attach() [2/2]

template<class TElem , class TElemHandler >
template<class TAttachment >
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().

◆ attachments_begin()

template<class TElem , class TElemHandler >
ConstAttachmentEntryIterator ug::AttachmentPipe< TElem, TElemHandler >::attachments_begin ( ) const
inline

◆ attachments_end()

template<class TElem , class TElemHandler >
ConstAttachmentEntryIterator ug::AttachmentPipe< TElem, TElemHandler >::attachments_end ( ) const
inline

◆ clear()

template<class TElem , class TElemHandler >
void ug::AttachmentPipe< TElem, TElemHandler >::clear

calls both clear_elements and clear_attachments.

References clear_attachments().

◆ clear_attachments()

template<class TElem , class TElemHandler >
void ug::AttachmentPipe< TElem, TElemHandler >::clear_attachments

clears registered attachments and associated data but keeps existing elements.

◆ clear_elements()

template<class TElem , class TElemHandler >
void ug::AttachmentPipe< TElem, TElemHandler >::clear_elements

clears elements and associated data but keeps registered attachments

◆ defragment()

template<class TElem , class TElemHandler >
void ug::AttachmentPipe< TElem, TElemHandler >::defragment

Aligns data with elements and removes unused data-memory.

References ug::INVALID_ATTACHMENT_INDEX.

◆ detach()

template<class TElem , class TElemHandler >
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().

◆ get_container_size()

template<class TElem , class TElemHandler >
size_t ug::AttachmentPipe< TElem, TElemHandler >::get_container_size
inlineprotected

◆ get_data_array()

template<class TElem , class TElemHandler >
template<class TAttachment >
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:

  • register_element
  • defragment
  • clear, clear_elements, clear_attachments

◆ get_data_container() [1/2]

template<class TElem , class TElemHandler >
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().

◆ get_data_container() [2/2]

template<class TElem , class TElemHandler >
template<class TAttachment >
TAttachment::ContainerType * ug::AttachmentPipe< TElem, TElemHandler >::get_data_container ( TAttachment &  attachment)

Returns the data container managing the data array for the given attachment.

◆ get_elem_handler()

◆ grow_attachment_containers()

template<class TElem , class TElemHandler >
void ug::AttachmentPipe< TElem, TElemHandler >::grow_attachment_containers ( size_t  newMinSize)
protected

◆ has_attachment()

template<class TElem , class TElemHandler >
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().

◆ is_fragmented()

template<class TElem , class TElemHandler >
bool ug::AttachmentPipe< TElem, TElemHandler >::is_fragmented ( ) const
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.

◆ num_data_entries()

template<class TElem , class TElemHandler >
size_t ug::AttachmentPipe< TElem, TElemHandler >::num_data_entries ( ) const
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().

◆ num_elements()

template<class TElem , class TElemHandler >
size_t ug::AttachmentPipe< TElem, TElemHandler >::num_elements ( ) const
inline

◆ register_element()

template<class TElem , class TElemHandler >
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.

◆ reserve()

template<class TElem , class TElemHandler >
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.

◆ reset_values()

template<class TElem , class TElemHandler >
void ug::AttachmentPipe< TElem, TElemHandler >::reset_values ( size_t  dataIndex)

fills the attached data at the given index with the default values.

◆ resize_attachment_containers()

template<class TElem , class TElemHandler >
void ug::AttachmentPipe< TElem, TElemHandler >::resize_attachment_containers ( size_t  newSize)
protected

◆ unregister_element()

template<class TElem , class TElemHandler >
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.

Member Data Documentation

◆ m_attachmentEntryContainer

template<class TElem , class TElemHandler >
AttachmentEntryContainer ug::AttachmentPipe< TElem, TElemHandler >::m_attachmentEntryContainer
protected

◆ m_attachmentEntryIteratorHash

template<class TElem , class TElemHandler >
AttachmentEntryIteratorHash ug::AttachmentPipe< TElem, TElemHandler >::m_attachmentEntryIteratorHash
protected

◆ m_containerSize

template<class TElem , class TElemHandler >
size_t ug::AttachmentPipe< TElem, TElemHandler >::m_containerSize
protected

total size of containers.

◆ m_numDataEntries

template<class TElem , class TElemHandler >
size_t ug::AttachmentPipe< TElem, TElemHandler >::m_numDataEntries
protected

◆ m_numElements

template<class TElem , class TElemHandler >
size_t ug::AttachmentPipe< TElem, TElemHandler >::m_numElements
protected

◆ m_pHandler

template<class TElem , class TElemHandler >
atraits::ElemHandlerPtr ug::AttachmentPipe< TElem, TElemHandler >::m_pHandler
protected

◆ m_stackFreeEntries

template<class TElem , class TElemHandler >
UINTStack ug::AttachmentPipe< TElem, TElemHandler >::m_stackFreeEntries
protected

holds indices to free entries.


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