1 #ifndef DOZERG_RING_BUFFER_H_20090218 2 #define DOZERG_RING_BUFFER_H_20090218 11 #include "tools/memory.hh" 15 template<
class T,
class Alloc = std::allocator<T> >
22 typedef T & reference;
23 typedef const T & const_reference;
25 typedef const T * const_pointer;
26 typedef size_t size_type;
27 typedef std::ptrdiff_t difference_type;
28 typedef typename Alloc::
29 template rebind<T>::other allocator_type;
31 explicit CRingBuf(size_type capacity)
40 size_type capacity()
const{
return capa_ - 1;}
41 bool empty()
const{
return head_ == tail_;}
42 size_type size()
const{
return (tail_ + capa_ - head_) % capa_;}
43 bool push(const_reference v){
44 assert(head_ < capa_ && tail_ < capa_);
45 const size_type n = next(tail_);
48 tools::Construct(buf_ + tail_, v);
53 assert(head_ < capa_ && tail_ < capa_);
56 const size_type n = next(head_);
59 tools::Destroy(buf_ + head_);
65 __Myt & operator =(
const __Myt &);
69 buf_ = tools::Allocate<value_type>(allocator_type(), capa_);
74 tools::Deallocate(buf_, capa_, allocator_type());
80 size_type next(size_type cur)
const{
87 const size_type capa_;
88 volatile size_type head_;
89 volatile size_type tail_;
Definition: ring_buf.hh:16