Usb read
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
Diff: USBHost/mymap.h
- Revision:
- 9:7f9f64cf5ded
- Child:
- 10:40c7f6788902
diff -r 6463cd1964c0 -r 7f9f64cf5ded USBHost/mymap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHost/mymap.h Mon Feb 03 13:00:16 2014 +0000 @@ -0,0 +1,53 @@ +#pragma once + +template<class K,class T> +class mymap { + struct mypair { + K key; + T value; + }; +public: + mymap() { + m_size = 0; + m_limit = 4; + m_buf = new mypair[m_limit]; + } + void put(K key, T value) { + int i = find(key); + if (i == (-1)) { + if (m_size >= m_limit) { + int new_limit = m_limit + 4; + mypair* new_buf = new mypair[new_limit]; + for(int i = 0; i < m_size; i++) { + new_buf[i] = m_buf[i]; + } + delete[] m_buf; + m_buf = new_buf; + m_limit = new_limit; + } + i = m_size++; + m_buf[i].key = key; + } + m_buf[i].value = value; + } + T get(K key) { + int i = find(key); + return (i == -1) ? NULL : m_buf[i].value; + } + bool empty() { return m_size == 0 ? true : false; } + int size() { return m_size; } + void clear() { m_size = 0; } + +private: + int find(K key) { + for(int i = 0; i < m_size; i++) { + if (m_buf[i].key == key) { + return i; + } + } + return -1; + } + int m_limit; + int m_size; + mypair *m_buf; +};