Buffer for general purpose use. Templated for most datatypes
Dependents: BufferedSoftSerial 09_PT1000 10_PT1000 11_PT1000 ... more
Example
#include "mbed.h" #include "Buffer.h" Buffer <char> buf; int main() { buf = 'a'; buf.put('b'); char *head = buf.head(); puts(head); char whats_in_there[2] = {0}; int pos = 0; while(buf.available()) { whats_in_there[pos++] = buf; } printf("%c %c\n", whats_in_there[0], whats_in_there[1]); buf.clear(); error("done\n\n\n"); }
Diff: Buffer.h
- Revision:
- 0:5e4bca1bd5f7
- Child:
- 1:490224f41c09
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Buffer.h Fri May 10 18:34:16 2013 +0000 @@ -0,0 +1,33 @@ + +#ifndef BUFFER_H +#define BUFFER_H + +#include <stdint.h> +#include <string.h> + +template <typename T> +class Buffer +{ +private: + T *_buf; + uint32_t _wloc; + uint32_t _rloc; + uint32_t _size; + + enum BUFFER_SIZE{SMALL = 0x100, MEDIUM = 0x400, LARGE = 0x1000}; + +public: + Buffer(BUFFER_SIZE size = Buffer::SMALL); + ~Buffer(); + + void put(T data); + T get(void); + T *head(void); + void clear(void); + Buffer &operator= (T data){put(data);return *this;} + uint32_t available(void); + +}; + +#endif +