2.3 Circreg

A circreg is a circular register, and is usefull for round robin like data storage. A circreg is a templated fixed size 1D container. Each time a new item is stored in the container a storage index is incremented, with circular wraparound when the index reaches the end of the container. Thus when the container is full, the “eldest” item is replaced with the “new” one. The “eldest” item is returned as result of the storage function.


Synopsis


  #include <lyric/Circreg.hpp>
  
  template <class RIT>
  class Circreg : public Memory1D<RIT>
  {
  public:
    ~Circreg ()
      throw ();
    Circreg (Size size)
      throw (Exception::Memory::Alloc);
    Circreg (const Circreg& reg)
      throw (Exception::Memory::Alloc);
    Circreg& operator = (const RIT& item)
      throw ();
    Circreg& operator = (const Circreg& reg)
      throw (Exception::Memory::Alloc);
    RIT store (const RIT& item)
      throw ();
  
    // Inherited from Memory1D, see Section 10.1
    Size size () const
      throw ();
    RIT& operator [] (Size index)
      throw (Exception::Memory::Range);
    const RIT& operator [] (Size index) const
      throw (Exception::Memory::Range);
  };


Description


˜Circreg ()
Destroys this circular register. Releases all memory resources used by this container and the stored items.

Circreg (Size size)
Constructs this container with the given size. The size is set and space to store size items is allocated.
|\ Exception::Memory::Alloc
is thrown if not enough memory is found to store size items.

Circreg (const Circreg& reg)
Clones the given circular register into this container. All properties and items stored in reg are copied into this container.
|\ Exception::Memory::Alloc
is thrown if not enough memory is found to store reg.size() items.

Circreg& operator = (const RIT& item)
Sets all items stored in this container to the given value, and returns a reference to this for assignment operation chaining.

Circreg& operator = (const Circreg& reg)
Assigns this container from the given circular register, and returns a reference to this for assignment operation chaining. All properties and items stored in reg are copied into this container.
|\ Exception::Memory::Alloc
is thrown if not enough memory is found to store reg.size() items.

RIT store (const RIT& item)
Stores a new item in this container, and returns the eldest item that was stored at this place. The internal storage index is then incremented with wraparound logic when the end of this container is reached. The stored item becomes the newest in this container.

Size size () const
Returns the number of items this container can store.

RIT& operator [...] (Size index)
Returns a reference to the item stored at position index in this container. This operator can be used as left or right hand value. This means one can as well read as write an item in this container.
|\ Exception::Memory::Range
is thrown if the given index is out of this container’s size, and only if the -DO_RANGE_CHECK is given to the compiler, resp. if O_RANGE_CHECK is defined.

const RIT& operator [...] (Size index) const
Returns an immutable reference to the item stored at position index in this container. This operator can only be used as right hand value. This means one can only read an item from this container.
|\ Exception::Memory::Range
is thrown if the given index is out of this container’s size, and only if the -DO_RANGE_CHECK is given to the compiler, resp. if O_RANGE_CHECK is defined.