BlockFifo

Files CCore/inc/BlockFifo.h CCore/src/BlockFifo.cpp

BlockFifo

The Partial class BlockFifo implements a buffer fifo upon a provided buffer. Unlike the Fifo class, it provides block put/get operations, i.e. these operations put/get multiple objects a time.


template <class T>
class BlockFifo : NoCopy
 {
   T *const buf;
   const ulen len;
   
   ulen off;
   ulen count;
   
  public:
   
   BlockFifo(T *buf,ulen len);
   
   explicit BlockFifo(PtrLen<T> buf);

   ulen getCount() const { return count; }
   
   bool isEmpty() const { return count==0; }
   
   bool isFull() const { return count==len; }
   
   void reset();
   
   // put
   
   template <class Func>
   ulen put(ulen putlen,Func func); // func(T *ptr,ulen len)
   
   ulen put(PtrLen<const T> data);
   
   // get
   
   template <class Func>
   ulen get(ulen getlen,Func func); // func([const] T *ptr,ulen len)
 
   ulen get(PtrLen<T> data);
 };

Constructor creates the fifo in the given buffer.

getCount() returns the number of objects in the fifo.

isEmpty() returns true, if the fifo is empty.

isFull() returns true, if the fifo is full.

reset() resets the fifo. It becomes empty.

put(ulen,Func) puts the number of objects in the fifo. This method is generic. The first argument is the number of objects, required to be put. The second is a functor. This functor is used to provide an actual data. It may be called up to two times to fill the range of objects with desired values. The number of handled objects is returned.

put(PtrLen<const T>) puts objects from the given range in the fifo. The number of objects have been copied is returned. It can be less, than the range length, if there is no enough room.

get(ulen,Func) gets the number of objects from the fifo. This method is generic. The first argument is the number of objects, required to be get. The second is a functor. This functor is used to extract data. It may be called up to two times to copy the range of objects from the fifo. The number of handled objects is returned.

get() gets objects from the fifo to the given range. The number of objects have been copied is returned.

BlockFifoBuf

The class BlockFifoBuf is an upgraded class BlockFifo with the embedded buffer:


template <class T,ulen Len>
class BlockFifoBuf : public BlockFifo<T>
 {
   T buf[Len];
   
  public:
  
   BlockFifoBuf() : BlockFifo<T>(buf,Len) {}
  
   ~BlockFifoBuf() {}
 };