test
Dependencies: SDFileSystem mbed-dev
Fork of Nucleo_Ex06_EMU by
USBHost/myvector.h@4:53ef91c87d74, 2017-05-27 (annotated)
- Committer:
- charliex
- Date:
- Sat May 27 02:17:37 2017 +0000
- Revision:
- 4:53ef91c87d74
- Parent:
- 0:3dac1f1bc9e0
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beaglescout007 | 0:3dac1f1bc9e0 | 1 | #pragma once |
beaglescout007 | 0:3dac1f1bc9e0 | 2 | |
beaglescout007 | 0:3dac1f1bc9e0 | 3 | template<class T> |
beaglescout007 | 0:3dac1f1bc9e0 | 4 | class myvector { |
beaglescout007 | 0:3dac1f1bc9e0 | 5 | public: |
beaglescout007 | 0:3dac1f1bc9e0 | 6 | myvector() { |
beaglescout007 | 0:3dac1f1bc9e0 | 7 | m_size = 0; |
beaglescout007 | 0:3dac1f1bc9e0 | 8 | m_buf = NULL; |
beaglescout007 | 0:3dac1f1bc9e0 | 9 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 10 | ~myvector() { |
beaglescout007 | 0:3dac1f1bc9e0 | 11 | if (m_buf) { |
beaglescout007 | 0:3dac1f1bc9e0 | 12 | delete[] m_buf; |
beaglescout007 | 0:3dac1f1bc9e0 | 13 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 14 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 15 | void push_back(T v) { |
beaglescout007 | 0:3dac1f1bc9e0 | 16 | T* new_buf = new T[m_size+1]; |
beaglescout007 | 0:3dac1f1bc9e0 | 17 | if (m_size > 0) { |
beaglescout007 | 0:3dac1f1bc9e0 | 18 | for(int i = 0; i < m_size; i++) { |
beaglescout007 | 0:3dac1f1bc9e0 | 19 | new_buf[i] = m_buf[i]; |
beaglescout007 | 0:3dac1f1bc9e0 | 20 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 21 | delete[] m_buf; |
beaglescout007 | 0:3dac1f1bc9e0 | 22 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 23 | m_buf = new_buf; |
beaglescout007 | 0:3dac1f1bc9e0 | 24 | m_buf[m_size++] = v; |
beaglescout007 | 0:3dac1f1bc9e0 | 25 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 26 | T& operator[](const int index) { |
beaglescout007 | 0:3dac1f1bc9e0 | 27 | return m_buf[index]; |
beaglescout007 | 0:3dac1f1bc9e0 | 28 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 29 | int size() { return m_size; } |
beaglescout007 | 0:3dac1f1bc9e0 | 30 | |
beaglescout007 | 0:3dac1f1bc9e0 | 31 | private: |
beaglescout007 | 0:3dac1f1bc9e0 | 32 | int m_size; |
beaglescout007 | 0:3dac1f1bc9e0 | 33 | T *m_buf; |
beaglescout007 | 0:3dac1f1bc9e0 | 34 | }; |
beaglescout007 | 0:3dac1f1bc9e0 | 35 |