WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
PersistenceTracker.hpp
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) ATTX INC 2026. 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#ifndef UTILS_PERSISTENCE_TRACKER_HPP
17#define UTILS_PERSISTENCE_TRACKER_HPP
18
19#include "types.h"
21
22namespace clockwerk {
23
63template <typename T, uint8 N>
65public:
66 PersistenceTracker(uint8 required=N) {_required = required;}
68
71 void pushValue(T value) {_values.write(value);}
72
76 bool greaterThan(T value);
77
81 bool lessThan(T value);
82
87 bool inRange(T min, T max);
88
93 bool outsideRange(T min, T max);
94protected:
95 // Buffer to hold last N values for persistence check
97 uint8 _required = 0;
98};
99
100template <typename T, uint8 N>
102 uint8 count = 0;
103 T tmp;
104 for (uint8 i = 0; i < _values.valsHeld(); i++) {
105 // Read from the queue into tmp, and return error if we encounter one
106 // (which should not be possible here, because the only error is a range one)
107 if(_values.peekIndex(i, tmp)) {return false;}
108 if (tmp > value) count++;
109 }
110 return count >= _required;
111}
112
113template <typename T, uint8 N>
115 uint8 count = 0;
116 T tmp;
117 for (uint8 i = 0; i < _values.valsHeld(); i++) {
118 // Read from the queue into tmp, and return error if we encounter one
119 // (which should not be possible here, because the only error is a range one)
120 if(_values.peekIndex(i, tmp)) {return false;}
121 if (tmp < value) count++;
122 }
123 return count >= _required;
124}
125
126template <typename T, uint8 N>
128 if(min >= max) {return false;}
129
130 uint8 count = 0;
131 T tmp;
132 for (uint8 i = 0; i < _values.valsHeld(); i++) {
133 // Read from the queue into tmp, and return error if we encounter one
134 // (which should not be possible here, because the only error is a range one)
135 if(_values.peekIndex(i, tmp)) {return false;}
136 if (tmp > min && tmp < max) count++;
137 }
138 return count >= _required;
139}
140
141template <typename T, uint8 N>
143 if(min >= max) {return false;}
144
145 uint8 count = 0;
146 T tmp;
147 for (uint8 i = 0; i < _values.valsHeld(); i++) {
148 // Read from the queue into tmp, and return error if we encounter one
149 // (which should not be possible here, because the only error is a range one)
150 if(_values.peekIndex(i, tmp)) {return false;}
151 if (tmp < min || tmp > max) count++;
152 }
153 return count >= _required;
154}
155
156}
157
158#endif
Simple Circular Buffer for data storage.
Definition CircularBuffer.hpp:37
uint8 _required
Definition PersistenceTracker.hpp:97
CircularBuffer< T, N > _values
Definition PersistenceTracker.hpp:96
bool outsideRange(T min, T max)
Check if required values lie outside range between min and max.
Definition PersistenceTracker.hpp:142
bool lessThan(T value)
Checks if the required number of values tracked is less than the input.
Definition PersistenceTracker.hpp:114
~PersistenceTracker()
Definition PersistenceTracker.hpp:67
bool inRange(T min, T max)
Check if required values lie inside range between min and max.
Definition PersistenceTracker.hpp:127
void pushValue(T value)
Add a value to the persistence tracker.
Definition PersistenceTracker.hpp:71
PersistenceTracker(uint8 required=N)
Definition PersistenceTracker.hpp:66
bool greaterThan(T value)
Checks if the required number of values tracked is greater than the input.
Definition PersistenceTracker.hpp:101
Definition CircularBuffer.hpp:28