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