33 #ifndef __UTIL__ATTACHMENT_PIPE__
34 #define __UTIL__ATTACHMENT_PIPE__
52 class IAttachmentDataContainer;
76 virtual void resize(
size_t iSize) = 0;
78 virtual void copy_data(
size_t indFrom,
size_t indTo) = 0;
90 int* indexMap,
int num)
const = 0;
99 virtual void defragment(
size_t* pNewIndices,
size_t numValidElements) = 0;
110 template <
class TValue>
153 m_vData.resize(iSize, m_defaultValue);
158 virtual size_t size() {
return m_vData.size();}
160 virtual void copy_data(
size_t indFrom,
size_t indTo) {m_vData[indTo] = m_vData[indFrom];}
164 m_vData[index] = m_defaultValue;
167 virtual void defragment(
size_t* pNewIndices,
size_t numValidElements)
169 size_t numOldElems = size();
171 m_vData.resize(numValidElements);
172 for(
size_t i = 0; i < numOldElems; ++i)
174 size_t nInd = pNewIndices[i];
176 m_vData[nInd] = vDataOld[i];
190 int* indexMap,
int num)
const
193 assert(destConT &&
"Type of pDestBuf has to be the same as the"
194 "type of this buffer");
200 for(
int i = 0; i < num; ++i)
201 dest[i] = m_vData[indexMap[i]];
208 return m_vData.capacity() *
sizeof(T);
213 inline TConstRef operator[] (
size_t index)
const {
return m_vData[index];}
214 inline TRef operator[] (
size_t index) {
return m_vData[index];}
303 template<
class TElem,
class TElemHandler>
335 template<
class TElem,
class TElemHandler>
357 void clear_elements();
374 void reserve(
size_t numElems);
381 void register_element(TElem elem);
388 void unregister_element(
const TElem& elem);
407 template <
class TAttachment>
408 void attach(TAttachment& attachment,
409 const typename TAttachment::ValueType& defaultValue,
419 bool has_attachment(
IAttachment& attachment)
const;
434 template <
class TAttachment>
435 typename TAttachment::ValueType*
436 get_data_array(TAttachment& attachment);
442 template <
class TAttachment>
443 typename TAttachment::ContainerType*
444 get_data_container(TAttachment& attachment);
464 inline bool is_fragmented()
const {
return m_numElements != m_numDataEntries;}
466 void reset_values(
size_t dataIndex);
469 void resize_attachment_containers(
size_t newSize);
470 void grow_attachment_containers(
size_t newMinSize);
471 inline size_t get_container_size();
508 template <
class TElem,
class TAttachment,
class TElemHandler>
531 "ERROR in AttachmentAccessor::operator[]: accessing element with invalid attachment index!");
532 assert(m_pContainer &&
"ERROR in AttachmentAccessor::operator[]: no AttachmentPipe assigned.");
540 "ERROR in AttachmentAccessor::operator[]: accessing element with invalid attachment index!");
541 assert(m_pContainer &&
"ERROR in AttachmentAccessor::operator[]: no AttachmentPipe assigned.");
554 {
return m_pContainer != NULL;}
557 {m_pContainer = NULL;}
572 if(m_pContainer->size() > 0)
573 return &(*m_pContainer)[0];
location name
Definition: checkpoint_util.lua:128
Used to access data that has been attached to an attachment pipe.
Definition: attachment_pipe.h:510
AttachmentPipe< TElem, TElemHandler > attachment_pipe
Definition: attachment_pipe.h:518
void invalidate()
Definition: attachment_pipe.h:556
TAttachment::ContainerType ContainerType
Definition: attachment_pipe.h:515
bool valid() const
Definition: attachment_pipe.h:553
ValueType * raw_data()
returns the raw pointer to the data of the associated container
Definition: attachment_pipe.h:569
TElemHandler ElemHandler
Definition: attachment_pipe.h:516
TAttachment::ValueType ValueType
Definition: attachment_pipe.h:514
TElem element
Definition: attachment_pipe.h:513
attachment_traits< TElem, TElemHandler > atraits
Definition: attachment_pipe.h:517
TElemHandler * m_pHandler
Definition: attachment_pipe.h:588
attachment_value_traits< ValueType >::const_reference operator[](typename atraits::ConstElemPtr elem) const
Definition: attachment_pipe.h:537
ContainerType * m_pContainer
Definition: attachment_pipe.h:587
TAttachment attachment
Definition: attachment_pipe.h:512
attachment_value_traits< ValueType >::reference operator[](typename atraits::ConstElemPtr elem)
Definition: attachment_pipe.h:528
size_t element_data_index(typename atraits::ConstElemPtr elem)
returns the data index of the given element regarding the associated container.
Definition: attachment_pipe.h:581
void swap(AttachmentAccessor< TElem, TAttachment, TElemHandler > &acc)
calls swap on associated containers
Definition: attachment_pipe.h:560
A generic specialization of IAttachedDataContainer.
Definition: attachment_pipe.h:135
void swap(AttachmentDataContainer< T > &container)
swaps the buffer content of associated data
Definition: attachment_pipe.h:217
AttachmentDataContainer< T > ClassType
Definition: attachment_pipe.h:137
virtual void copy_data(size_t indFrom, size_t indTo)
copy data from entry indFrom to entry indTo.
Definition: attachment_pipe.h:160
virtual size_t size()
returns the size of the data-array.
Definition: attachment_pipe.h:158
std::vector< T > DataContainer
Definition: attachment_pipe.h:139
attachment_value_traits< T >::const_reference TConstRef
Definition: attachment_pipe.h:141
TRef get_elem(size_t index)
Definition: attachment_pipe.h:212
DataContainer m_vData
Definition: attachment_pipe.h:225
virtual ~AttachmentDataContainer()
Definition: attachment_pipe.h:148
virtual void defragment(size_t *pNewIndices, size_t numValidElements)
Definition: attachment_pipe.h:167
virtual void reset_entry(size_t index)
resets the entry to its default value.
Definition: attachment_pipe.h:162
T ValueType
Definition: attachment_pipe.h:144
AttachmentDataContainer(const T &defaultValue=T())
Definition: attachment_pipe.h:146
virtual void copy_to_container(IAttachmentDataContainer *pDestCon, int *indexMap, int num) const
Definition: attachment_pipe.h:189
attachment_value_traits< T >::reference TRef
Definition: attachment_pipe.h:140
TConstRef get_elem(size_t index) const
Definition: attachment_pipe.h:211
virtual void resize(size_t iSize)
resize the data array
Definition: attachment_pipe.h:150
T m_defaultValue
Definition: attachment_pipe.h:226
virtual size_t occupied_memory()
returns the memory occupied by the container
Definition: attachment_pipe.h:206
DataContainer & get_data_container()
Definition: attachment_pipe.h:220
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
AttachmentDataContainer< T > ContainerType
Definition: attachment_pipe.h:265
virtual IAttachmentDataContainer * create_container()
Definition: attachment_pipe.h:275
Attachment(bool passOnBehaviour)
Definition: attachment_pipe.h:269
IAttachmentDataContainer * create_container(const T &defaultValue)
Definition: attachment_pipe.h:277
Attachment(const char *name, bool passOnBehaviour)
Definition: attachment_pipe.h:271
Attachment(const char *name)
Definition: attachment_pipe.h:270
T ValueType
Definition: attachment_pipe.h:266
bool m_passOnBehaviour
Definition: attachment_pipe.h:280
virtual IAttachment * clone()
Definition: attachment_pipe.h:274
Attachment()
Definition: attachment_pipe.h:268
virtual bool default_pass_on_behaviour() const
Definition: attachment_pipe.h:276
virtual ~Attachment()
Definition: attachment_pipe.h:273
Handles data which has been attached to the pipe using callbacks for the element.
Definition: attachment_pipe.h:337
ConstAttachmentEntryIterator attachments_begin() const
Definition: attachment_pipe.h:447
AttachmentEntryIteratorHash m_attachmentEntryIteratorHash
Definition: attachment_pipe.h:478
size_t num_data_entries() const
Returns the size of the associated data arrays.
Definition: attachment_pipe.h:456
std::list< AttachmentEntry > AttachmentEntryContainer
Definition: attachment_pipe.h:341
AttachmentEntryContainer m_attachmentEntryContainer
Definition: attachment_pipe.h:477
std::stack< size_t > UINTStack
Definition: attachment_pipe.h:474
TElemHandler ElementHandler
Definition: attachment_pipe.h:340
atraits::ElemHandlerPtr m_pHandler
Definition: attachment_pipe.h:486
size_t m_containerSize
total size of containers.
Definition: attachment_pipe.h:484
ConstAttachmentEntryIterator attachments_end() const
Definition: attachment_pipe.h:448
TElem element
Definition: attachment_pipe.h:339
UINTStack m_stackFreeEntries
holds indices to free entries.
Definition: attachment_pipe.h:480
AttachmentEntryContainer::iterator AttachmentEntryIterator
Definition: attachment_pipe.h:342
size_t m_numElements
Definition: attachment_pipe.h:482
attachment_traits< TElem, TElemHandler > atraits
Definition: attachment_pipe.h:345
size_t m_numDataEntries
Definition: attachment_pipe.h:483
Hash< uint, AttachmentEntryIterator > AttachmentEntryIteratorHash
Definition: attachment_pipe.h:344
bool is_fragmented() const
Returns whether the attachment pipe is fragmented.
Definition: attachment_pipe.h:464
size_t num_elements() const
Returns the number of registered elements.
Definition: attachment_pipe.h:451
AttachmentEntryContainer::const_iterator ConstAttachmentEntryIterator
Definition: attachment_pipe.h:343
atraits::ElemHandlerPtr get_elem_handler()
Definition: attachment_pipe.h:352
the interface for an attachment-data-container.
Definition: attachment_pipe.h:72
virtual size_t occupied_memory()=0
returns the size in bytes, which the container occupies
virtual void reset_entry(size_t index)=0
resets the entry to its default value.
virtual void defragment(size_t *pNewIndices, size_t numValidElements)=0
virtual size_t size()=0
returns the size of the data-array.
virtual void copy_data(size_t indFrom, size_t indTo)=0
copy data from entry indFrom to entry indTo.
virtual void copy_to_container(IAttachmentDataContainer *pDestCon, int *indexMap, int num) const =0
virtual ~IAttachmentDataContainer()
Definition: attachment_pipe.h:74
virtual void resize(size_t iSize)=0
resize the data array
the interface for attachments.
Definition: attachment_pipe.h:239
virtual IAttachment * clone()=0
const char * get_name()
should only be used for debug purposes.
Definition: attachment_pipe.h:250
virtual ~IAttachment()
Definition: attachment_pipe.h:245
IAttachment()
Definition: attachment_pipe.h:241
virtual IAttachmentDataContainer * create_container()=0
virtual bool default_pass_on_behaviour() const =0
IAttachment(const char *name)
Definition: attachment_pipe.h:242
const char * m_name
Definition: attachment_pipe.h:253
supplies a unique ID.
Definition: uid.h:50
define the interface that enables you to use your own types as element-types in an AttachmentPipe.
Definition: attachment_pipe.h:305
void * ElemPtr
Definition: attachment_pipe.h:308
const void * ConstElemHandlerPtr
Definition: attachment_pipe.h:311
const void * ConstElemPtr
Definition: attachment_pipe.h:309
void element_iterator
Definition: attachment_pipe.h:313
static void set_data_index(ElemHandlerPtr pHandler, ElemPtr elem, size_t index)
Definition: attachment_pipe.h:318
static element_iterator elements_end(ElemHandlerPtr pHandler)
Definition: attachment_pipe.h:316
TElem & ElemRef
Definition: attachment_pipe.h:307
static element_iterator elements_begin(ElemHandlerPtr pHandler)
Definition: attachment_pipe.h:315
void * ElemHandlerPtr
Definition: attachment_pipe.h:310
static uint get_data_index(ElemHandlerPtr pHandler, ConstElemPtr elem)
Definition: attachment_pipe.h:317
virtual void clear_attachments(typename TDomain::grid_type &grid)
#define UG_API
Definition: ug_config.h:65
unsigned int uint
Definition: types.h:114
ATTACHMENT_CONSTANTS
Definition: attachment_pipe.h:57
@ INVALID_ATTACHMENT_INDEX
Definition: attachment_pipe.h:58
This struct is used by AttachmentPipe in order to manage its attachments.
Definition: attachment_pipe.h:287
AttachmentEntry()
Definition: attachment_pipe.h:288
uint m_userData
Definition: attachment_pipe.h:294
IAttachmentDataContainer * m_pContainer
Definition: attachment_pipe.h:293
IAttachment * m_pAttachment
Definition: attachment_pipe.h:292
AttachmentEntry(IAttachment *pAttachment, IAttachmentDataContainer *pContainer, uint userData=0)
Definition: attachment_pipe.h:289
std::vector< bool >::reference reference
Definition: attachment_pipe.h:119
const std::vector< bool >::reference const_reference
Definition: attachment_pipe.h:120
define reference and const reference types for attachment values.
Definition: attachment_pipe.h:111
TValue & reference
Definition: attachment_pipe.h:112
const TValue & const_reference
Definition: attachment_pipe.h:113