Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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