WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
CircularBuffer.hpp
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) ATTX INC 2025. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, INC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, INC.
15******************************************************************************/
16/*
17
18Author: Will Burken
19*/
20#ifndef DATA_MANAGEMENT_CIRC_BUFF_HPP
21#define DATA_MANAGEMENT_CIRC_BUFF_HPP
22
23#include <stdint.h>
24
25#include "types.h"
27
28namespace clockwerk {
29
36template <typename T, uint32 L>
37class CircularBuffer : public Queue<T, L> {
38public:
39 // Can't actually do anything in the constructor
41
45 int16 write(const T& instance);
52 int16 writeBuffer(const T* buffer, uint32 size);
53
54};
55
56template <typename T, uint32 L>
57int16 CircularBuffer<T, L>::write(const T& instance) {
58 int16 err = NO_ERROR;
59 // Check if buffer is full. is so, read one value to make space
63 }
64
65 Queue<T,L>::write(instance);
66 return err;
67}
68
69template <typename T, uint32 L>
70int16 CircularBuffer<T, L>::writeBuffer(const T* buffer, uint32 size) {
71 if(buffer == nullptr) {
72 return ERROR_NULLPTR;
73 }
74 if(size > L) {
75 return ERROR_QUEUE_FULL;
76 }
77
78 int16 err = NO_ERROR;
79
80 // Check and return if buffer doesn't have enough space
81 while(size > Queue<T, L>::_vals_available) {
84 }
85 Queue<T, L>::writeBuffer(buffer, size);
86 return err;
87}
88
89}
90
91#endif
CircularBuffer()
Definition CircularBuffer.hpp:40
int16 write(const T &instance)
Write a single data item into the buffer.
Definition CircularBuffer.hpp:57
int16 writeBuffer(const T *buffer, uint32 size)
Write a buffer of data items into the buffer.
Definition CircularBuffer.hpp:70
int16 pop()
Function to pop one value from the queue and discard it.
Definition Queue.hpp:220
int16 write(const T &instance)
Write a single data item into the queue.
Definition Queue.hpp:118
uint32 _vals_available
Number of values available in the queue.
Definition Queue.hpp:111
Queue()
Definition Queue.hpp:41
int16 writeBuffer(const T *buffer, uint32 size)
Write a buffer of data items into the queue.
Definition Queue.hpp:138
#define NO_ERROR
Error code in the case where matrix math executed successfully.
Definition clockwerkerrors.h:34
#define ERROR_NULLPTR
Error code in case of a null pointer.
Definition clockwerkerrors.h:60
#define WARNING_BUFFER_FULL
Warning in case buffer byte(s) need to be popped to write new values.
Definition clockwerkerrors.h:201
#define ERROR_QUEUE_FULL
Error in case the queue is full.
Definition clockwerkerrors.h:195
Definition CircularBuffer.hpp:28