12 #ifndef __NET_CIRCULARBUFFER_H__
13 #define __NET_CIRCULARBUFFER_H__
46 myArrayOne(one), myArrayTwo(two), myCurrent(0)
49 myArrayOne(), myArrayTwo(), myCurrent(current)
54 return this->item_(myCurrent);
58 return *(this->item_(myCurrent));
62 return *(this->item_(idx));
99 return (*
this) += (-
n);
103 return (*
this) + (-
n);
107 return myCurrent == it.myCurrent;
112 return myCurrent < it.myCurrent;
116 return !(it < *
this);
124 return !(*
this < it);
128 return myCurrent - it.myCurrent;
132 U* item_(
exint idx)
const
134 exint count = myArrayOne.second + myArrayTwo.second;
137 if (myCurrent > count)
140 if (myCurrent > myArrayOne.second)
142 exint idx = myCurrent - myArrayOne.second;
143 return myArrayTwo.first + idx;
146 return myArrayOne.first + myCurrent;
161 T&
front() {
return myData[firstIndex_()]; }
167 T&
back() {
return myData[lastIndex_()]; }
172 const T&
front()
const {
return myData[firstIndex_()]; }
177 const T&
back()
const {
return myData[lastIndex_()]; }
199 return const_base_iterator(
size());
237 growIfNeeded_(count);
242 exint start_idx = mask_(myWrite);
245 T*
start = myData.getArray() + start_idx;
246 const T* data_start =
data;
258 std::memcpy(start, data_start,
sizeof(
T) * chunk);
261 start = myData.data();
269 std::memcpy(start, data_start,
sizeof(
T) * full_count);
272 incrementWrite_(count);
280 T data = myData[myRead];
289 incrementRead_(count);
296 bool isFull()
const {
return increment_(myWrite) == myRead; }
300 bool isEmpty()
const {
return myRead == myWrite; }
306 if (myWrite >= myRead)
307 return myWrite - myRead;
308 return (
capacity() - myRead) + myWrite;
348 exint first_index = firstIndex_();
349 exint last_index = mask_(myWrite);
350 if (
isEmpty() || last_index >= first_index)
351 return std::make_pair(
nullptr, 0);
353 range_t result = std::make_pair(myData.data(), mask_(myWrite));
376 myData.setCapacity(0);
384 UTformat(stderr,
"Read: {} idx={}\n", myRead, mask_(myRead));
385 UTformat(stderr,
"Write: {} idx={}\n", myWrite, mask_(myWrite));
397 return value - last - 1;
405 void growIfNeeded_(
index_t count)
409 exint new_size = UTbumpAlloc(
size() + count);
410 myData.setCapacity(new_size);
411 myData.entries(new_size);
422 return mask_(myRead);
434 return mask_(myWrite - 1);
438 return mask_(index + count);
440 void incrementRead_(
index_t count)
442 myRead = increment_(myRead, count);
444 void incrementWrite_(
index_t count)
446 myWrite = increment_(myWrite, count);
454 #endif // __NET_CIRCULARBUFFER_H__
base_iterator operator+(exint n) const
void debug() const
Printout debug information about this buffer.
bool operator>(const base_iterator &it) const
const_range_t arrayTwo() const
Const variant of the arrayTwo().
bool operator!=(const base_iterator &it) const
void clear()
Completely clear the buffer. This will free any currently allocated data.
base_iterator & operator++()
T & back()
The last element in the buffer. Undefined behaviour if the buffer is empty.
GLsizei const GLfloat * value
const_iterator begin() const
The begin const iterator for the buffer.
bool operator<(const base_iterator &it) const
iterator end()
The end iterator for the buffer.
base_iterator & operator--()
T pop()
Remove a single element from the front of the buffer.
std::pair< const U *, int > const_range_t
**But if you need a result
range_t arrayTwo()
Holds information about the second array of contigous data. See arrayOne() for further details...
void push(const T &data)
Place a single element onto the back of the buffer.
bool isEmpty() const
Is the buffer currently empty.
void push(const T *data, exint count)
Place an array of elements onto the back of the buffer.
const T & operator[](int index) const
Retrieve element at provided index.
base_iterator & operator+=(exint n)
base_iterator< U > iterator
base_iterator operator-(exint n) const
const_iterator end() const
The end const iterator for the buffer.
bool operator>=(const base_iterator &it) const
base_iterator operator++(int)
base_iterator(const range_t &one, const range_t &two)
iterator begin()
The begin iterator for the buffer.
exint capacity() const
The current capacity of the buffer.
base_iterator(exint current)
bool isFull() const
Is the buffer currently full.
range_t arrayOne()
A circular buffer can wrap around in memory. This is the first array of continious memory...
exint maxSize() const
The absolute maximum size of the buffer. Use size() if you need to know the current size of the buffe...
bool operator<=(const base_iterator &it) const
__hostdev__ uint64_t last(uint32_t i) const
bool operator==(const base_iterator &it) const
std::pair< U *, int > range_t
exint operator-(const base_iterator &it) const
U & operator[](exint idx) const
const T & back() const
The last element in the buffer. Undefined behaviour if the buffer is empty.
base_iterator operator--(int)
base_iterator< const U > const_iterator
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
T & operator[](int index)
Retrieve element at provided index.
typename NET_CircularBuffer< U >::range_t range_t
exint size() const
The number of elements currently stored in the buffer.
base_iterator & operator-=(exint n)
T & front()
The first element in the buffer. Undefined behaviour if the buffer is empty.
const T & front() const
The first element in the buffer. Undefined behaviour if the buffer is empty.
void pop(int count)
Remove multiple elements from the front of the buffer.
int entries() const
The number of elements currently stored in the buffer.
const_range_t arrayOne() const
Const variant of the arrayOne().