OGLplus  (0.59.0) a C++ wrapper for rendering APIs

double_buffer.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_DOUBLE_BUFFER_HPP
10 #define EAGINE_DOUBLE_BUFFER_HPP
11 
12 #include <array>
13 
14 namespace eagine {
15 
18 template <typename T>
20 public:
22  double_buffer() = default;
23 
25  double_buffer(const T& initial)
26  : _values{{initial, initial}} {}
27 
31  void swap() noexcept {
32  _idx = !_idx;
33  }
34 
36  auto front() noexcept -> T& {
37  return _idx ? _values.back() : _values.front();
38  }
39 
41  auto front() const noexcept -> const T& {
42  return _idx ? _values.back() : _values.front();
43  }
44 
46  auto back() noexcept -> T& {
47  return _idx ? _values.front() : _values.back();
48  }
49 
51  auto back() const noexcept -> const T& {
52  return _idx ? _values.front() : _values.back();
53  }
54 
55 private:
56  std::array<T, 2> _values{};
57  bool _idx{false};
58 };
59 
60 } // namespace eagine
61 
62 #endif // EAGINE_DOUBLE_BUFFER_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
auto front() noexcept -> T &
Returns a reference to the current "front" instance.
Definition: double_buffer.hpp:36
void swap() noexcept
Swaps the front and the back buffers.
Definition: double_buffer.hpp:31
auto front() const noexcept -> const T &
Returns a const reference to the current "front" instance.
Definition: double_buffer.hpp:41
auto back() const noexcept -> const T &
Returns a const reference to the current "back" instance.
Definition: double_buffer.hpp:51
auto back() noexcept -> T &
Returns a reference to the current "back" instance.
Definition: double_buffer.hpp:46
Class holding two instances of type T and allows to switch them.
Definition: double_buffer.hpp:19
double_buffer(const T &initial)
Constructor setting the initial value for both buffers.
Definition: double_buffer.hpp:25
double_buffer()=default
Default constructor.

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).