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