33 #ifndef __UTIL__ATTACHMENT_PIPE__IMPL__
34 #define __UTIL__ATTACHMENT_PIPE__IMPL__
41 template <
class TElem,
class TElemHandler>
44 m_attachmentEntryIteratorHash(13),
52 template <
class TElem,
class TElemHandler>
55 m_attachmentEntryIteratorHash(13),
63 template <
class TElem,
class TElemHandler>
69 iter != m_attachmentEntryContainer.end(); iter++)
71 delete (*iter).m_pAttachment;
72 delete (*iter).m_pContainer;
76 template <
class TElem,
class TElemHandler>
85 template <
class TElem,
class TElemHandler>
91 resize_attachment_containers(0);
96 template <
class TElem,
class TElemHandler>
101 m_attachmentEntryContainer.clear();
102 m_attachmentEntryIteratorHash.clear();
105 template <
class TElem,
class TElemHandler>
111 iter != m_attachmentEntryContainer.end(); iter++)
113 (*iter).m_pContainer->reset_entry(dataIndex);
119 template <
class TElem,
class TElemHandler>
124 if(numElems > get_container_size())
125 resize_attachment_containers(numElems);
128 template <
class TElem,
class TElemHandler>
136 if(!m_stackFreeEntries.empty())
139 newInd = m_stackFreeEntries.top();
140 m_stackFreeEntries.pop();
143 reset_values(newInd);
148 newInd = m_numDataEntries++;
150 grow_attachment_containers(m_numDataEntries);
154 atraits::set_data_index(m_pHandler, elem, newInd);
160 template <
class TElem,
class TElemHandler>
166 size_t ind = atraits::get_data_index(m_pHandler, elem);
168 m_stackFreeEntries.push(ind);
174 template <
class TElem,
class TElemHandler>
175 template <
class TAttachment>
178 attach(TAttachment& attachment,
179 const typename TAttachment::ValueType& defaultValue,
183 if(!has_attachment(attachment))
190 pClonedContainer->
resize(get_container_size());
192 insert(m_attachmentEntryContainer.end(),
194 pClonedContainer, options));
195 m_attachmentEntryIteratorHash.insert(pClonedAttachment->
id(), iter);
203 template <
class TElem,
class TElemHandler>
209 if(!has_attachment(attachment))
216 pClonedContainer->
resize(get_container_size());
218 m_attachmentEntryIteratorHash.insert(pClonedAttachment->
id(), iter);
226 template <
class TElem,
class TElemHandler>
231 if(has_attachment(attachment))
234 delete ((*iter).m_pAttachment);
235 ((*iter).m_pAttachment) = NULL;
236 delete((*iter).m_pContainer);
237 ((*iter).m_pContainer) = NULL;
238 m_attachmentEntryContainer.erase(iter);
239 m_attachmentEntryIteratorHash.erase(attachment.
id());
243 template <
class TElem,
class TElemHandler>
248 return m_attachmentEntryIteratorHash.has_entry(attachment.
id());
252 template <
class TElem,
class TElemHandler>
253 template <
class TAttachment>
254 typename TAttachment::ValueType*
258 if(has_attachment(attachment))
259 return get_data_container(attachment)->get_ptr();
264 template <
class TElem,
class TElemHandler>
270 if(m_attachmentEntryIteratorHash.get_entry(iter, attachment.
id()))
271 return iter->m_pContainer;
275 template <
class TElem,
class TElemHandler>
276 template <
class TAttachment>
277 typename TAttachment::ContainerType*
282 if(m_attachmentEntryIteratorHash.get_entry(iter, attachment.id()))
283 return static_cast<typename TAttachment::ContainerType*
>(iter->m_pContainer);
287 template <
class TElem,
class TElemHandler>
296 if(num_elements() == 0)
300 iter != m_attachmentEntryContainer.end(); iter++)
302 (*iter).m_pContainer->resize(0);
305 m_numDataEntries = 0;
317 for(; iter != end; ++iter){
318 vNewIndices[atraits::get_data_index(m_pHandler, (*iter))] = counter;
319 atraits::set_data_index(m_pHandler, (*iter), counter);
325 m_numDataEntries = counter;
330 iter != m_attachmentEntryContainer.end(); iter++)
332 (*iter).m_pContainer->defragment(&vNewIndices.front(), num_elements());
396 template <
class TElem,
class TElemHandler>
403 m_containerSize = newSize;
405 iter != m_attachmentEntryContainer.end(); iter++)
407 (*iter).m_pContainer->resize(newSize);
413 template <
class TElem,
class TElemHandler>
422 size_t actSize = get_container_size();
424 if(actSize < newMinSize)
426 size_t newSize = actSize * 2;
427 if(newSize < newMinSize)
428 newSize = newMinSize;
430 resize_attachment_containers(newSize);
435 template <
class TElem,
class TElemHandler>
440 return m_containerSize;
446 template <
class TElem,
class TAttachment,
class TElemHandler>
452 template <
class TElem,
class TAttachment,
class TElemHandler>
460 template <
class TElem,
class TAttachment,
class TElemHandler>
466 assert(m_pContainer &&
"ERROR in AttachmentAccessor::AttachmentAccessor(attachmentPipe, attachment): attachment not attached to attachmentPipe!");
469 template <
class TElem,
class TAttachment,
class TElemHandler>
479 assert(m_pContainer &&
"ERROR in AttachmentAccessor::access(attachmentPipe, attachment): attachment not attached to attachmentPipe!");
Used to access data that has been attached to an attachment pipe.
Definition: attachment_pipe.h:510
TElemHandler * m_pHandler
Definition: attachment_pipe.h:588
bool access(attachment_pipe &attachmentPipe, TAttachment &attachment)
Definition: attachment_pipe.hpp:472
ContainerType * m_pContainer
Definition: attachment_pipe.h:587
TAttachment attachment
Definition: attachment_pipe.h:512
AttachmentAccessor()
Definition: attachment_pipe.hpp:448
Handles data which has been attached to the pipe using callbacks for the element.
Definition: attachment_pipe.h:337
size_t get_container_size()
Definition: attachment_pipe.hpp:438
void attach(TAttachment &attachment, const typename TAttachment::ValueType &defaultValue, uint options)
attaches a new data-array to the pipe.
Definition: attachment_pipe.hpp:178
void resize_attachment_containers(size_t newSize)
Definition: attachment_pipe.hpp:399
void reset_values(size_t dataIndex)
fills the attached data at the given index with the default values.
Definition: attachment_pipe.hpp:108
TAttachment::ValueType * get_data_array(TAttachment &attachment)
Lets you access the raw data array associated with the given attachment.
Definition: attachment_pipe.hpp:256
std::stack< size_t > UINTStack
Definition: attachment_pipe.h:474
void clear_elements()
clears elements and associated data but keeps registered attachments
Definition: attachment_pipe.hpp:88
void grow_attachment_containers(size_t newMinSize)
Definition: attachment_pipe.hpp:416
void reserve(size_t numElems)
Reserves memory for element- and data-entries.
Definition: attachment_pipe.hpp:122
void clear()
calls both clear_elements and clear_attachments.
Definition: attachment_pipe.hpp:79
void register_element(TElem elem)
Registers a new element at the attachment pipe.
Definition: attachment_pipe.hpp:131
void clear_attachments()
clears registered attachments and associated data but keeps existing elements.
Definition: attachment_pipe.hpp:99
void detach(IAttachment &attachment)
Removes the data associated with the given attachment from the pipe.
Definition: attachment_pipe.hpp:229
AttachmentPipe()
Definition: attachment_pipe.hpp:43
void defragment()
Definition: attachment_pipe.hpp:290
AttachmentEntryContainer::iterator AttachmentEntryIterator
Definition: attachment_pipe.h:342
~AttachmentPipe()
Definition: attachment_pipe.hpp:65
IAttachmentDataContainer * get_data_container(IAttachment &attachment) const
Returns the data container managing the data array for the given attachment.
Definition: attachment_pipe.hpp:267
bool has_attachment(IAttachment &attachment) const
Returns true if the given attachment is currently attached to the pipe.
Definition: attachment_pipe.hpp:246
void unregister_element(const TElem &elem)
Unregisters the given element.
Definition: attachment_pipe.hpp:163
atraits::ElemHandlerPtr get_elem_handler()
Definition: attachment_pipe.h:352
the interface for an attachment-data-container.
Definition: attachment_pipe.h:72
virtual void resize(size_t iSize)=0
resize the data array
the interface for attachments.
Definition: attachment_pipe.h:239
virtual IAttachment * clone()=0
virtual IAttachmentDataContainer * create_container()=0
unsigned int id() const
Definition: uid.h:60
void element_iterator
Definition: attachment_pipe.h:313
void * ElemHandlerPtr
Definition: attachment_pipe.h:310
virtual void clear_attachments(typename TDomain::grid_type &grid)
unsigned int uint
Definition: types.h:114
@ 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