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.
Fork of Nucleo_Ex04_USBPAD by
Diff: USBHost/myvector.h
- Revision:
- 0:b5f79b4f741d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHost/myvector.h Tue Mar 15 11:39:04 2016 +0000
@@ -0,0 +1,35 @@
+#pragma once
+
+template<class T>
+class myvector {
+public:
+ myvector() {
+ m_size = 0;
+ m_buf = NULL;
+ }
+ ~myvector() {
+ if (m_buf) {
+ delete[] m_buf;
+ }
+ }
+ void push_back(T v) {
+ T* new_buf = new T[m_size+1];
+ if (m_size > 0) {
+ for(int i = 0; i < m_size; i++) {
+ new_buf[i] = m_buf[i];
+ }
+ delete[] m_buf;
+ }
+ m_buf = new_buf;
+ m_buf[m_size++] = v;
+ }
+ T& operator[](const int index) {
+ return m_buf[index];
+ }
+ int size() { return m_size; }
+
+private:
+ int m_size;
+ T *m_buf;
+};
+
