2 #ifndef GMARRAYRINGBUFFER_HPP_
3 #define GMARRAYRINGBUFFER_HPP_
20 template<
typename T,
int C>
28 int WriteRecord (T *pcSource);
29 int ReadRecord (T *pcDestination);
30 int NoticeRecord (
int *piDestination);
31 int ForgetNextRecord ();
36 Bool HasUnnoticedData ();
37 int ReserveRecord (
int *pIndex);
38 T& GetBuffer (
int iBufferIndex);
39 int CopyAndCommitData (T *pcSource,
41 int CommitData (
int index);
46 int InternalWriteRecord (T *pcSource);
47 int m_iLastBufferRead,
52 Bool m_bNextWriteWouldOverrun,
53 m_bNextWriteWouldOverrunNotice,
61 #ifndef _GEO_APPDEFS_HPP
62 #include <GeoAppDefs.hpp>
72 #include <xdc/cfg/global.h>
73 #include <xdc/runtime/Error.h>
74 #include <xdc/runtime/System.h>
75 #include <xdc/runtime/Memory.h>
77 #include "geotypes.hpp"
79 #include "GmRingBuffer.hpp"
81 #include "GmArrayRingBuffer.hpp"
86 #ifdef DEBUGGING_COMPILE_ISSUES
98 template<
typename T,
int C>
102 m_bOkToOverrun (bOkToOverrun),
103 m_bNotices (bNotices)
113 #ifdef DEBUGGING_COMPILE_ISSUES
118 ReadRecord (&aTestItem);
120 WriteRecord(&aTestItem);
124 template<
typename T,
int C>
128 m_iLastBufferRead = -1;
129 m_iLastBufferWritten = -1;
130 m_iLastBufferNoticed = -1;
131 m_bNextWriteWouldOverrun = FALSE;
132 m_bNextWriteWouldOverrunNotice = FALSE;
135 template<
typename T,
int C>
138 if ((iBufferIndex < 0) ||
139 (iBufferIndex >= this->size()))
144 return this->at(iBufferIndex);
147 template<
typename T,
int C>
150 return ((m_iLastBufferRead == m_iLastBufferWritten)&&
151 !m_bNextWriteWouldOverrun);
155 template<
typename T,
int C>
161 template<
typename T,
int C>
164 if (m_iLastBufferRead < m_iLastBufferWritten)
166 return (m_iLastBufferWritten - m_iLastBufferRead);
168 else if (m_iLastBufferWritten < m_iLastBufferRead)
170 return (this->size() - m_iLastBufferRead + m_iLastBufferWritten);
172 else if (m_iLastBufferWritten == -1)
182 template<
typename T,
int C>
185 return (!IsEmpty ());
188 template<
typename T,
int C>
191 return (HasData () && (this->m_iLastBufferNoticed != m_iLastBufferRead));
201 template<
typename T,
int C>
206 if (m_Buffer == NULL)
207 return GM_RING_BUFFER_FAILURE;
210 return GM_RING_BUFFER_EMPTY;
212 if (!HasUnnoticedData ())
214 return GM_RING_BUFFER_NO_UNNOTICED;
218 iNotice = m_iLastBufferNoticed + 1;
220 if (iNotice == m_iMaxItems)
222 *piDestination = iNotice;
227 m_bNextWriteWouldOverrunNotice = FALSE;
230 m_iLastBufferNoticed = iNotice;
232 return GM_RING_BUFFER_OK;
239 template<
typename T,
int C>
246 return GM_RING_BUFFER_EMPTY;
249 iReadBuffer = m_iLastBufferRead + 1;
251 if (iReadBuffer == this->size())
254 if (pcDestination !=
nullptr)
256 *pcDestination = GetBuffer (iReadBuffer);
260 m_bNextWriteWouldOverrun = FALSE;
263 if (iReadBuffer == m_iLastBufferWritten)
265 m_iLastBufferWritten = -1;
266 m_iLastBufferRead = -1;
270 m_iLastBufferRead = iReadBuffer;
273 if (pcDestination ==
nullptr)
274 return GM_RING_BUFFER_NULL_DESTINATION;
276 return GM_RING_BUFFER_OK;
279 template<
typename T,
int C>
283 int iTest = ReadRecord (NULL);
286 case GM_RING_BUFFER_NULL_DESTINATION:
287 return GM_RING_BUFFER_OK;
290 case GM_RING_BUFFER_OK:
291 return GM_RING_BUFFER_FAILURE;
298 template<
typename T,
int C>
303 iTest = CheckToWrite ( iSize);
304 if (iTest == GM_RING_BUFFER_OK)
306 return InternalWriteRecord (pcSource);
313 template<
typename T,
int C>
316 return GM_RING_BUFFER_OK;
319 template<
typename T,
int C>
324 int iReturn = GM_RING_BUFFER_OK;
329 if (m_bNextWriteWouldOverrun)
334 m_bNextWriteWouldOverrun = FALSE;
337 iReturn = ReserveRecord (pIndex);
340 if (iReturn == GM_RING_BUFFER_OK)
341 return GM_RING_BUFFER_OVERRUN_OVERWROTE;
349 return GM_RING_BUFFER_OVERRUN_NO_WRITE;
354 if (m_bNextWriteWouldOverrunNotice)
356 m_iLastBufferNoticed++;
357 if (m_iLastBufferNoticed == this->size())
358 m_iLastBufferNoticed = 0;
361 iWriteBuffer = m_iLastBufferWritten + 1;
362 if (iWriteBuffer == this->size())
366 if (iWriteBuffer == m_iLastBufferRead)
368 m_bNextWriteWouldOverrun = TRUE;
372 if (iWriteBuffer == m_iLastBufferNoticed)
374 m_bNextWriteWouldOverrunNotice = TRUE;
377 *pIndex = iWriteBuffer;
378 return GM_RING_BUFFER_OK;
381 template<
typename T,
int C>
384 m_iLastBufferWritten = index;
385 return GM_RING_BUFFER_OK;
389 template<
typename T,
int C>
396 GetBuffer(index) = *pcSource;
401 m_iLastBufferWritten = index;
403 return GM_RING_BUFFER_OK;
407 template<
typename T,
int C>
413 int iReturn = ReserveRecord (&iWriteBuffer);
415 if ((iReturn == GM_RING_BUFFER_OK) ||
416 (iReturn == GM_RING_BUFFER_OVERRUN_OVERWROTE))
418 int iWriteTest = CopyAndCommitData (pcSource,iWriteBuffer);
419 if (iWriteTest != GM_RING_BUFFER_OK)
Definition: GmArrayRingBuffer.hpp:22
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47