12 #ifndef __NET_CIRCULARBUFFER_H__
13 #define __NET_CIRCULARBUFFER_H__
47 myArrayOne(one), myArrayTwo(two), myCurrent(0)
50 myArrayOne(), myArrayTwo(), myCurrent(current)
55 return this->item_(myCurrent);
59 return *(this->item_(myCurrent));
63 return *(this->item_(idx));
100 return (*
this) += (-
n);
104 return (*
this) + (-
n);
108 return myCurrent == it.myCurrent;
113 return myCurrent < it.myCurrent;
117 return !(it < *
this);
125 return !(*
this < it);
129 return myCurrent - it.myCurrent;
133 U* item_(
exint idx)
const
135 exint count = myArrayOne.second + myArrayTwo.second;
138 if (myCurrent > count)
141 if (myCurrent > myArrayOne.second)
143 exint idx = myCurrent - myArrayOne.second;
144 return myArrayTwo.first + idx;
147 return myArrayOne.first + myCurrent;
162 T&
front() {
return myData[firstIndex_()]; }
168 T&
back() {
return myData[lastIndex_()]; }
173 const T&
front()
const {
return myData[firstIndex_()]; }
178 const T&
back()
const {
return myData[lastIndex_()]; }
200 return const_base_iterator(
size());
238 growIfNeeded_(count);
243 exint start_idx = mask_(myWrite);
246 T*
start = myData.getArray() + start_idx;
247 const T* data_start =
data;
260 std::memcpy(start, data_start,
sizeof(
T) * chunk);
263 start = myData.data();
271 std::memcpy(start, data_start,
sizeof(
T) * full_count);
274 incrementWrite_(count);
282 T data = myData[myRead];
291 incrementRead_(count);
298 bool isFull()
const {
return increment_(myWrite) == myRead; }
302 bool isEmpty()
const {
return myRead == myWrite; }
308 if (myWrite >= myRead)
309 return myWrite - myRead;
310 return (
capacity() - myRead) + myWrite;
350 exint first_index = firstIndex_();
351 exint last_index = mask_(myWrite);
352 if (
isEmpty() || last_index >= first_index)
353 return std::make_pair(
nullptr, 0);
355 range_t result = std::make_pair(myData.data(), mask_(myWrite));
378 myData.setCapacity(0);
386 UTformat(stderr,
"Read: {} idx={}\n", myRead, mask_(myRead));
387 UTformat(stderr,
"Write: {} idx={}\n", myWrite, mask_(myWrite));
399 return value - last - 1;
407 void growIfNeeded_(
index_t count)
411 exint new_size = UTbumpAlloc(
size() + count);
412 myData.setCapacity(new_size);
413 myData.entries(new_size);
424 return mask_(myRead);
436 return mask_(myWrite - 1);
440 return mask_(index + count);
442 void incrementRead_(
index_t count)
444 myRead = increment_(myRead, count);
446 void incrementWrite_(
index_t count)
448 myWrite = increment_(myWrite, count);
456 #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().