From b9eb6285dfe318738732a0f7419e98981323ebe3 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 20 May 2016 15:46:20 +0200 Subject: [PATCH] Exported libraries as submodules --- .gitmodules | 9 + usart/cppalloc | 1 + usart/cppalloc.cpp | 25 --- usart/cppalloc.h | 18 -- usart/string | 1 + usart/string.cpp | 448 -------------------------------------------- usart/string.h | 55 ------ usart/usart.cppproj | 187 +++++++++++------- usart/usart.h | 4 +- usart/vector | 1 + usart/vector.h | 188 ------------------- 11 files changed, 135 insertions(+), 802 deletions(-) create mode 100644 .gitmodules create mode 160000 usart/cppalloc delete mode 100644 usart/cppalloc.cpp delete mode 100644 usart/cppalloc.h create mode 160000 usart/string delete mode 100644 usart/string.cpp delete mode 100644 usart/string.h create mode 160000 usart/vector delete mode 100644 usart/vector.h diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..940a38b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "usart/cppalloc"] + path = usart/cppalloc + url = git@blackmark.me:cppalloc.git +[submodule "usart/string"] + path = usart/string + url = git@blackmark.me:string.git +[submodule "usart/vector"] + path = usart/vector + url = git@blackmark.me:vector.git diff --git a/usart/cppalloc b/usart/cppalloc new file mode 160000 index 0000000..72c6a6c --- /dev/null +++ b/usart/cppalloc @@ -0,0 +1 @@ +Subproject commit 72c6a6cc88d6cafecf372fe968d3befae037ad9e diff --git a/usart/cppalloc.cpp b/usart/cppalloc.cpp deleted file mode 100644 index 5180a86..0000000 --- a/usart/cppalloc.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#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 deleted file mode 100644 index ed97e7e..0000000 --- a/usart/cppalloc.h +++ /dev/null @@ -1,18 +0,0 @@ -/* -* 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/string b/usart/string new file mode 160000 index 0000000..2318991 --- /dev/null +++ b/usart/string @@ -0,0 +1 @@ +Subproject commit 23189911c6929685e962be9866ff6127938da6a8 diff --git a/usart/string.cpp b/usart/string.cpp deleted file mode 100644 index 903da99..0000000 --- a/usart/string.cpp +++ /dev/null @@ -1,448 +0,0 @@ -#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 deleted file mode 100644 index af4c2cc..0000000 --- a/usart/string.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -* 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/usart.cppproj b/usart/usart.cppproj index 1a12ec0..f8471c0 100644 --- a/usart/usart.cppproj +++ b/usart/usart.cppproj @@ -71,73 +71,123 @@ - -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" - True - 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 - True - libmlibprintf_flt - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - NDEBUG - Optimize for size (-Os) - NDEBUG - Optimize for size (-Os) - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + 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 + True + + + libm + libprintf_flt + + + + + %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 - 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 - True - libmlibprintf_flt - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - DEBUG - Optimize (-O1) - Default (-g2) - DEBUG - Optimize (-O1) - Default (-g2) - Default (-Wa,-g) - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + 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 + True + + + libm + libprintf_flt + + + + + %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" @@ -145,19 +195,19 @@ compile - + compile - + compile compile - + compile - + compile @@ -166,9 +216,14 @@ compile - + compile + + + + + \ No newline at end of file diff --git a/usart/usart.h b/usart/usart.h index 501082c..b666ff3 100644 --- a/usart/usart.h +++ b/usart/usart.h @@ -13,8 +13,8 @@ #include #include #include "Clock.h" -#include "string.h" -#include "vector.h" +#include "string/string.h" +#include "vector/vector.h" #if defined (__AVR_ATmega168A__) || defined (__AVR_ATmega328P__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega1284P__) #define USART_SPI diff --git a/usart/vector b/usart/vector new file mode 160000 index 0000000..42aed5c --- /dev/null +++ b/usart/vector @@ -0,0 +1 @@ +Subproject commit 42aed5c824ed24b019ddbe0142454ae5a9375470 diff --git a/usart/vector.h b/usart/vector.h deleted file mode 100644 index 7da1bfb..0000000 --- a/usart/vector.h +++ /dev/null @@ -1,188 +0,0 @@ -/* -* 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