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