Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

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