Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
core/arraylist.h
- Committer:
- gwappa
- Date:
- 2018-12-13
- Revision:
- 32:1416e015016c
- Parent:
- 26:b4421d1ee57a
File content as of revision 32:1416e015016c:
#ifndef ARRAYLIST_H_ #define ARRAYLIST_H_ #include "mbed.h" #include "IO.h" #define ARRAY_BUFFER_SIZE 256 template <typename T> class ArrayList { public: ArrayList(): offset(0) { } void add(const T& item) { array[offset++] = item; if (offset == ARRAY_BUFFER_SIZE) { offset = 0; } } void clear() { offset = 0; } void writeToSerial(const T& origin=0) { IO::write('['); for (int i=0; i<offset; i++) { IO::write("%d,",array[i] - origin); } IO::write(']'); } private: int offset; T array[ARRAY_BUFFER_SIZE]; }; #endif