quiet warnings, add Clamp()

This commit is contained in:
Dick Hollenbeck 2012-03-19 11:29:24 -05:00
parent b5cac30abd
commit 87aa22f13f
3 changed files with 29 additions and 11 deletions

View File

@ -1,8 +1,8 @@
/********************/ /********************/
/* System includes. */ /* System includes. */
/********************/ /********************/
#ifndef FCTSYS_H #ifndef FCTSYS_H_
#define FCTSYS_H #define FCTSYS_H_
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h> #include <wx/wxprec.h>
@ -46,6 +46,25 @@
#define D(x) // nothing #define D(x) // nothing
#endif #endif
/**
* Function Clamp
* limits @a value within the range @a lower <= @a value <= @a upper. It will work
* on temporary expressions, since they are evaluated only once, and it should work
* on most if not all numeric types. The arguments are accepted in this order so you
* can remember the expression as a memory aid:
* <p>
* result is: lower <= value <= upper
*/
template <typename T> inline const T& Clamp( const T& lower, const T& value, const T& upper )
{
wxASSERT( lower <= upper );
if( value < lower )
return lower;
else if( value > upper )
return upper;
return value;
}
#define UNIX_STRING_DIR_SEP wxT( "/" ) #define UNIX_STRING_DIR_SEP wxT( "/" )
#define WIN_STRING_DIR_SEP wxT( "\\" ) #define WIN_STRING_DIR_SEP wxT( "\\" )
@ -64,4 +83,4 @@
#include <config.h> #include <config.h>
#endif /* FCTSYS_H */ #endif // FCTSYS_H__

View File

@ -438,7 +438,7 @@ void DIALOG_PAD_PROPERTIES::initValues()
// Type of pad selection // Type of pad selection
m_PadType->SetSelection( 0 ); m_PadType->SetSelection( 0 );
for( int ii = 0; ii < NBTYPES; ii++ ) for( unsigned ii = 0; ii < NBTYPES; ii++ )
{ {
if( CodeType[ii] == m_dummyPad->GetAttribute() ) if( CodeType[ii] == m_dummyPad->GetAttribute() )
{ {
@ -574,10 +574,9 @@ void DIALOG_PAD_PROPERTIES::PadOrientEvent( wxCommandEvent& event )
void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event ) void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event )
{ {
long layer_mask; long layer_mask;
int ii; unsigned ii = m_PadType->GetSelection();
ii = m_PadType->GetSelection(); if( ii >= NBTYPES ) // catches < 0 also
if( ii < 0 || ii >= NBTYPES )
ii = 0; ii = 0;
layer_mask = Std_Pad_Layers[ii]; layer_mask = Std_Pad_Layers[ii];