Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
core/arraylist.h@32:1416e015016c, 2018-12-13 (annotated)
- Committer:
- gwappa
- Date:
- Thu Dec 13 07:18:43 2018 +0000
- Revision:
- 32:1416e015016c
- Parent:
- 26:b4421d1ee57a
change to use the Staged state
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gwappa | 3:991c6d5ce19d | 1 | #ifndef ARRAYLIST_H_ |
| gwappa | 3:991c6d5ce19d | 2 | #define ARRAYLIST_H_ |
| gwappa | 3:991c6d5ce19d | 3 | |
| gwappa | 3:991c6d5ce19d | 4 | #include "mbed.h" |
| gwappa | 3:991c6d5ce19d | 5 | #include "IO.h" |
| gwappa | 3:991c6d5ce19d | 6 | |
| gwappa | 3:991c6d5ce19d | 7 | #define ARRAY_BUFFER_SIZE 256 |
| gwappa | 3:991c6d5ce19d | 8 | |
| gwappa | 3:991c6d5ce19d | 9 | template <typename T> |
| gwappa | 3:991c6d5ce19d | 10 | class ArrayList |
| gwappa | 3:991c6d5ce19d | 11 | { |
| gwappa | 3:991c6d5ce19d | 12 | public: |
| gwappa | 3:991c6d5ce19d | 13 | ArrayList(): offset(0) { } |
| gwappa | 3:991c6d5ce19d | 14 | |
| gwappa | 3:991c6d5ce19d | 15 | void add(const T& item) { |
| gwappa | 3:991c6d5ce19d | 16 | array[offset++] = item; |
| gwappa | 3:991c6d5ce19d | 17 | if (offset == ARRAY_BUFFER_SIZE) { |
| gwappa | 3:991c6d5ce19d | 18 | offset = 0; |
| gwappa | 3:991c6d5ce19d | 19 | } |
| gwappa | 3:991c6d5ce19d | 20 | } |
| gwappa | 3:991c6d5ce19d | 21 | |
| gwappa | 3:991c6d5ce19d | 22 | void clear() { |
| gwappa | 3:991c6d5ce19d | 23 | offset = 0; |
| gwappa | 3:991c6d5ce19d | 24 | } |
| gwappa | 3:991c6d5ce19d | 25 | |
| gwappa | 3:991c6d5ce19d | 26 | void writeToSerial(const T& origin=0) { |
| gwappa | 3:991c6d5ce19d | 27 | IO::write('['); |
| gwappa | 3:991c6d5ce19d | 28 | for (int i=0; i<offset; i++) { |
| gwappa | 3:991c6d5ce19d | 29 | IO::write("%d,",array[i] - origin); |
| gwappa | 3:991c6d5ce19d | 30 | } |
| gwappa | 3:991c6d5ce19d | 31 | IO::write(']'); |
| gwappa | 3:991c6d5ce19d | 32 | } |
| gwappa | 3:991c6d5ce19d | 33 | private: |
| gwappa | 3:991c6d5ce19d | 34 | int offset; |
| gwappa | 3:991c6d5ce19d | 35 | T array[ARRAY_BUFFER_SIZE]; |
| gwappa | 3:991c6d5ce19d | 36 | }; |
| gwappa | 3:991c6d5ce19d | 37 | |
| gwappa | 3:991c6d5ce19d | 38 | #endif |