my customized lib

Committer:
DuyLionTran
Date:
Sun Nov 26 15:08:14 2017 +0000
Revision:
0:8094b249013c
Initial commit

Who changed what in which revision?

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