From a1f91c08ad0b4b9dd16ec4172d0218883ea87843 Mon Sep 17 00:00:00 2001 From: Lorenzo Marcantonio Date: Sun, 28 Apr 2013 17:43:26 +0200 Subject: [PATCH] Converted macros to inline template function --- include/common.h | 2 - include/macros.h | 122 ++++++++++++++++--------------------- pcbnew/class_track.cpp | 2 - pcbnew/editrack.cpp | 2 +- pcbnew/specctra_import.cpp | 2 +- 5 files changed, 56 insertions(+), 74 deletions(-) diff --git a/include/common.h b/include/common.h index 1d542fa609..d2a27d1f9b 100644 --- a/include/common.h +++ b/include/common.h @@ -116,8 +116,6 @@ enum pseudokeys { #define TEXT_ORIENT_HORIZ 0 #define TEXT_ORIENT_VERT 900 -#define ON 1 -#define OFF 0 //----------------------------------------------------------------- diff --git a/include/macros.h b/include/macros.h index f7c370f464..d9b69aaa1d 100644 --- a/include/macros.h +++ b/include/macros.h @@ -13,6 +13,8 @@ * converts a wxString to a UTF8 encoded C string for all wxWidgets build modes. * wxstring is a wxString, not a wxT() or _(). The scope of the return value * is very limited and volatile, but can be used with printf() style functions well. + * NOTE: Trying to convert it to a function is tricky because of the + * type of the parameter! */ #define TO_UTF8( wxstring ) ( (const char*) (wxstring).utf8_str() ) @@ -20,7 +22,6 @@ * function FROM_UTF8 * converts a UTF8 encoded C string to a wxString for all wxWidgets build modes. */ -//#define FROM_UTF8( cstring ) wxString::FromUTF8( cstring ) static inline wxString FROM_UTF8( const char* cstring ) { wxString line = wxString::FromUTF8( cstring ); @@ -56,82 +57,67 @@ static inline const wxChar* GetChars( const wxString& s ) #endif } -#define NEGATE( x ) (x = -x) +// This really need a function? anyway is used *a lot* of times +template inline void NEGATE( T& x ) { x = -x; } /// # of elements in an array #define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t +inline double DEG2RAD( double deg ) { return deg * M_PI / 180.0; } +inline double RAD2DEG( double rad ) { return rad * 180.0 / M_PI; } -#define DEG2RAD( Deg ) ( (Deg) * M_PI / 180.0 ) -#define RAD2DEG( Rad ) ( (Rad) * 180.0 / M_PI ) +/// Normalize angle to be in the -360.0 .. 360.0: +template inline void NORMALIZE_ANGLE_360( T& Angle ) +{ + while( Angle < -3600 ) + Angle += 3600; + while( Angle > 3600 ) + Angle -= 3600; +} -// Normalize angle to be in the -360.0 .. 360.0: -#define NORMALIZE_ANGLE_360( Angle ) { \ - while( Angle < -3600 ) \ - Angle += 3600; \ - while( Angle > 3600 ) \ - Angle -= 3600; } +/// Normalize angle to be in the 0.0 .. 360.0 range: +template inline void NORMALIZE_ANGLE_POS( T& Angle ) +{ + while( Angle < 0 ) + Angle += 3600; + while( Angle >= 3600 ) + Angle -= 3600; +} -/* Normalize angle to be in the 0.0 .. 360.0 range: */ -#define NORMALIZE_ANGLE_POS( Angle ) { \ - while( Angle < 0 ) \ - Angle += 3600; \ - while( Angle >= 3600 ) \ - Angle -= 3600; } +template inline void NEGATE_AND_NORMALIZE_ANGLE_POS( T& Angle ) +{ + Angle = -Angle; + while( Angle < 0 ) + Angle += 3600; + while( Angle >= 3600 ) + Angle -= 3600; +} -#define NEGATE_AND_NORMALIZE_ANGLE_POS( Angle ) { \ - Angle = -Angle; \ - while( Angle < 0 ) \ - Angle += 3600; \ - while( Angle >= 3600 ) \ - Angle -= 3600; } +/// Normalize angle to be in the -90.0 .. 90.0 range +template inline void NORMALIZE_ANGLE_90( T& Angle ) +{ + while( Angle < -900 ) + Angle += 1800; + while( Angle > 900 ) + Angle -= 1800; +} -/* Normalize angle to be in the -90.0 .. 90.0 range */ -#define NORMALIZE_ANGLE_90( Angle ) { \ - while( Angle < -900 ) \ - Angle += 1800; \ - while( Angle > 900 ) \ - Angle -= 1800; } - -/* Normalize angle to be in the -180.0 .. 180.0 range */ -#define NORMALIZE_ANGLE_180( Angle ) { \ - while( Angle <= -1800 ) \ - Angle += 3600; \ - while( Angle > 1800 ) \ - Angle -= 3600; } - -/*****************************/ -/* macro to exchange 2 items */ -/*****************************/ - -/* - * The EXCHG macro uses BOOST_TYPEOF for compilers that do not have native - * typeof support (MSVC). Please do not attempt to qualify these macros - * within #ifdef compiler definitions pragmas. BOOST_TYPEOF is smart enough - * to check for native typeof support and use it instead of it's own - * implementation. These macros effectively compile to nothing on platforms - * with native typeof support. - */ - -#include - -// we have to register the types used with the typeof keyword with boost -BOOST_TYPEOF_REGISTER_TYPE( wxPoint ) -BOOST_TYPEOF_REGISTER_TYPE( wxSize ) -BOOST_TYPEOF_REGISTER_TYPE( wxString ) -class DrawSheetLabelStruct; -BOOST_TYPEOF_REGISTER_TYPE( DrawSheetLabelStruct* ) -class EDA_ITEM; -BOOST_TYPEOF_REGISTER_TYPE( EDA_ITEM* ) -class D_PAD; -BOOST_TYPEOF_REGISTER_TYPE( D_PAD* ) -BOOST_TYPEOF_REGISTER_TYPE( const D_PAD* ) -class BOARD_ITEM; -BOOST_TYPEOF_REGISTER_TYPE( BOARD_ITEM* ) - -#define EXCHG( a, b ) { BOOST_TYPEOF( a ) __temp__ = (a); \ - (a) = (b); \ - (b) = __temp__; } +/// Normalize angle to be in the -180.0 .. 180.0 range +template inline void NORMALIZE_ANGLE_180( T& Angle ) +{ + while( Angle <= -1800 ) + Angle += 3600; + while( Angle > 1800 ) + Angle -= 3600; +} +/// Exchange two values; std::swap works only with arguments of the +// same type; here the compiler will figure out what to do (I hope) +template inline void EXCHG( T& a, T2& b ) +{ + T temp = a; + a = b; + b = temp; +} #endif /* ifdef MACRO_H */ diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 3d33e346ee..347efa79fe 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -162,8 +162,6 @@ wxString SEGZONE::GetSelectMenuText() const NETINFO_ITEM* net; BOARD* board = GetBoard(); - text << _( "Zone" ) << wxT( " " ) << wxString::Format( wxT( "(%08lX)" ), m_TimeStamp ); - if( board ) { net = board->FindNet( GetNet() ); diff --git a/pcbnew/editrack.cpp b/pcbnew/editrack.cpp index 651f26dd0c..465be3f831 100644 --- a/pcbnew/editrack.cpp +++ b/pcbnew/editrack.cpp @@ -460,7 +460,7 @@ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* aDC ) // creates a lock point if not exists { // Creates a lock point, if not already exists: - wxPoint hp = g_CurrentTrackSegment->GetEnd(); + wxPoint hp = g_CurrentTrackSegment->GetEnd(); LockPoint = GetBoard()->CreateLockPoint( hp, (TRACK*) LockPoint, &s_ItemsListPicker ); g_CurrentTrackSegment->SetEnd(hp); } diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp index 5a495ca4f3..988c08def3 100644 --- a/pcbnew/specctra_import.cpp +++ b/pcbnew/specctra_import.cpp @@ -320,7 +320,7 @@ SEGVIA* SPECCTRA_DB::makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNet else // VIA_MICROVIA or VIA_BLIND_BURIED { LAYER_NUM topLayerNdx = UNDEFINED_LAYER; - LAYER_NUM botLayerNdx = 7000; + LAYER_NUM botLayerNdx = 7000; // Ask Dick if this number loses its magic int viaDiam = -1; for( int i=0; i