Skip to content

Commit

Permalink
Enable C++98 safety.
Browse files Browse the repository at this point in the history
As the Arduino IDE team has not yet released 1.6.6 with C++11
support. This patch allows regression to older standards.

Some C++11 features will be unavailable, like streaming.
  • Loading branch information
Chris--A committed Sep 14, 2015
1 parent 1064a0d commit 4c0d475
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/PrintEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
ios::IStream<StreamExtension> os( streamer );
return os >> data;
}
#endif
#endif
1 change: 1 addition & 0 deletions src/lib/IStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

derived &input;
};

//Entry point for an IStream chain.
template< typename derived >
struct IStreamBase{
Expand Down
56 changes: 55 additions & 1 deletion src/lib/MemoryPrinter.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
/******************************************************************************** Copyright 2015 Christopher Andrews. https://github.com/Chris--A/PrintEx Released under MIT licence.********************************************************************************/ #include "MemoryPrinter.h" /******************************************************************************** EEPROMPrinter class ********************************************************************************/#ifdef __AVR__ size_t EEPROMPrinter::write( uint8_t u_Data ) { if( eeprom_read_byte( start + len ) != u_Data ) eeprom_write_byte( start + len, u_Data ); ++len; return 0x01; } size_t EEPROMPrinter::printTo(Print& p) const { for( uint16_t counter = 0 ; counter < len ; ++counter ){ p.write( ( uint8_t ) eeprom_read_byte( &start[counter] ) ); } return len; }#endif /******************************************************************************** SRAMPrinter class ********************************************************************************/ size_t SRAMPrinter::write( uint8_t data ) { start[len++] = data; return 0x01; } /******************************************************************************** PROGMEMPrinter class ********************************************************************************/#ifdef __AVR__ size_t PROGMEMPrinter::printTo(Print& p) const { size_t returnSize = 0; for( uint16_t counter = 0 ;; ++counter ){ unsigned char current = pgm_read_byte( &start[counter] ); if ( !current ) break; returnSize += p.write( current ); } return returnSize; }#endif
/********************************************************************************
Copyright 2015 Christopher Andrews.
https://github.com/Chris--A/PrintEx
Released under MIT licence.
********************************************************************************/

#include "MemoryPrinter.h"


/********************************************************************************
EEPROMPrinter class
********************************************************************************/
#ifdef __AVR__
size_t EEPROMPrinter::write( uint8_t u_Data )
{
if( eeprom_read_byte( start + len ) != u_Data )
eeprom_write_byte( start + len, u_Data );
++len;
return 0x01;
}

size_t EEPROMPrinter::printTo(Print& p) const
{
for( uint16_t counter = 0 ; counter < len ; ++counter ){
p.write( ( uint8_t ) eeprom_read_byte( &start[counter] ) );
}
return len;
}
#endif
/********************************************************************************
SRAMPrinter class
********************************************************************************/

size_t SRAMPrinter::write( uint8_t data )
{
start[len++] = data;
return 0x01;
}

/********************************************************************************
PROGMEMPrinter class
********************************************************************************/
#ifdef __AVR__
size_t PROGMEMPrinter::printTo(Print& p) const
{
size_t returnSize = 0;
for( uint16_t counter = 0 ;; ++counter ){
unsigned char current = pgm_read_byte( &start[counter] );
if ( !current ) break;
returnSize += p.write( current );
}
return returnSize;
}
#endif
3 changes: 2 additions & 1 deletion src/lib/OStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
return os << data;
}
};
#endif
}; //namespace ios
#endif

#endif
2 changes: 1 addition & 1 deletion src/lib/PrintExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
//Check for passed length.
#ifndef PRINTF_NO_WIDTH_PARAM
if( formatTest( format, CHAR_STAR ) ) width = ( unsigned int ) GetParam_int( vList );
else //Width provided in format specifier (drop to for loop below).
else //Width provided in format specifier (drop to parseValue below).
#endif

//Calculate padding width (if not provided as an extra parameter).
Expand Down
29 changes: 17 additions & 12 deletions src/lib/PrintVariadic.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@

#ifndef HEADER_PRINTVARIADIC
#define HEADER_PRINTVARIADIC

template< typename derived >
struct PrintVariadic{

derived &printx( void ){ return CRTPO; }

template< typename T, typename... U >
derived &printx( const T& t, const U&... u ){
CRTPO << t;
return printx( u... );
}
};

#ifdef ISCPP11

template< typename derived >
struct PrintVariadic{

derived &printx( void ){ return CRTPO; }

template< typename T, typename... U >
derived &printx( const T& t, const U&... u ){
CRTPO << t;
return printx( u... );
}
};
#else
template< typename derived > struct PrintVariadic{};
#endif
#endif
2 changes: 1 addition & 1 deletion src/lib/StreamExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
const pft p_Return = printer._printf( format, vList );
va_end( vList );
return p_Return;
};
};
50 changes: 26 additions & 24 deletions src/lib/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,30 @@
Determines whether D is inherited by B.
************************************************************************************* */

template<class B, class D, typename C = void> struct is_base_of;

template<class B, class D>
struct is_base_of<B,D,typename enable_if<
!is_array<D>::value &&
!is_fundamental<D>::value &&
!is_pointer<D>::value>::type
>{
template< typename T > struct dummy{};
struct Child : D, dummy<int> {};
static B* Check (B*);
template< typename T > static char Check (dummy<T>*);
static const bool value = (sizeof(Check((Child*)0)) == sizeof(B*));
};

template<class B, class D>
struct is_base_of<B,D,typename enable_if<
is_array<D>::value ||
is_fundamental<D>::value ||
is_pointer<D>::value>::type
>{
static const bool value = 0;
};


#ifdef ISCPP11
template<class B, class D, typename C = void> struct is_base_of;

template<class B, class D>
struct is_base_of<B,D,typename enable_if<
!is_array<D>::value &&
!is_fundamental<D>::value &&
!is_pointer<D>::value>::type
>{
template< typename T > struct dummy{};
struct Child : D, dummy<int> {};
static B* Check (B*);
template< typename T > static char Check (dummy<T>*);
static const bool value = (sizeof(Check((Child*)0)) == sizeof(B*));
};

template<class B, class D>
struct is_base_of<B,D,typename enable_if<
is_array<D>::value ||
is_fundamental<D>::value ||
is_pointer<D>::value>::type
>{
static const bool value = 0;
};
#endif
#endif

0 comments on commit 4c0d475

Please sign in to comment.