Plasma Engine  2.0
Loading...
Searching...
No Matches
ProcessingStreamIterator_inl.h
1
2template <typename Type>
3plProcessingStreamIterator<Type>::plProcessingStreamIterator(const plProcessingStream* pStream, plUInt64 uiNumElements, plUInt64 uiStartIndex)
4
5{
6 PL_ASSERT_DEV(pStream != nullptr, "Stream pointer may not be null!");
7 PL_ASSERT_DEV(pStream->GetElementSize() == sizeof(Type), "Data size missmatch");
8
9 m_uiElementStride = pStream->GetElementStride();
10
11 m_pCurrentPtr = plMemoryUtils::AddByteOffset(pStream->GetWritableData(), static_cast<std::ptrdiff_t>(uiStartIndex * m_uiElementStride));
12 m_pEndPtr = plMemoryUtils::AddByteOffset(pStream->GetWritableData(), static_cast<std::ptrdiff_t>((uiStartIndex + uiNumElements) * m_uiElementStride));
13}
14
15template <typename Type>
16PL_ALWAYS_INLINE Type& plProcessingStreamIterator<Type>::Current() const
17{
18 return *static_cast<Type*>(m_pCurrentPtr);
19}
20
21template <typename Type>
23{
24 return m_pCurrentPtr >= m_pEndPtr;
25}
26
27template <typename Type>
29{
30 m_pCurrentPtr = plMemoryUtils::AddByteOffset(m_pCurrentPtr, static_cast<std::ptrdiff_t>(m_uiElementStride));
31}
32
33template <typename Type>
34PL_ALWAYS_INLINE void plProcessingStreamIterator<Type>::Advance(plUInt32 uiNumElements)
35{
36 m_pCurrentPtr = plMemoryUtils::AddByteOffset(m_pCurrentPtr, static_cast<std::ptrdiff_t>(m_uiElementStride * uiNumElements));
37}
static T * AddByteOffset(T *pPtr, std::ptrdiff_t offset)
Returns the address stored in ptr plus the given byte offset iOffset, cast to type T.
A single stream in a stream group holding contiguous data of a given type.
Definition ProcessingStream.h:8
T * GetWritableData() const
Returns a non-const pointer to the data casted to the type T, note that no type check is done!
Definition ProcessingStream.h:60
plUInt16 GetElementStride() const
Returns the stride between two elements of the stream in bytes.
Definition ProcessingStream.h:83
plUInt16 GetElementSize() const
Returns the size of one stream element in bytes.
Definition ProcessingStream.h:80
plProcessingStreamIterator(const plProcessingStream *pStream, plUInt64 uiNumElements, plUInt64 uiStartIndex)
Constructor.
Definition ProcessingStreamIterator_inl.h:3
void Advance()
Advances the current pointer to the next element in the stream.
Definition ProcessingStreamIterator_inl.h:28
bool HasReachedEnd() const
Returns true of the iterator has reached the end of the stream or the number of elements it should it...
Definition ProcessingStreamIterator_inl.h:22
Type & Current() const
Returns a reference to the current element. Note that the behavior is undefined if HasReachedEnd() is...
Definition ProcessingStreamIterator_inl.h:16