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