Commit 6b500d60 authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

Converted macros to inline template function

parent 3b1ddd95
...@@ -116,8 +116,6 @@ enum pseudokeys { ...@@ -116,8 +116,6 @@ enum pseudokeys {
#define TEXT_ORIENT_HORIZ 0 #define TEXT_ORIENT_HORIZ 0
#define TEXT_ORIENT_VERT 900 #define TEXT_ORIENT_VERT 900
#define ON 1
#define OFF 0
//-----<KiROUND KIT>------------------------------------------------------------ //-----<KiROUND KIT>------------------------------------------------------------
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
* converts a wxString to a UTF8 encoded C string for all wxWidgets build modes. * 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 * 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. * 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() ) #define TO_UTF8( wxstring ) ( (const char*) (wxstring).utf8_str() )
...@@ -20,7 +22,6 @@ ...@@ -20,7 +22,6 @@
* function FROM_UTF8 * function FROM_UTF8
* converts a UTF8 encoded C string to a wxString for all wxWidgets build modes. * 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 ) static inline wxString FROM_UTF8( const char* cstring )
{ {
wxString line = wxString::FromUTF8( cstring ); wxString line = wxString::FromUTF8( cstring );
...@@ -56,82 +57,67 @@ static inline const wxChar* GetChars( const wxString& s ) ...@@ -56,82 +57,67 @@ static inline const wxChar* GetChars( const wxString& s )
#endif #endif
} }
#define NEGATE( x ) (x = -x) // This really need a function? anyway is used *a lot* of times
template<class T> inline void NEGATE( T& x ) { x = -x; }
/// # of elements in an array /// # of elements in an array
#define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t #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 ) /// Normalize angle to be in the -360.0 .. 360.0:
#define RAD2DEG( Rad ) ( (Rad) * 180.0 / M_PI ) template<class T> inline void NORMALIZE_ANGLE_360( T& Angle )
{
// Normalize angle to be in the -360.0 .. 360.0: while( Angle < -3600 )
#define NORMALIZE_ANGLE_360( Angle ) { \ Angle += 3600;
while( Angle < -3600 ) \ while( Angle > 3600 )
Angle += 3600; \ Angle -= 3600;
while( Angle > 3600 ) \ }
Angle -= 3600; }
/// Normalize angle to be in the 0.0 .. 360.0 range:
/* Normalize angle to be in the 0.0 .. 360.0 range: */ template<class T> inline void NORMALIZE_ANGLE_POS( T& Angle )
#define NORMALIZE_ANGLE_POS( Angle ) { \ {
while( Angle < 0 ) \ while( Angle < 0 )
Angle += 3600; \ Angle += 3600;
while( Angle >= 3600 ) \ while( Angle >= 3600 )
Angle -= 3600; } Angle -= 3600;
}
#define NEGATE_AND_NORMALIZE_ANGLE_POS( Angle ) { \
Angle = -Angle; \ template<class T> inline void NEGATE_AND_NORMALIZE_ANGLE_POS( T& Angle )
while( Angle < 0 ) \ {
Angle += 3600; \ Angle = -Angle;
while( Angle >= 3600 ) \ while( Angle < 0 )
Angle -= 3600; } Angle += 3600;
while( Angle >= 3600 )
/* Normalize angle to be in the -90.0 .. 90.0 range */ Angle -= 3600;
#define NORMALIZE_ANGLE_90( Angle ) { \ }
while( Angle < -900 ) \
Angle += 1800; \ /// Normalize angle to be in the -90.0 .. 90.0 range
while( Angle > 900 ) \ template<class T> inline void NORMALIZE_ANGLE_90( T& Angle )
Angle -= 1800; } {
while( Angle < -900 )
/* Normalize angle to be in the -180.0 .. 180.0 range */ Angle += 1800;
#define NORMALIZE_ANGLE_180( Angle ) { \ while( Angle > 900 )
while( Angle <= -1800 ) \ 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 <boost/typeof/typeof.hpp> /// Normalize angle to be in the -180.0 .. 180.0 range
template<class T> inline void NORMALIZE_ANGLE_180( T& Angle )
// we have to register the types used with the typeof keyword with boost {
BOOST_TYPEOF_REGISTER_TYPE( wxPoint ) while( Angle <= -1800 )
BOOST_TYPEOF_REGISTER_TYPE( wxSize ) Angle += 3600;
BOOST_TYPEOF_REGISTER_TYPE( wxString ) while( Angle > 1800 )
class DrawSheetLabelStruct; Angle -= 3600;
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__; }
/// 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<class T, class T2> inline void EXCHG( T& a, T2& b )
{
T temp = a;
a = b;
b = temp;
}
#endif /* ifdef MACRO_H */ #endif /* ifdef MACRO_H */
...@@ -162,8 +162,6 @@ wxString SEGZONE::GetSelectMenuText() const ...@@ -162,8 +162,6 @@ wxString SEGZONE::GetSelectMenuText() const
NETINFO_ITEM* net; NETINFO_ITEM* net;
BOARD* board = GetBoard(); BOARD* board = GetBoard();
text << _( "Zone" ) << wxT( " " ) << wxString::Format( wxT( "(%08lX)" ), m_TimeStamp );
if( board ) if( board )
{ {
net = board->FindNet( GetNet() ); net = board->FindNet( GetNet() );
......
...@@ -460,7 +460,7 @@ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* aDC ) ...@@ -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 exists
{ {
// Creates a lock point, if not already 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 ); LockPoint = GetBoard()->CreateLockPoint( hp, (TRACK*) LockPoint, &s_ItemsListPicker );
g_CurrentTrackSegment->SetEnd(hp); g_CurrentTrackSegment->SetEnd(hp);
} }
......
...@@ -320,7 +320,7 @@ SEGVIA* SPECCTRA_DB::makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNet ...@@ -320,7 +320,7 @@ SEGVIA* SPECCTRA_DB::makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNet
else // VIA_MICROVIA or VIA_BLIND_BURIED else // VIA_MICROVIA or VIA_BLIND_BURIED
{ {
LAYER_NUM topLayerNdx = UNDEFINED_LAYER; LAYER_NUM topLayerNdx = UNDEFINED_LAYER;
LAYER_NUM botLayerNdx = 7000; LAYER_NUM botLayerNdx = 7000; // Ask Dick if this number loses its magic
int viaDiam = -1; int viaDiam = -1;
for( int i=0; i<shapeCount; ++i ) for( int i=0; i<shapeCount; ++i )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment