3      Copyright (C) Dean Camera, 2010. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this  
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in  
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting  
  17   documentation, and that the name of the author not be used in  
  18   advertising or publicity pertaining to distribution of the  
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33 void Buffer_Initialize(RingBuff_t
* const Buffer
) 
  37                 Buffer
->InPtr    
= (RingBuff_Data_t
*)&Buffer
->Buffer
; 
  38                 Buffer
->OutPtr   
= (RingBuff_Data_t
*)&Buffer
->Buffer
; 
  43 void Buffer_StoreElement(RingBuff_t
* const Buffer
, RingBuff_Data_t Data
) 
  47         #if defined(BUFF_DROPOLD) 
  48                 if (Buffer
->Elements 
== BUFF_LENGTH
) 
  52                         if (Buffer
->OutPtr 
== &Buffer
->Buffer
[BUFF_LENGTH
]) 
  53                           Buffer
->OutPtr 
= (RingBuff_Data_t
*)&Buffer
->Buffer
; 
  59         #elif defined(BUFF_DROPNEW) 
  60                 if (Buffer
->Elements 
== BUFF_LENGTH
) 
  64         #elif defined(BUFF_NODROPCHECK) 
  68                 *(Buffer
->InPtr
) = Data
; 
  71                 if (Buffer
->InPtr 
== &Buffer
->Buffer
[BUFF_LENGTH
]) 
  72                   Buffer
->InPtr 
= (RingBuff_Data_t
*)&Buffer
->Buffer
; 
  76 RingBuff_Data_t 
Buffer_GetElement(RingBuff_t
* const Buffer
) 
  78         RingBuff_Data_t BuffData
; 
  82 #if defined(BUFF_EMPTYRETURNSZERO) 
  83                 if (!(Buffer
->Elements
)) 
  85 #elif !defined(BUFF_NOEMPTYCHECK) 
  86         #error No empty buffer check behavior specified. 
  89                 BuffData 
= *(Buffer
->OutPtr
); 
  94                 if (Buffer
->OutPtr 
== &Buffer
->Buffer
[BUFF_LENGTH
]) 
  95                   Buffer
->OutPtr 
= (RingBuff_Data_t
*)&Buffer
->Buffer
; 
 101 #if defined(BUFF_USEPEEK) 
 102 RingBuff_Data_t 
Buffer_PeekElement(const RingBuff_t
* const Buffer
) 
 104         RingBuff_Data_t BuffData
; 
 108 #if defined(BUFF_EMPTYRETURNSZERO) 
 109                 if (!(Buffer
->Elements
)) 
 111 #elif !defined(BUFF_NOEMPTYCHECK) 
 112         #error No empty buffer check behavior specified. 
 115                 BuffData 
= *(Buffer
->OutPtr
);