USB Host Driver with Socket Modem support. Works with revision 323 of mbed-src but broken with any later version.
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
USBHost/mymap.h@26:53970cabf56d, 2015-06-26 (annotated)
- Committer:
- fritz291
- Date:
- Fri Jun 26 19:30:55 2015 +0000
- Revision:
- 26:53970cabf56d
- Parent:
- 12:b91fdea8c0a7
Fixed small error in testAT function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 12:b91fdea8c0a7 | 1 | #pragma once |
va009039 | 12:b91fdea8c0a7 | 2 | |
va009039 | 12:b91fdea8c0a7 | 3 | template<class K,class T> |
va009039 | 12:b91fdea8c0a7 | 4 | class mymap { |
va009039 | 12:b91fdea8c0a7 | 5 | struct mypair { |
va009039 | 12:b91fdea8c0a7 | 6 | K first; |
va009039 | 12:b91fdea8c0a7 | 7 | T second; |
va009039 | 12:b91fdea8c0a7 | 8 | }; |
va009039 | 12:b91fdea8c0a7 | 9 | public: |
va009039 | 12:b91fdea8c0a7 | 10 | mymap() { |
va009039 | 12:b91fdea8c0a7 | 11 | m_size = 0; |
va009039 | 12:b91fdea8c0a7 | 12 | } |
va009039 | 12:b91fdea8c0a7 | 13 | T& operator[](const K& key) { |
va009039 | 12:b91fdea8c0a7 | 14 | int it; |
va009039 | 12:b91fdea8c0a7 | 15 | if (count(key) == 0) { |
va009039 | 12:b91fdea8c0a7 | 16 | it = insert(key, 0); |
va009039 | 12:b91fdea8c0a7 | 17 | } else { |
va009039 | 12:b91fdea8c0a7 | 18 | it = find(key); |
va009039 | 12:b91fdea8c0a7 | 19 | } |
va009039 | 12:b91fdea8c0a7 | 20 | return m_buf[it].second; |
va009039 | 12:b91fdea8c0a7 | 21 | } |
va009039 | 12:b91fdea8c0a7 | 22 | bool empty() { return m_size == 0 ? true : false; } |
va009039 | 12:b91fdea8c0a7 | 23 | int size() { return m_size; } |
va009039 | 12:b91fdea8c0a7 | 24 | void clear() { m_size = 0; } |
va009039 | 12:b91fdea8c0a7 | 25 | int count(K key) { |
va009039 | 12:b91fdea8c0a7 | 26 | for(int i = 0; i < m_size; i++) { |
va009039 | 12:b91fdea8c0a7 | 27 | if (m_buf[i].first == key) { |
va009039 | 12:b91fdea8c0a7 | 28 | return 1; |
va009039 | 12:b91fdea8c0a7 | 29 | } |
va009039 | 12:b91fdea8c0a7 | 30 | } |
va009039 | 12:b91fdea8c0a7 | 31 | return 0; |
va009039 | 12:b91fdea8c0a7 | 32 | } |
va009039 | 12:b91fdea8c0a7 | 33 | |
va009039 | 12:b91fdea8c0a7 | 34 | private: |
va009039 | 12:b91fdea8c0a7 | 35 | int find(K key) { |
va009039 | 12:b91fdea8c0a7 | 36 | for(int i = 0; i < m_size; i++) { |
va009039 | 12:b91fdea8c0a7 | 37 | if (m_buf[i].first == key) { |
va009039 | 12:b91fdea8c0a7 | 38 | return i; |
va009039 | 12:b91fdea8c0a7 | 39 | } |
va009039 | 12:b91fdea8c0a7 | 40 | } |
va009039 | 12:b91fdea8c0a7 | 41 | return -1; |
va009039 | 12:b91fdea8c0a7 | 42 | } |
va009039 | 12:b91fdea8c0a7 | 43 | int insert(K key, T value) { |
va009039 | 12:b91fdea8c0a7 | 44 | int it = find(key); |
va009039 | 12:b91fdea8c0a7 | 45 | if (it != -1) { |
va009039 | 12:b91fdea8c0a7 | 46 | m_buf[it].second = value; |
va009039 | 12:b91fdea8c0a7 | 47 | return it; |
va009039 | 12:b91fdea8c0a7 | 48 | } |
va009039 | 12:b91fdea8c0a7 | 49 | mypair* new_buf = new mypair[m_size+1]; |
va009039 | 12:b91fdea8c0a7 | 50 | if (m_size > 0) { |
va009039 | 12:b91fdea8c0a7 | 51 | for(int i = 0; i < m_size; i++) { |
va009039 | 12:b91fdea8c0a7 | 52 | new_buf[i] = m_buf[i]; |
va009039 | 12:b91fdea8c0a7 | 53 | } |
va009039 | 12:b91fdea8c0a7 | 54 | delete[] m_buf; |
va009039 | 12:b91fdea8c0a7 | 55 | } |
va009039 | 12:b91fdea8c0a7 | 56 | m_buf = new_buf; |
va009039 | 12:b91fdea8c0a7 | 57 | it = m_size++; |
va009039 | 12:b91fdea8c0a7 | 58 | m_buf[it].first = key; |
va009039 | 12:b91fdea8c0a7 | 59 | m_buf[it].second = value; |
va009039 | 12:b91fdea8c0a7 | 60 | return it; |
va009039 | 12:b91fdea8c0a7 | 61 | } |
va009039 | 12:b91fdea8c0a7 | 62 | |
va009039 | 12:b91fdea8c0a7 | 63 | int m_size; |
va009039 | 12:b91fdea8c0a7 | 64 | mypair *m_buf; |
va009039 | 12:b91fdea8c0a7 | 65 | }; |