Blame | Last modification | View Log | RSS feed
/* Copyright (c) 2005, Ira W. Snyder (devel@irasnyder.com)* All rights reserved.** Permission is hereby granted, free of charge, to any person obtaining a copy* of this software and associated documentation files (the "Software"), to* deal in the Software without restriction, including without limitation the* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or* sell copies of the Software, and to permit persons to whom the Software is* furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included in* all copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS* IN THE SOFTWARE.*/#ifndef _RING_BUFFER_H_#define _RING_BUFFER_H_#include <memory.h>#include <assert.h>#include <stdint.h>class RingBuffer{/* =============================================================================PRIVATE VARIABLES===========================================================================*/private:int32_t buffer_size; //Size of the bufferint8_t *buffer; //The buffer itselfint8_t *r_ptr; //The read pointerint8_t *w_ptr; //The write pointerint8_t *buffer_begin; //Pointer to the first byte in the bufferint8_t *buffer_end; //Pointer to the last byte in the bufferint32_t available_bytes;//The number of bytes currently stored/* =============================================================================PRIVATE FUNCTIONS===========================================================================*/private:/* =============================================================================PUBLIC FUNCTIONS===========================================================================*/public:RingBuffer (int32_t buffer_size); //Constructor~RingBuffer(); //Destructorint32_t read (int8_t *dst, int32_t bytes); //Read from the bufferbool write (int8_t *src, int32_t bytes); //Write to the bufferint32_t numBytes (); //Bytes available};#endif