libcruft-util/cruft/util/buffer/circular.hpp

57 lines
1.6 KiB
C++
Raw Normal View History

2015-11-11 16:56:35 +11:00
/*
2018-08-04 15:14:06 +10:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
2015-11-11 16:56:35 +11:00
*
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
2015-11-11 16:56:35 +11:00
#include "../view.hpp"
2015-11-11 16:56:35 +11:00
#include <cstddef>
namespace cruft::buffer {
2015-11-11 16:56:35 +11:00
// buffer size is advisory and will likely depend on page size. the user
// must check the size after creation if this field is important for
// their usage.
template <typename ValueT>
2015-11-11 16:56:35 +11:00
class circular {
public:
using value_type = ValueT;
using iterator = value_type*;
using const_iterator = const value_type*;
2015-11-11 16:56:35 +11:00
2016-03-17 18:09:40 +11:00
explicit circular (size_t bytes);
2015-11-11 16:56:35 +11:00
~circular ();
circular (const circular&) = delete;
circular (circular&&) = delete;
circular& operator= (const circular&) = delete;
circular& operator= (circular&&) = delete;
value_type& operator[] (size_t)&;
const value_type& operator[] (size_t) const&;
2015-11-11 16:56:35 +11:00
iterator begin (void)&;
iterator end (void)&;
2015-11-11 16:56:35 +11:00
const_iterator begin (void) const&;
const_iterator end (void) const&;
2015-11-11 16:56:35 +11:00
size_t size (void) const;
/// rebases the pointer so that it points to within the first
/// repetition of the data buffer.
iterator constrain (iterator);
/// rebases a pair of pointers so they fall within a contiguous span of
/// the data buffer.
cruft::view<iterator> constrain (cruft::view<iterator>);
2015-11-11 16:56:35 +11:00
private:
value_type *m_begin, *m_end;
2015-11-11 16:56:35 +11:00
};
2017-01-05 15:06:49 +11:00
}