From 6ac7d71530643ee9ca476d07fa0517c2835b0b8c Mon Sep 17 00:00:00 2001 From: BlackMark Date: Thu, 19 May 2016 21:43:10 +0200 Subject: [PATCH] Initial commit --- .gitattributes | 9 + .gitignore | 5 + USART.atsln | 22 ++ USART/Clock.h | 14 ++ USART/USART.cpp | 586 ++++++++++++++++++++++++++++++++++++++++++++ USART/USART.cppproj | 158 ++++++++++++ USART/USART.h | 163 ++++++++++++ USART/cppalloc.cpp | 25 ++ USART/cppalloc.h | 18 ++ USART/main.cpp | 54 ++++ USART/string.cpp | 448 +++++++++++++++++++++++++++++++++ USART/string.h | 55 +++++ USART/vector.h | 188 ++++++++++++++ 13 files changed, 1745 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 USART.atsln create mode 100644 USART/Clock.h create mode 100644 USART/USART.cpp create mode 100644 USART/USART.cppproj create mode 100644 USART/USART.h create mode 100644 USART/cppalloc.cpp create mode 100644 USART/cppalloc.h create mode 100644 USART/main.cpp create mode 100644 USART/string.cpp create mode 100644 USART/string.h create mode 100644 USART/vector.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3e5b64f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +*.h eol=lf +*.hpp eol=lf +*.c eol=lf +*.cpp eol=lf +.git* eol=lf +*.vcxproj* eol=crlf +*.cppproj eol=crlf +*.sln eol=crlf +*.atsln eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..38e936d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vs +Release +Debug +*.componentinfo.xml +avrdude.bat diff --git a/USART.atsln b/USART.atsln new file mode 100644 index 0000000..81e3f7a --- /dev/null +++ b/USART.atsln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "USART", "USART\USART.cppproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/USART/Clock.h b/USART/Clock.h new file mode 100644 index 0000000..cbdc6c5 --- /dev/null +++ b/USART/Clock.h @@ -0,0 +1,14 @@ +/* +* Copyright (c) by BlackMark 2015 +* Date 24/11/2015 +* Version 1.1 +*/ + +#ifndef CLOCK_H +#define CLOCK_H + +#define F_CPU 16000000 + +#include + +#endif \ No newline at end of file diff --git a/USART/USART.cpp b/USART/USART.cpp new file mode 100644 index 0000000..4cbb40c --- /dev/null +++ b/USART/USART.cpp @@ -0,0 +1,586 @@ +#include "USART.h" + +////////////////////////////////////////////////////////////////////////// +uint8_t USART0::readUCSRC() +{ + uint8_t ui8UCSRC; + +#ifdef USART_SHAREDIO + ui8UCSRC = UBRRH; + ui8UCSRC = UCSRC; +#else + ui8UCSRC = *m_vui8pUCSRC; +#endif + + return ui8UCSRC; +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setUCSRC( uint8_t ui8UCSRC ) +{ +#ifdef USART_SHAREDIO + *m_vui8pUCSRC = ( 1 << URSEL ) | ui8UCSRC; +#else + *m_vui8pUCSRC = ui8UCSRC; +#endif +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setRXState( bool bEnable ) +{ + if( bEnable ) + { + *m_vui8pUCSRB |= ( 1 << m_ui8RXEN ); + } + else + { + *m_vui8pUCSRB &= ~( 1 << m_ui8RXEN ); + } +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setTXState( bool bEnable ) +{ + if( bEnable ) + { + *m_vui8pUCSRB |= ( 1 << m_ui8TXEN ); + } + else + { + *m_vui8pUCSRB &= ~( 1 << m_ui8TXEN ); + } +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setBaudRate( uint32_t ui32BaudRate ) +{ + uint16_t ui16UBRR = ( ( F_CPU / ( 16 * ui32BaudRate ) ) - 1 ); + *m_vui8pUBRRH = static_cast( ui16UBRR >> 8 ); + *m_vui8pUBRRL = static_cast( ui16UBRR ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setDataBits( uint8_t ui8DataBits ) +{ + uint8_t ui8UCSRC = readUCSRC(); + + if( ui8DataBits < 5 ) + { + ui8DataBits = 5; + } + else if( ui8DataBits > 9 ) + { + ui8DataBits = 9; + } + + if( ui8DataBits <= 8 ) + { + bool bZeroBit = ( ui8DataBits - 5 ) & 1; + bool bOneBit = ( ( ui8DataBits - 5 ) >> 1 ) & 1; + + if( bZeroBit ) + { + ui8UCSRC |= ( 1 << m_ui8UCSZ0 ); + } + else + { + ui8UCSRC &= ~( 1 << m_ui8UCSZ0 ); + } + + if( bOneBit ) + { + ui8UCSRC |= ( 1 << m_ui8UCSZ1 ); + } + else + { + ui8UCSRC &= ~( 1 << m_ui8UCSZ1 ); + } + + *m_vui8pUCSRB &= ~( 1 << m_ui8UCSZ2 ); + } + else + { + ui8UCSRC |= ( 1 << m_ui8UCSZ1 ) | ( 1 << m_ui8UCSZ0 ); + *m_vui8pUCSRB |= ( 1 << m_ui8UCSZ2 ); + } + + setUCSRC( ui8UCSRC ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setParity( Parity enmParity ) +{ + uint8_t ui8UCSRC = readUCSRC(); + + if( enmParity == Parity::DISABLED ) + { + ui8UCSRC &= ~( ( 1 << m_ui8UPM1 ) | ( 1 << m_ui8UPM0 ) ); + } + else if( enmParity == Parity::ODD ) + { + ui8UCSRC |= ( ( 1 << m_ui8UPM1 ) | ( 1 << m_ui8UPM0 ) ); + } + else if( enmParity == Parity::EVEN ) + { + ui8UCSRC &= ~( ( 1 << m_ui8UPM0 ) ); + ui8UCSRC |= ( ( 1 << m_ui8UPM1 ) ); + } + + setUCSRC( ui8UCSRC ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setStopBits( StopBit enmStopBits ) +{ + uint8_t ui8UCSRC = readUCSRC(); + + if( enmStopBits == StopBit::ONE ) + { + ui8UCSRC &= ~( 1 << m_ui8USBS ); + } + else if( enmStopBits == StopBit::TWO ) + { + ui8UCSRC |= ( 1 << m_ui8USBS ); + } + + setUCSRC( ui8UCSRC ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::setMode( Mode enmMode ) +{ + uint8_t ui8UCSRC = readUCSRC(); + +#ifdef USART_SPI + if( enmMode == Mode::ASYNCHRONOUS ) + { + ui8UCSRC &= ~( ( 1 << m_ui8UMSEL1 ) | ( 1 << m_ui8UMSEL0 ) ); + } + else if( enmMode == Mode::SYNCHRONOUS ) + { + ui8UCSRC &= ~( 1 << m_ui8UMSEL1 ); + ui8UCSRC |= ( 1 << m_ui8UMSEL0 ); + } + else if( enmMode == Mode::MASTERSPI ) + { + ui8UCSRC |= ( ( 1 << m_ui8UMSEL1 ) | ( 1 << m_ui8UMSEL0 ) ); + } +#else + if( enmMode == Mode::ASYNCHRONOUS ) + { + ui8UCSRC &= ~( 1 << m_ui8UMSEL ); + } + else if( enmMode == Mode::SYNCHRONOUS ) + { + ui8UCSRC |= ( 1 << m_ui8UMSEL ); + } +#endif + + setUCSRC( ui8UCSRC ); +} + +////////////////////////////////////////////////////////////////////////// +USART0::USART0() : USART0( 9600, 8, Parity::DISABLED, StopBit::ONE, Mode::ASYNCHRONOUS ) +{} + +////////////////////////////////////////////////////////////////////////// +USART0::USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode /* = Mode::ASYNCHRONOUS */ ) +{ +#ifdef USART_SHAREDIO + m_vui8pUCSRA = &UCSRA; + m_vui8pUCSRB = &UCSRB; + m_vui8pUCSRC = &UCSRC; + m_vui8pUBRRH = &UBRRH; + m_vui8pUBRRL = &UBRRL; + m_vui8pUDR = &UDR; + + m_ui8RXEN = RXEN; + m_ui8TXEN = TXEN; + m_ui8UCSZ0 = UCSZ0; + m_ui8UCSZ1 = UCSZ1; + m_ui8UCSZ2 = UCSZ2; + m_ui8UPM0 = UPM0; + m_ui8UPM1 = UPM1; + m_ui8USBS = USBS; + m_ui8RXC = RXC; + m_ui8UDRE = UDRE; +#endif + +#ifndef USART_SHAREDIO + m_vui8pUCSRA = &UCSR0A; + m_vui8pUCSRB = &UCSR0B; + m_vui8pUCSRC = &UCSR0C; + m_vui8pUBRRH = &UBRR0H; + m_vui8pUBRRL = &UBRR0L; + m_vui8pUDR = &UDR0; + + m_ui8RXEN = RXEN0; + m_ui8TXEN = TXEN0; + m_ui8UCSZ0 = UCSZ00; + m_ui8UCSZ1 = UCSZ01; + m_ui8UCSZ2 = UCSZ02; + m_ui8UPM0 = UPM00; + m_ui8UPM1 = UPM01; + m_ui8USBS = USBS0; + m_ui8RXC = RXC0; + m_ui8UDRE = UDRE0; +#endif + +#ifdef USART_SPI + m_ui8UMSEL0 = UMSEL00; + m_ui8UMSEL1 = UMSEL01; +#else + m_ui8UMSEL = UMSEL; +#endif + + init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode ); +} + +////////////////////////////////////////////////////////////////////////// +USART0::~USART0() +{} + +////////////////////////////////////////////////////////////////////////// +void USART0::init( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode /* = Mode::ASYNCHRONOUS */ ) +{ + setBaudRate( ui32BaudRate ); + setDataBits( ui8DataBits ); + setParity( enmParity ); + setStopBits( enmStopBits ); + setMode( enmMode ); + + setRXState( true ); + setTXState( true ); +} + +////////////////////////////////////////////////////////////////////////// +bool USART0::receiveByte( unsigned char &chData, uint32_t ui32DelayMS ) +{ + const uint8_t ui8ClockCyclesPerIteration = 6; + double dDelayS = ui32DelayMS / 1000.0; + + uint32_t ui32Iterations = static_cast( ( dDelayS * F_CPU ) / ui8ClockCyclesPerIteration ); + + do + { + if( ( *m_vui8pUCSRA & ( 1 << m_ui8RXC ) ) ) + { + chData = *m_vui8pUDR; + return true; + } + } while( --ui32Iterations > 0 ); + + return false; +} + +////////////////////////////////////////////////////////////////////////// +unsigned char USART0::receiveByte() +{ + while( !( *m_vui8pUCSRA & ( 1 << m_ui8RXC ) ) ); + + return *m_vui8pUDR; +} + +////////////////////////////////////////////////////////////////////////// +string USART0::receiveLine( string strLineTerminator /* = "\r\n" */, size_t sizeMaxSize /* = 1024 */ ) +{ + string strReceived; + + while( strReceived.length() < sizeMaxSize ) + { + strReceived += receiveByte(); + + size_t sizeLineTerminator = strReceived.rfind( strLineTerminator ); + + if( sizeLineTerminator != string::npos ) + { + strReceived = strReceived.substr( 0, sizeLineTerminator ); + break; + } + } + + return strReceived; +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( char &chReceived ) +{ + chReceived = receiveByte(); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( unsigned char &uchReceived ) +{ + uchReceived = receiveByte(); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( short int &shiReceived ) +{ + long int liInput; + receive( liInput ); + + shiReceived = static_cast( liInput ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( unsigned short int &ushiReceived ) +{ + unsigned long int uliInput; + receive( uliInput ); + + ushiReceived = static_cast( uliInput ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( int &iReceived ) +{ + long int liInput; + receive( liInput ); + + iReceived = static_cast( liInput ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( unsigned int &uiReceived ) +{ + unsigned long int uliInput; + receive( uliInput ); + + uiReceived = static_cast( uliInput ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( long int &liReceived ) +{ + string strInput; + unsigned char uchRead; + + while( !isspace( uchRead = receiveByte() ) ) + { + strInput += uchRead; + } + + liReceived = strtol( strInput.c_str(), nullptr, 10 ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( unsigned long int &uliReceived ) +{ + string strInput; + unsigned char uchRead; + + while( !isspace( uchRead = receiveByte() ) ) + { + strInput += uchRead; + } + + uliReceived = strtoul( strInput.c_str(), nullptr, 10 ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( long long int &lliReceived ) +{ + long int liInput; + receive( liInput ); + + lliReceived = liInput; +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( unsigned long long int &ulliReceived ) +{ + unsigned long int uliInput; + receive( uliInput ); + + ulliReceived = uliInput; +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( float &fReceived ) +{ + double dInput; + receive( dInput ); + + fReceived = dInput; +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( double &dReceived ) +{ + string strInput; + unsigned char uchRead; + + while( !isspace( uchRead = receiveByte() ) ) + { + strInput += uchRead; + } + + dReceived = strtod( strInput.c_str(), nullptr ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::receive( long double &ldReceived ) +{ + double dInput; + receive( dInput ); + + ldReceived = dInput; +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmitByte( unsigned char byteData ) +{ + while( !( *m_vui8pUCSRA & ( 1 << m_ui8UDRE ) ) ); + + *m_vui8pUDR = byteData; +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( string strData ) +{ + for( size_t i = 0; i < strData.length(); ++i ) + { + transmitByte( strData[i] ); + } +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( char chData ) +{ + transmitByte( chData ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( unsigned char uchData ) +{ + vector vecBuffer( 4 ); + sprintf( vecBuffer.data(), "%hhu", uchData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( short int shiData ) +{ + vector vecBuffer( 6 ); + sprintf( vecBuffer.data(), "%hd", shiData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( unsigned short int ushiData ) +{ + vector vecBuffer( 6 ); + sprintf( vecBuffer.data(), "%hu", ushiData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( int iData ) +{ + vector vecBuffer( 6 ); + sprintf( vecBuffer.data(), "%d", iData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( unsigned int uiData ) +{ + vector vecBuffer( 6 ); + sprintf( vecBuffer.data(), "%u", uiData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( long int liData ) +{ + vector vecBuffer( 11 ); + sprintf( vecBuffer.data(), "%ld", liData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( unsigned long int uliData ) +{ + vector vecBuffer( 11 ); + sprintf( vecBuffer.data(), "%lu", uliData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( long long int lliData ) +{ + vector vecBuffer( 21 ); + sprintf( vecBuffer.data(), "%lld", lliData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( unsigned long long int ulliData ) +{ + vector vecBuffer( 21 ); + sprintf( vecBuffer.data(), "%llu", ulliData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( float fData ) +{ + vector vecBuffer( 64 ); + sprintf( vecBuffer.data(), "%f", static_cast( fData ) ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( double dData ) +{ + vector vecBuffer( 64 ); + sprintf( vecBuffer.data(), "%f", dData ); + transmit( vecBuffer.data() ); +} + +////////////////////////////////////////////////////////////////////////// +void USART0::transmit( long double ldData ) +{ + vector vecBuffer( 64 ); + sprintf( vecBuffer.data(), "%f", static_cast( ldData ) ); + transmit( vecBuffer.data() ); +} + +#ifdef SECOND_USART + +////////////////////////////////////////////////////////////////////////// +USART1::USART1() : USART1( 9600, 8, Parity::DISABLED, StopBit::ONE, Mode::ASYNCHRONOUS ) +{} + +////////////////////////////////////////////////////////////////////////// +USART1::USART1( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode /* = Mode::ASYNCHRONOUS */ ) +{ + m_vui8pUCSRA = &UCSR1A; + m_vui8pUCSRB = &UCSR1B; + m_vui8pUCSRC = &UCSR1C; + m_vui8pUBRRH = &UBRR1H; + m_vui8pUBRRL = &UBRR1L; + m_vui8pUDR = &UDR1; + + m_ui8RXEN = RXEN1; + m_ui8TXEN = TXEN1; + m_ui8UCSZ0 = UCSZ10; + m_ui8UCSZ1 = UCSZ11; + m_ui8UCSZ2 = UCSZ12; + m_ui8UPM0 = UPM10; + m_ui8UPM1 = UPM11; + m_ui8USBS = USBS1; + m_ui8RXC = RXC1; + m_ui8UDRE = UDRE1; + m_ui8UMSEL0 = UMSEL10; + m_ui8UMSEL1 = UMSEL11; + + init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode ); +} + +////////////////////////////////////////////////////////////////////////// +USART1::~USART1() +{} + +#endif \ No newline at end of file diff --git a/USART/USART.cppproj b/USART/USART.cppproj new file mode 100644 index 0000000..2f997d1 --- /dev/null +++ b/USART/USART.cppproj @@ -0,0 +1,158 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.CPP + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATmega328P + none + Executable + CPP + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + USART + USART + USART + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + + + + + + + + + + + + + com.atmel.avrdbg.tool.stk500 + + 0x1E950F + + + + 1843200 + + ISP + + com.atmel.avrdbg.tool.stk500 + + + STK500 + + ISP + 1843200 + + + + + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + True + True + True + False + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + -Wextra -std=c++11 + libm + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + NDEBUG + Optimize for size (-Os) + NDEBUG + Optimize for size (-Os) + + + echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" + + + + + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + True + True + True + False + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + -Wextra -std=c++11 + libm + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + DEBUG + Optimize (-O1) + Default (-g2) + DEBUG + Optimize (-O1) + Default (-g2) + Default (-Wa,-g) + + + echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" + + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/USART/USART.h b/USART/USART.h new file mode 100644 index 0000000..29ed50a --- /dev/null +++ b/USART/USART.h @@ -0,0 +1,163 @@ +/* +* Copyright (c) by BlackMark 2015-2016 +* Date 05/01/2016 +* Version 2.2 +*/ + +#ifndef USART_H +#define USART_H + +#include +#include +#include +#include +#include +#include "Clock.h" +#include "string.h" +#include "vector.h" + +#if defined (__AVR_ATmega168A__) || defined (__AVR_ATmega328P__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega1284P__) +#define USART_SPI +#endif +#if defined (__AVR_ATmega32A__) || (__AVR_ATmega8__) +#define USART_SHAREDIO +#endif +#if defined (__AVR_ATmega1284P__) +#define SECOND_USART +#endif + +class USART0 +{ +public: + enum class Mode + { + ASYNCHRONOUS = 0, + SYNCHRONOUS = 1, +#ifdef USART_SPI + MASTERSPI = 2 +#endif + }; + + enum class Parity + { + DISABLED = 0, + ODD = 1, + EVEN = 2 + }; + + enum class StopBit + { + ONE = 1, + TWO = 2 + }; + +protected: + volatile uint8_t *m_vui8pUCSRA; + volatile uint8_t *m_vui8pUCSRB; + volatile uint8_t *m_vui8pUCSRC; + volatile uint8_t *m_vui8pUBRRH; + volatile uint8_t *m_vui8pUBRRL; + volatile uint8_t *m_vui8pUDR; + + uint8_t m_ui8RXEN; + uint8_t m_ui8TXEN; + uint8_t m_ui8UCSZ0; + uint8_t m_ui8UCSZ1; + uint8_t m_ui8UCSZ2; + uint8_t m_ui8UPM0; + uint8_t m_ui8UPM1; + uint8_t m_ui8USBS; + uint8_t m_ui8RXC; + uint8_t m_ui8UDRE; + +#ifdef USART_SPI + uint8_t m_ui8UMSEL0; + uint8_t m_ui8UMSEL1; +#else + uint8_t m_ui8UMSEL; +#endif + +private: + uint8_t readUCSRC(); + void setUCSRC( uint8_t ui8UCSRC ); + + void setRXState( bool bEnable ); + void setTXState( bool bEnable ); + void setBaudRate( uint32_t ui32BaudRate ); + void setDataBits( uint8_t ui8DataBits ); + void setParity( Parity enmParity ); + void setStopBits( StopBit enmStopBits ); + void setMode( Mode enmMode ); + +public: + USART0(); + USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode = Mode::ASYNCHRONOUS ); + ~USART0(); + + void init( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode = Mode::ASYNCHRONOUS ); + + bool receiveByte( unsigned char &chData, uint32_t ui32DelayMS ); + unsigned char receiveByte(); + string receiveLine( string strLineTerminator = "\r\n", size_t sizeMaxSize = 1024 ); + + void receive( char &chReceived ); + void receive( unsigned char &uchReceived ); + void receive( short int &shiReceived ); + void receive( unsigned short int &ushiReceived ); + void receive( int &iReceived ); + void receive( unsigned int &uiReceived ); + void receive( long int &liReceived ); + void receive( unsigned long int &uliReceived ); + void receive( long long int &lliReceived ); + void receive( unsigned long long int &ulliReceived ); + void receive( float &fReceived ); + void receive( double &dReceived ); + void receive( long double &ldReceived ); + + void transmitByte( unsigned char byteData ); + void transmit( string strData ); + + void transmit( char chData ); + void transmit( unsigned char uchData ); + void transmit( short int shiData ); + void transmit( unsigned short int ushiData ); + void transmit( int iData ); + void transmit( unsigned int uiData ); + void transmit( long int liData ); + void transmit( unsigned long int uliData ); + void transmit( long long int lliData ); + void transmit( unsigned long long int ulliData ); + void transmit( float fData ); + void transmit( double dData ); + void transmit( long double ldData ); + + ////////////////////////////////////////////////////////////////////////// + template + USART0& operator<<( const T &RHS ) + { + transmit( RHS ); + return *this; + } + + ////////////////////////////////////////////////////////////////////////// + template + USART0& operator>>( T &RHS ) + { + receive( RHS ); + return *this; + } +}; + +#ifdef SECOND_USART + +class USART1 : public USART0 +{ +public: + USART1(); + USART1( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode = Mode::ASYNCHRONOUS ); + ~USART1(); +}; + +#endif + +#endif \ No newline at end of file diff --git a/USART/cppalloc.cpp b/USART/cppalloc.cpp new file mode 100644 index 0000000..5180a86 --- /dev/null +++ b/USART/cppalloc.cpp @@ -0,0 +1,25 @@ +#include "cppalloc.h" + +////////////////////////////////////////////////////////////////////////// +void* operator new( size_t sizeSize ) +{ + return malloc( sizeSize ); +} + +////////////////////////////////////////////////////////////////////////// +void operator delete( void* pAddress ) +{ + free( pAddress ); +} + +////////////////////////////////////////////////////////////////////////// +void* operator new[]( size_t sizeSize ) +{ + return malloc( sizeSize ); +} + +////////////////////////////////////////////////////////////////////////// +void operator delete[]( void* pAddress ) +{ + free( pAddress ); +} \ No newline at end of file diff --git a/USART/cppalloc.h b/USART/cppalloc.h new file mode 100644 index 0000000..ed97e7e --- /dev/null +++ b/USART/cppalloc.h @@ -0,0 +1,18 @@ +/* +* Copyright (c) by BlackMark 2015 +* Date 24/11/2015 +* Version 1.3 +*/ + +#ifndef CPPALLOC_H +#define CPPALLOC_H + +#include + +void* operator new( size_t sizeSize ); +void operator delete( void* pAddress ); + +void* operator new[]( size_t sizeSize ); +void operator delete[]( void* pAddress ); + +#endif \ No newline at end of file diff --git a/USART/main.cpp b/USART/main.cpp new file mode 100644 index 0000000..0c6b7ae --- /dev/null +++ b/USART/main.cpp @@ -0,0 +1,54 @@ +/* +* Copyright (c) by BlackMark 2015-2016 +* Date 05/01/2016 +* Version 1.4 +*/ + +#include +#include "Clock.h" +#include "USART.h" + +int main() +{ + USART0 cUSART; + + uint32_t ui32Counter = 0; + + cUSART << "\r\nSizes: \r\n"; + cUSART << "sizeof( char ) = " << sizeof( char ) << "\r\n"; + cUSART << "sizeof( unsigned char ) = " << sizeof( unsigned char ) << "\r\n"; + cUSART << "sizeof( short int ) = " << sizeof( short int ) << "\r\n"; + cUSART << "sizeof( unsigned short int ) = " << sizeof( unsigned short int ) << "\r\n"; + cUSART << "sizeof( int ) = " << sizeof( int ) << "\r\n"; + cUSART << "sizeof( unsigned int ) = " << sizeof( unsigned int ) << "\r\n"; + cUSART << "sizeof( long int ) = " << sizeof( long int ) << "\r\n"; + cUSART << "sizeof( unsigned long int ) = " << sizeof( unsigned long int ) << "\r\n"; + cUSART << "sizeof( long long int ) = " << sizeof( long long int ) << "\r\n"; + cUSART << "sizeof( unsigned long long int ) = " << sizeof( unsigned long long int ) << "\r\n"; + cUSART << "sizeof( float ) = " << sizeof( float ) << "\r\n"; + cUSART << "sizeof( double ) = " << sizeof( double ) << "\r\n"; + cUSART << "sizeof( long double ) = " << sizeof( long double ) << "\r\n\r\n"; + + while( true ) + { + cUSART << "This has been running for \"" << ui32Counter++ << "\" seconds!\r\n\r\n"; + + cUSART << "Please enter a number: "; + + int iNumber; + cUSART >> iNumber; + + cUSART << "\r\nYou entered: " << iNumber << "\r\n\r\n"; + + cUSART << "Please enter a decimal number: "; + + double dNumber; + cUSART >> dNumber; + + cUSART << "\r\nYou entered: " << dNumber << "\r\n\r\n"; + + _delay_ms( 1000 ); + } + + return 0; +} \ No newline at end of file diff --git a/USART/string.cpp b/USART/string.cpp new file mode 100644 index 0000000..903da99 --- /dev/null +++ b/USART/string.cpp @@ -0,0 +1,448 @@ +#include "string.h" + +////////////////////////////////////////////////////////////////////////// +string::string() : +m_sizeLength( 0 ), m_sizeCapacity( 1 ), m_szString( nullptr ) +{ + m_szString = new char[m_sizeCapacity]; + + if( !m_szString ) + { + return; + } + + m_szString[m_sizeLength] = '\0'; +} + +////////////////////////////////////////////////////////////////////////// +string::string( const string &strString ) : +m_sizeLength( strString.m_sizeLength ), m_sizeCapacity( strString.m_sizeCapacity ), m_szString( nullptr ) +{ + m_szString = new char[m_sizeCapacity]; + + if( !m_szString ) + { + return; + } + + memcpy( m_szString, strString.m_szString, m_sizeCapacity * sizeof( char ) ); +} + +////////////////////////////////////////////////////////////////////////// +string::string( const char* szString ) : +m_sizeLength( strlen( szString ) ), m_sizeCapacity( strlen( szString ) + 1 ), m_szString( nullptr ) +{ + m_szString = new char[m_sizeCapacity]; + + if( !m_szString ) + { + return; + } + + memcpy( m_szString, szString, m_sizeLength * sizeof( char ) ); + m_szString[m_sizeLength] = '\0'; +} + +////////////////////////////////////////////////////////////////////////// +string::string( char chCharacter ) : +m_sizeLength( 1 ), m_sizeCapacity( 2 ), m_szString( nullptr ) +{ + m_szString = new char[m_sizeCapacity]; + + if( !m_szString ) + { + return; + } + + m_szString[0] = chCharacter; + m_szString[m_sizeLength] = '\0'; +} + +////////////////////////////////////////////////////////////////////////// +string::string( size_t sizeLength, char chCharacter ) : +m_sizeLength( sizeLength ), m_sizeCapacity( sizeLength + 1 ), m_szString( nullptr ) +{ + m_szString = new char[m_sizeCapacity]; + + if( !m_szString ) + { + return; + } + + for( size_t i = 0; i < sizeLength; ++i ) + { + m_szString[i] = chCharacter; + } + + m_szString[m_sizeLength] = '\0'; +} + +////////////////////////////////////////////////////////////////////////// +string::~string() +{ + delete [] m_szString; +} + +////////////////////////////////////////////////////////////////////////// +string &string::append( const string& strString ) +{ + if( m_sizeLength + strString.m_sizeLength >= m_sizeCapacity ) + { + char* szCopyString = new char[m_sizeLength + strString.m_sizeLength + 1]; + + if( !szCopyString ) + { + return *this; + } + + memcpy( szCopyString, m_szString, m_sizeLength * sizeof( char ) ); + delete [] m_szString; + + m_sizeCapacity = m_sizeLength + strString.m_sizeLength + 1; + m_szString = szCopyString; + } + + memcpy( m_szString + m_sizeLength, strString.m_szString, strString.m_sizeLength * sizeof( char ) ); + m_sizeLength = m_sizeLength + strString.m_sizeLength; + m_szString[m_sizeLength] = '\0'; + + return *this; +} + +////////////////////////////////////////////////////////////////////////// +char& string::at( size_t sizeIndex ) +{ + if( sizeIndex >= m_sizeLength ) + { + return m_szString[m_sizeLength - 1]; + } + + return m_szString[sizeIndex]; +} + +////////////////////////////////////////////////////////////////////////// +const char& string::at( size_t sizeIndex ) const +{ + if( sizeIndex >= m_sizeLength ) + { + return m_szString[m_sizeLength - 1]; + } + + return m_szString[sizeIndex]; +} + +////////////////////////////////////////////////////////////////////////// +size_t string::capacity() const +{ + return m_sizeCapacity; +} + +////////////////////////////////////////////////////////////////////////// +void string::clear() +{ + m_sizeLength = 0; + m_szString[m_sizeLength] = '\0'; +} + +////////////////////////////////////////////////////////////////////////// +const char* string::c_str() const +{ + return m_szString; +} + +////////////////////////////////////////////////////////////////////////// +const char* string::data() const +{ + return m_szString; +} + +////////////////////////////////////////////////////////////////////////// +bool string::empty() const +{ + if( m_sizeLength == 0 ) + { + return true; + } + + return false; +} + +////////////////////////////////////////////////////////////////////////// +size_t string::find( const string &strString, size_t sizePos /* = 0 */ ) const +{ + if( strString.empty() || sizePos >= m_sizeLength ) + { + return npos; + } + + for( size_t i = sizePos; i < m_sizeLength; ++i ) + { + if( i + strString.length() > m_sizeLength ) + { + return npos; + } + + if( m_szString[i] == strString[0] ) + { + size_t sizeFound; + + for( sizeFound = 1; sizeFound < strString.size(); ++sizeFound ) + { + if( m_szString[i + sizeFound] != strString[sizeFound] ) + { + break; + } + } + + if( sizeFound == strString.size() ) + { + return i; + } + } + } + + return npos; +} + +////////////////////////////////////////////////////////////////////////// +size_t string::length() const +{ + return m_sizeLength; +} + +////////////////////////////////////////////////////////////////////////// +void string::push_back( char chCharacter ) +{ + if( m_sizeLength + 1 >= m_sizeCapacity ) + { + char* szCopyString = new char[m_sizeLength + 2]; + + if( !szCopyString ) + { + return; + } + + memcpy( szCopyString, m_szString, m_sizeLength * sizeof( char ) ); + delete [] m_szString; + + m_sizeCapacity = m_sizeLength + 2; + m_szString = szCopyString; + } + + m_szString[m_sizeLength++] = chCharacter; + m_szString[m_sizeLength] = '\0'; +} + +////////////////////////////////////////////////////////////////////////// +void string::reserve( size_t sizeCapacity /* = 0 */ ) +{ + if( sizeCapacity > m_sizeCapacity ) + { + char* szCopyString = new char[sizeCapacity]; + + if( !szCopyString ) + { + return; + } + + memcpy( szCopyString, m_szString, m_sizeLength * sizeof( char ) ); + delete [] m_szString; + + szCopyString[m_sizeLength] = '\0'; + + m_sizeCapacity = sizeCapacity; + m_szString = szCopyString; + } +} + +////////////////////////////////////////////////////////////////////////// +void string::resize( size_t sizeLength, char chCharacter ) +{ + if( sizeLength < m_sizeLength ) + { + m_sizeLength = sizeLength; + m_szString[m_sizeLength] = '\0'; + } + else if( sizeLength > m_sizeLength ) + { + if( sizeLength + 1 > m_sizeCapacity ) + { + char* szCopyString = new char[sizeLength + 1]; + + if( !szCopyString ) + { + return; + } + + memcpy( szCopyString, m_szString, m_sizeLength * sizeof( char ) ); + delete [] m_szString; + + for( size_t i = m_sizeLength; i < sizeLength; ++i ) + { + szCopyString[i] = chCharacter; + } + szCopyString[sizeLength] = '\0'; + + m_sizeLength = sizeLength; + m_sizeCapacity = m_sizeLength + 1; + m_szString = szCopyString; + } + else + { + for( size_t i = m_sizeLength; i < sizeLength; ++i ) + { + m_szString[i] = chCharacter; + } + m_szString[sizeLength] = '\0'; + + m_sizeLength = sizeLength; + } + } +} + +////////////////////////////////////////////////////////////////////////// +size_t string::rfind( const string &strString, size_t sizePos /* = npos */ ) const +{ + if( sizePos == npos ) + { + sizePos = m_sizeLength - 1; + } + + if( strString.empty() || sizePos >= m_sizeLength ) + { + return npos; + } + + for( size_t i = sizePos + 1; i-- > 0; ) + { + if( i - ( strString.length() - 1 ) > m_sizeLength ) + { + return npos; + } + + if( m_szString[i] == strString[strString.length() - 1] ) + { + size_t sizeFound; + + for( sizeFound = strString.length() - 1; sizeFound-- > 0; ) + { + if( m_szString[i - ( strString.length() - ( sizeFound + 1 ) )] != strString[sizeFound] ) + { + break; + } + } + + if( sizeFound == npos ) + { + return i - ( strString.length() - 1 ); + } + } + } + + return npos; +} + +////////////////////////////////////////////////////////////////////////// +size_t string::size() const +{ + return m_sizeLength; +} + +////////////////////////////////////////////////////////////////////////// +string string::substr( size_t sizePos /* = 0 */, size_t sizeLength /* = npos */ ) const +{ + if( sizePos >= m_sizeLength ) + { + return string(); + } + + string strSubString; + + for( size_t i = sizePos; i < sizePos + sizeLength; ++i ) + { + if( i >= m_sizeLength ) + { + break; + } + + strSubString += m_szString[i]; + } + + return strSubString; +} + +////////////////////////////////////////////////////////////////////////// +string& string::operator=( const string &strRHS ) +{ + char* szCopyString = new char[strRHS.m_sizeCapacity]; + + if( !szCopyString ) + { + return *this; + } + + m_sizeLength = strRHS.m_sizeLength; + m_sizeCapacity = strRHS.m_sizeCapacity; + + memcpy( szCopyString, strRHS.m_szString, m_sizeCapacity * sizeof( char ) ); + delete [] m_szString; + + m_szString = szCopyString; + + return *this; +} + +////////////////////////////////////////////////////////////////////////// +char &string::operator[]( size_t sizeIndex ) +{ + return m_szString[sizeIndex]; +} + +////////////////////////////////////////////////////////////////////////// +const char &string::operator[]( size_t sizeIndex ) const +{ + return m_szString[sizeIndex]; +} + +////////////////////////////////////////////////////////////////////////// +string string::operator+( const string &strRHS ) const +{ + string strReturn = *this; + + strReturn.append( strRHS ); + + return strReturn; +} + +////////////////////////////////////////////////////////////////////////// +string &string::operator+=( const string &strRHS ) +{ + append( strRHS ); + + return *this; +} + +////////////////////////////////////////////////////////////////////////// +bool string::operator==( const string &strRHS ) const +{ + if( size() != strRHS.size() ) + { + return false; + } + + for( size_t i = 0; i < size(); ++i ) + { + if( m_szString[i] != strRHS.m_szString[i] ) + { + return false; + } + } + + return true; +} + +////////////////////////////////////////////////////////////////////////// +bool string::operator!=( const string &strRHS ) const +{ + return !( *this == strRHS ); +} \ No newline at end of file diff --git a/USART/string.h b/USART/string.h new file mode 100644 index 0000000..af4c2cc --- /dev/null +++ b/USART/string.h @@ -0,0 +1,55 @@ +/* +* Copyright (c) by BlackMark 2015 +* Date 26/11/2015 +* Version 1.4 +*/ + +#ifndef STRING_H +#define STRING_H + +#include + +class string +{ +private: + size_t m_sizeLength; + size_t m_sizeCapacity; + char* m_szString; + +public: + static const size_t npos = -1; + + string(); + string( const string &strString ); + string( const char* szString ); + string( char chCharacter ); + string( size_t sizeLength, char chCharacter ); + ~string(); + + string& append( const string &strString ); + char& at( size_t sizeIndex ); + const char& at( size_t sizeIndex ) const; + size_t capacity() const; + void clear(); + const char* c_str() const; + const char* data() const; + bool empty() const; + size_t find( const string &strString, size_t sizePos = 0 ) const; + size_t length() const; + void push_back( char chCharacter ); + void reserve( size_t sizeCapacity = 0 ); + void resize( size_t sizeLength, char chCharacter = '\0' ); + size_t rfind( const string &strString, size_t sizePos = npos ) const; + size_t size() const; + string substr( size_t sizePos = 0, size_t sizeLength = npos ) const; + + string& operator=( const string &strRHS ); + char& operator[]( size_t sizeIndex ); + const char& operator[]( size_t sizeIndex ) const; + string operator+( const string &strRHS ) const; + string& operator+=( const string &strRHS ); + bool operator==( const string &strRHS ) const; + bool operator!=( const string &strRHS ) const; +}; + +#endif \ No newline at end of file diff --git a/USART/vector.h b/USART/vector.h new file mode 100644 index 0000000..7da1bfb --- /dev/null +++ b/USART/vector.h @@ -0,0 +1,188 @@ +/* +* Copyright (c) by BlackMark 2015 +* Date 06/12/2015 +* Version 1.6 +*/ + +#ifndef VECTOR_H +#define VECTOR_H + +#include +#include +#include "cppalloc.h" + +template +class vector +{ +private: + size_t m_sizeSize; + size_t m_sizeCapacity; + T* m_pData; + + ////////////////////////////////////////////////////////////////////////// + void extend() + { + m_sizeCapacity = ( ( m_sizeCapacity > 0 ) ? ( 2 * m_sizeCapacity ) : ( 1 ) ); + + T *pCopyData = new T[m_sizeCapacity]; + memcpy( pCopyData, m_pData, m_sizeSize * sizeof( T ) ); + + delete [] m_pData; + m_pData = pCopyData; + } + +public: + ////////////////////////////////////////////////////////////////////////// + vector() : + m_sizeSize( 0 ), m_sizeCapacity( 0 ), m_pData( nullptr ) + {} + + ////////////////////////////////////////////////////////////////////////// + vector( size_t sizeSize, const T &Value = T() ) : + m_sizeSize( sizeSize ), m_sizeCapacity( sizeSize ), m_pData( nullptr ) + { + m_pData = new T[m_sizeCapacity]; + + for( size_t i = 0; i < m_sizeSize; ++i ) + { + m_pData[i] = Value; + } + } + + ////////////////////////////////////////////////////////////////////////// + vector( const vector &vecVector ) : + m_sizeSize( vecVector.m_sizeSize ), m_sizeCapacity( vecVector.m_sizeCapacity ), m_pData( nullptr ) + { + m_pData = new T[m_sizeCapacity]; + memcpy( m_pData, vecVector.m_pData, m_sizeSize * sizeof( T ) ); + } + + ////////////////////////////////////////////////////////////////////////// + vector( vector &&vecVector ) : + m_sizeSize( vecVector.m_sizeSize ), m_sizeCapacity( vecVector.m_sizeCapacity ), m_pData( vecVector.m_pData ) + { + vecVector.m_sizeSize = 0; + vecVector.m_sizeCapacity = 0; + vecVector.m_pData = nullptr; + } + + ////////////////////////////////////////////////////////////////////////// + ~vector() + { + delete [] m_pData; + } + + ////////////////////////////////////////////////////////////////////////// + vector& operator=( const vector &vecRHS ) + { + m_sizeSize = vecRHS.m_sizeSize; + m_sizeCapacity = vecRHS.m_sizeCapacity; + m_pData = new T[m_sizeCapacity]; + memcpy( m_pData, vecRHS.m_pData, m_sizeSize * sizeof( T ) ); + + return *this; + } + + ////////////////////////////////////////////////////////////////////////// + vector& operator=( vector &&vecRHS ) + { + m_sizeSize = vecRHS.m_sizeSize; + m_sizeCapacity = vecRHS.m_sizeCapacity; + delete [] m_pData; + m_pData = vecRHS.m_pData; + + vecRHS.m_sizeSize = 0; + vecRHS.m_sizeCapacity = 0; + vecRHS.m_pData = nullptr; + + return *this; + } + + ////////////////////////////////////////////////////////////////////////// + T* data() + { + return m_pData; + } + + ////////////////////////////////////////////////////////////////////////// + const T* data() const + { + return m_pData; + } + + ////////////////////////////////////////////////////////////////////////// + void clear() + { + delete [] m_pData; + m_pData = nullptr; + m_sizeSize = 0; + m_sizeCapacity = 0; + } + + ////////////////////////////////////////////////////////////////////////// + void push_back( T const &Data ) + { + if( m_sizeSize == m_sizeCapacity ) + { + extend(); + } + + m_pData[m_sizeSize++] = Data; + } + + ////////////////////////////////////////////////////////////////////////// + void resize( size_t sizeSize, T val = T() ) + { + if( sizeSize != m_sizeSize ) + { + m_sizeCapacity = sizeSize; + + T *pCopyData = new T[m_sizeCapacity]; + memcpy( pCopyData, m_pData, ( ( sizeSize < m_sizeSize ) ? ( sizeSize ) : ( m_sizeSize ) ) * sizeof( T ) ); + + delete [] m_pData; + m_pData = pCopyData; + + if( sizeSize > m_sizeSize ) + { + for( size_t i = m_sizeSize; i < sizeSize; ++i ) + { + m_pData[i] = val; + } + } + + m_sizeSize = sizeSize; + } + } + + ////////////////////////////////////////////////////////////////////////// + size_t size() const + { + return m_sizeSize; + } + + ////////////////////////////////////////////////////////////////////////// + bool empty() const + { + if( m_sizeSize == 0 ) + { + return true; + } + + return false; + } + + ////////////////////////////////////////////////////////////////////////// + const T& operator[]( size_t sizeIndex ) const + { + return m_pData[sizeIndex]; + } + + ////////////////////////////////////////////////////////////////////////// + T& operator[]( size_t sizeIndex ) + { + return m_pData[sizeIndex]; + } +}; + +#endif \ No newline at end of file