teditor  1.8.0@@fee5e94
Terminal based editor written in C++
double_buffer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace teditor {
4 
9 template <typename Type>
10 struct DoubleBuffer {
11  DoubleBuffer(): data(), pos(0) {}
12  Type& current() { return data[pos]; }
13  const Type& current() const { return data[pos]; }
14  Type& next() { return data[pos ^ 1]; }
15  const Type& next() const { return data[pos ^ 1]; }
16  void update() { pos ^= 1; }
17 
18  private:
19  Type data[2];
20  int pos;
21 }; // struct DoubleBuffer
22 
23 } // namespace teditor
teditor::DoubleBuffer::current
Type & current()
Definition: double_buffer.hpp:12
teditor::DoubleBuffer::DoubleBuffer
DoubleBuffer()
Definition: double_buffer.hpp:11
teditor::DoubleBuffer::next
Type & next()
Definition: double_buffer.hpp:14
teditor::DoubleBuffer::update
void update()
Definition: double_buffer.hpp:16
teditor::DoubleBuffer::current
const Type & current() const
Definition: double_buffer.hpp:13
teditor::DoubleBuffer::next
const Type & next() const
Definition: double_buffer.hpp:15
teditor::DoubleBuffer
A simple double buffer container for ping-pong kind of operations.
Definition: double_buffer.hpp:10
teditor
Definition: any.hpp:10