final
Dependencies: mbed FATFileSystem
Fork of KL46Z-USBHostMSD_HelloWorld by
F401RE-USBHost/USBHost/myvector.h@4:77d6450f34d7, 2015-04-04 (annotated)
- Committer:
- homzovam
- Date:
- Sat Apr 04 20:16:39 2015 +0000
- Revision:
- 4:77d6450f34d7
prijimac-funkcni final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
homzovam | 4:77d6450f34d7 | 1 | #pragma once |
homzovam | 4:77d6450f34d7 | 2 | |
homzovam | 4:77d6450f34d7 | 3 | template<class T> |
homzovam | 4:77d6450f34d7 | 4 | class myvector { |
homzovam | 4:77d6450f34d7 | 5 | public: |
homzovam | 4:77d6450f34d7 | 6 | myvector() { |
homzovam | 4:77d6450f34d7 | 7 | m_size = 0; |
homzovam | 4:77d6450f34d7 | 8 | m_buf = NULL; |
homzovam | 4:77d6450f34d7 | 9 | } |
homzovam | 4:77d6450f34d7 | 10 | void push_back(T v) { |
homzovam | 4:77d6450f34d7 | 11 | T* new_buf = new T[m_size+1]; |
homzovam | 4:77d6450f34d7 | 12 | if (m_size > 0) { |
homzovam | 4:77d6450f34d7 | 13 | for(int i = 0; i < m_size; i++) { |
homzovam | 4:77d6450f34d7 | 14 | new_buf[i] = m_buf[i]; |
homzovam | 4:77d6450f34d7 | 15 | } |
homzovam | 4:77d6450f34d7 | 16 | delete[] m_buf; |
homzovam | 4:77d6450f34d7 | 17 | } |
homzovam | 4:77d6450f34d7 | 18 | m_buf = new_buf; |
homzovam | 4:77d6450f34d7 | 19 | m_buf[m_size++] = v; |
homzovam | 4:77d6450f34d7 | 20 | } |
homzovam | 4:77d6450f34d7 | 21 | T& operator[](const int index) { |
homzovam | 4:77d6450f34d7 | 22 | return m_buf[index]; |
homzovam | 4:77d6450f34d7 | 23 | } |
homzovam | 4:77d6450f34d7 | 24 | int size() { return m_size; } |
homzovam | 4:77d6450f34d7 | 25 | |
homzovam | 4:77d6450f34d7 | 26 | private: |
homzovam | 4:77d6450f34d7 | 27 | int m_size; |
homzovam | 4:77d6450f34d7 | 28 | T *m_buf; |
homzovam | 4:77d6450f34d7 | 29 | }; |