• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • FIFOBuffer
  • 4.11.14

FIFOBuffer Class

A FIFO buffer using a circular buffer with head and tail indices. More...

Header: #include <Generic/FIFOBuffer.h>
  • List of all members, including inherited members

Public Functions

FIFOBuffer(unsigned int bufferSize = 255)
FIFOBuffer(FIFOBuffer<T, R> &rhs)
virtual ~FIFOBuffer()
void Add(R newValue)
bool Empty() const
bool Full() const
unsigned int GetHeadIndex()
void IncrementIndex(unsigned int &index)
void Insert(R newValue, unsigned int index)
unsigned int Length() const
unsigned int NumberOfUnreadValues(unsigned int lastIndexRead)
R ReadDontRemove()
void Realloc(unsigned int nNewSize)
T Remove()
T Remove(unsigned int index)
R operator[](unsigned int index) const

Protected Variables

unsigned int m_nBufferSize
unsigned int m_nHead
int m_nLength
unsigned int m_nTail
T *m_pBuffer
OSAPIMutex mutexLock

Detailed Description

A FIFO buffer using a circular buffer with head and tail indices.

Stores up to 'bufferSize' last elements that were added/inserted. Oldest elements will be overwritten.

Template parameters:

  • T: The type of data/object to be stored in the buffer.
  • R: The type used as a reference to the stored data type. The purpose is to enable passing by reference for complex objects. For simple data types, this parameters should equal T.

Note: Internally, a buffer with size one more than specified is used because this simplifies the length handling (therefore, m_nBufferSize will be one more than the specified buffer size).

Member Function Documentation

FIFOBuffer::FIFOBuffer(unsigned int bufferSize = 255)

Constructs a FIFOBuffer instance. Allocates memory for m_pBuffer of size bufferSize+1

FIFOBuffer::FIFOBuffer(FIFOBuffer<T, R> &rhs)

Copy constructor for FIFOBuffer. Allocates memory for m_pBuffer of same size as rhs and copies the data from rhs.

[virtual] FIFOBuffer::~FIFOBuffer()

Destroys the instance of FIFOBuffer and releases allocated resources.

void FIFOBuffer::Add(R newValue)

Adds a new value into the buffer, at index m_nHead.

bool FIFOBuffer::Empty() const

Returns true if buffer is empty

bool FIFOBuffer::Full() const

Returns true if buffer has grown to full size

unsigned int FIFOBuffer::GetHeadIndex()

Returns index of next free position, m_nHead

void FIFOBuffer::IncrementIndex(unsigned int &index)

Increments index, including wrapping at m_nBufferSize

void FIFOBuffer::Insert(R newValue, unsigned int index)

Insert a new value at specified index in the buffer.

Index should be in the range [0..'Length()-1'], where index 0 will correspond to value found in m_nTail, but if index is larger than 'Length()-1', value will be added at index 'Length()' (same as Add()). This function will copy data, and adjust either m_nHead or m_nTail.

unsigned int FIFOBuffer::Length() const

Returns number of elements in the buffer

unsigned int FIFOBuffer::NumberOfUnreadValues(unsigned int lastIndexRead)

Returns number of unread values in the buffer

R FIFOBuffer::ReadDontRemove()

Return but don't remove the next value from the buffer. Call Remove() later to remove.

void FIFOBuffer::Realloc(unsigned int nNewSize)

T FIFOBuffer::Remove()

Returns and removes the next value from the buffer

T FIFOBuffer::Remove(unsigned int index)

Return and remove the index-specified value from the buffer.

Index should be in the range [0..'Length()-1'], where index 0 will correspond to value found in m_nTail. This function will copy data, and adjust either m_nHead or m_nTail. If illegal index is specified, m_pBuffer[m_nTail] is returned.

R FIFOBuffer::operator[](unsigned int index) const

Operator[] which returns value of element at position index in the array container (m_pBuffer)

Member Variable Documentation

unsigned int FIFOBuffer::m_nBufferSize

This variable holds the maximum size of the buffer before oldest elements will be overwritten.

unsigned int FIFOBuffer::m_nHead

This variable holds index storing the location of where the next element will be added.

int FIFOBuffer::m_nLength

This variable holds number of elements in the buffer.

unsigned int FIFOBuffer::m_nTail

This variable holds index of the last element in the buffer (the next to remove).

T *FIFOBuffer::m_pBuffer

This variable holds the buffer/array containing the datavalues of type T.

OSAPIMutex FIFOBuffer::mutexLock

This variable holds the OSAPIMutex member used to protect the other members during access/update.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

    © Copyright 2022 CDP Technologies. Privacy and cookie policy.

    Return to top