Converted macros to inline template function

This commit is contained in:
Lorenzo Marcantonio 2013-04-28 17:43:26 +02:00
parent 3b1ddd952f
commit 6b500d606c
5 changed files with 56 additions and 74 deletions

View File

@ -116,8 +116,6 @@ enum pseudokeys {
#define TEXT_ORIENT_HORIZ 0
#define TEXT_ORIENT_VERT 900
#define ON 1
#define OFF 0
//-----<KiROUND KIT>------------------------------------------------------------

View File

@ -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<class T> 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<class T> 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<class T> 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<class T> 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<class T> 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 <boost/typeof/typeof.hpp>
// 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<class T> 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<class T, class T2> inline void EXCHG( T& a, T2& b )
{
T temp = a;
a = b;
b = temp;
}
#endif /* ifdef MACRO_H */

View File

@ -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() );

View File

@ -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);
}

View File

@ -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<shapeCount; ++i )