Easily add all supported connectivity methods to your mbed OS project

Dependencies:   type-yd-driver

Committer:
MACRUM
Date:
Wed Jul 12 10:52:58 2017 +0000
Revision:
0:615f90842ce8
Initial commit

Who changed what in which revision?

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