versione corretta
Dependents: DISCO_L475VG_IOT01-Sensors-BSP
ISM43362/ATParser/BufferedSpi/Buffer/MyBuffer.cpp@0:766454e296c3, 2018-08-21 (annotated)
- Committer:
- group-Farnell24-IOT-Team
- Date:
- Tue Aug 21 08:34:28 2018 +0000
- Revision:
- 0:766454e296c3
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-Farnell24-IOT-Team | 0:766454e296c3 | 1 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 2 | /** |
group-Farnell24-IOT-Team | 0:766454e296c3 | 3 | * @file Buffer.cpp |
group-Farnell24-IOT-Team | 0:766454e296c3 | 4 | * @brief Software Buffer - Templated Ring Buffer for most data types |
group-Farnell24-IOT-Team | 0:766454e296c3 | 5 | * @author sam grove |
group-Farnell24-IOT-Team | 0:766454e296c3 | 6 | * @version 1.0 |
group-Farnell24-IOT-Team | 0:766454e296c3 | 7 | * @see |
group-Farnell24-IOT-Team | 0:766454e296c3 | 8 | * |
group-Farnell24-IOT-Team | 0:766454e296c3 | 9 | * Copyright (c) 2013 |
group-Farnell24-IOT-Team | 0:766454e296c3 | 10 | * |
group-Farnell24-IOT-Team | 0:766454e296c3 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
group-Farnell24-IOT-Team | 0:766454e296c3 | 12 | * you may not use this file except in compliance with the License. |
group-Farnell24-IOT-Team | 0:766454e296c3 | 13 | * You may obtain a copy of the License at |
group-Farnell24-IOT-Team | 0:766454e296c3 | 14 | * |
group-Farnell24-IOT-Team | 0:766454e296c3 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
group-Farnell24-IOT-Team | 0:766454e296c3 | 16 | * |
group-Farnell24-IOT-Team | 0:766454e296c3 | 17 | * Unless required by applicable law or agreed to in writing, software |
group-Farnell24-IOT-Team | 0:766454e296c3 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
group-Farnell24-IOT-Team | 0:766454e296c3 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
group-Farnell24-IOT-Team | 0:766454e296c3 | 20 | * See the License for the specific language governing permissions and |
group-Farnell24-IOT-Team | 0:766454e296c3 | 21 | * limitations under the License. |
group-Farnell24-IOT-Team | 0:766454e296c3 | 22 | */ |
group-Farnell24-IOT-Team | 0:766454e296c3 | 23 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 24 | #include "MyBuffer.h" |
group-Farnell24-IOT-Team | 0:766454e296c3 | 25 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 26 | template <class T> |
group-Farnell24-IOT-Team | 0:766454e296c3 | 27 | MyBuffer<T>::MyBuffer(uint32_t size) |
group-Farnell24-IOT-Team | 0:766454e296c3 | 28 | { |
group-Farnell24-IOT-Team | 0:766454e296c3 | 29 | _buf = new T [size]; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 30 | _size = size; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 31 | clear(); |
group-Farnell24-IOT-Team | 0:766454e296c3 | 32 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 33 | return; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 34 | } |
group-Farnell24-IOT-Team | 0:766454e296c3 | 35 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 36 | template <class T> |
group-Farnell24-IOT-Team | 0:766454e296c3 | 37 | MyBuffer<T>::~MyBuffer() |
group-Farnell24-IOT-Team | 0:766454e296c3 | 38 | { |
group-Farnell24-IOT-Team | 0:766454e296c3 | 39 | delete [] _buf; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 40 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 41 | return; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 42 | } |
group-Farnell24-IOT-Team | 0:766454e296c3 | 43 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 44 | template <class T> |
group-Farnell24-IOT-Team | 0:766454e296c3 | 45 | uint32_t MyBuffer<T>::getSize() |
group-Farnell24-IOT-Team | 0:766454e296c3 | 46 | { |
group-Farnell24-IOT-Team | 0:766454e296c3 | 47 | return this->_size; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 48 | } |
group-Farnell24-IOT-Team | 0:766454e296c3 | 49 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 50 | template <class T> |
group-Farnell24-IOT-Team | 0:766454e296c3 | 51 | uint32_t MyBuffer<T>::getNbAvailable() |
group-Farnell24-IOT-Team | 0:766454e296c3 | 52 | { |
group-Farnell24-IOT-Team | 0:766454e296c3 | 53 | if ( _wloc >= _rloc) return (_wloc - _rloc); |
group-Farnell24-IOT-Team | 0:766454e296c3 | 54 | else return (_size - _rloc + _wloc); |
group-Farnell24-IOT-Team | 0:766454e296c3 | 55 | } |
group-Farnell24-IOT-Team | 0:766454e296c3 | 56 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 57 | template <class T> |
group-Farnell24-IOT-Team | 0:766454e296c3 | 58 | void MyBuffer<T>::clear(void) |
group-Farnell24-IOT-Team | 0:766454e296c3 | 59 | { |
group-Farnell24-IOT-Team | 0:766454e296c3 | 60 | _wloc = 0; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 61 | _rloc = 0; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 62 | memset(_buf, 0, _size); |
group-Farnell24-IOT-Team | 0:766454e296c3 | 63 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 64 | return; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 65 | } |
group-Farnell24-IOT-Team | 0:766454e296c3 | 66 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 67 | template <class T> |
group-Farnell24-IOT-Team | 0:766454e296c3 | 68 | uint32_t MyBuffer<T>::peek(char c) |
group-Farnell24-IOT-Team | 0:766454e296c3 | 69 | { |
group-Farnell24-IOT-Team | 0:766454e296c3 | 70 | return 1; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 71 | } |
group-Farnell24-IOT-Team | 0:766454e296c3 | 72 | |
group-Farnell24-IOT-Team | 0:766454e296c3 | 73 | // make the linker aware of some possible types |
group-Farnell24-IOT-Team | 0:766454e296c3 | 74 | template class MyBuffer<uint8_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 75 | template class MyBuffer<int8_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 76 | template class MyBuffer<uint16_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 77 | template class MyBuffer<int16_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 78 | template class MyBuffer<uint32_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 79 | template class MyBuffer<int32_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 80 | template class MyBuffer<uint64_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 81 | template class MyBuffer<int64_t>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 82 | template class MyBuffer<char>; |
group-Farnell24-IOT-Team | 0:766454e296c3 | 83 | template class MyBuffer<wchar_t>; |