Replace DIM() macro

The standard DIM() macro was not typesafe as it happily deferred errors
to runtime that can be caught at compile time.  Replacing it with a
generic C++11 constexpr allows for typecasting, comparison and compile
time error checking.
This commit is contained in:
Seth Hillbrand 2019-01-06 08:43:12 -08:00
parent cec97ebfa6
commit 1e5ba6f1b1
49 changed files with 116 additions and 116 deletions

View File

@ -219,10 +219,10 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
layer_id.clear();
layer_id.reserve( m_copperLayersCount );
for( unsigned i = 0; i < DIM( cu_seq ); ++i )
for( unsigned i = 0; i < arrayDim( cu_seq ); ++i )
cu_seq[i] = ToLAYER_ID( B_Cu - i );
for( LSEQ cu = cu_set.Seq( cu_seq, DIM( cu_seq ) ); cu; ++cu )
for( LSEQ cu = cu_set.Seq( cu_seq, arrayDim( cu_seq ) ); cu; ++cu )
{
const PCB_LAYER_ID curr_layer_id = *cu;
@ -973,7 +973,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// User layers are not drawn here, only technical layers
for( LSEQ seq = LSET::AllNonCuMask().Seq( teckLayerList, DIM( teckLayerList ) );
for( LSEQ seq = LSET::AllNonCuMask().Seq( teckLayerList, arrayDim( teckLayerList ) );
seq;
++seq )
{

View File

@ -172,8 +172,8 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent,
// Create the status line
static const int status_dims[4] = { -1, 130, 130, 170 };
wxStatusBar *status_bar = CreateStatusBar( DIM( status_dims ) );
SetStatusWidths( DIM( status_dims ), status_dims );
wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) );
SetStatusWidths( arrayDim( status_dims ), status_dims );
CreateMenuBar();
ReCreateMainToolbar();

View File

@ -75,7 +75,7 @@ const int COGL_ATT_LIST::m_openGL_attributes_list[] = {
#define ATT_WX_GL_SAMPLE_BUFFERS_DATA 11
int COGL_ATT_LIST::m_openGL_attributes_list_to_use[
DIM( COGL_ATT_LIST::m_openGL_attributes_list ) ] = { 0 };
arrayDim( COGL_ATT_LIST::m_openGL_attributes_list ) ] = { 0 };
const int *COGL_ATT_LIST::GetAttributesList( bool aUseAntiAliasing )

View File

@ -100,15 +100,15 @@ COLORS_DESIGN_SETTINGS::COLORS_DESIGN_SETTINGS( FRAME_T aFrameType )
m_frameType = aFrameType;
m_legacyMode = false;
for( unsigned src = 0, dst = 0; dst < DIM( m_LayersColors ); ++dst )
for( unsigned src = 0, dst = 0; dst < arrayDim( m_LayersColors ); ++dst )
{
m_LayersColors[dst] = COLOR4D( default_layer_color[src++] );
if( src >= DIM( default_layer_color ) )
if( src >= arrayDim( default_layer_color ) )
src = 0; // wrap the source.
}
for( unsigned src = 0, dst = LAYER_VIAS; src < DIM( default_items_color ); ++dst, ++src )
for( unsigned src = 0, dst = LAYER_VIAS; src < arrayDim( default_items_color ); ++dst, ++src )
{
m_LayersColors[dst] = COLOR4D( default_items_color[src] );
}
@ -125,7 +125,7 @@ COLORS_DESIGN_SETTINGS::COLORS_DESIGN_SETTINGS( FRAME_T aFrameType )
COLOR4D COLORS_DESIGN_SETTINGS::GetLayerColor( LAYER_NUM aLayer ) const
{
if( (unsigned) aLayer < DIM( m_LayersColors ) )
if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
{
return m_legacyMode ? m_LayersColors[aLayer].AsLegacyColor()
: m_LayersColors[aLayer];
@ -136,7 +136,7 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetLayerColor( LAYER_NUM aLayer ) const
void COLORS_DESIGN_SETTINGS::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor )
{
if( (unsigned) aLayer < DIM( m_LayersColors ) )
if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
{
m_LayersColors[aLayer] = aColor;
}
@ -145,7 +145,7 @@ void COLORS_DESIGN_SETTINGS::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor )
COLOR4D COLORS_DESIGN_SETTINGS::GetItemColor( int aItemIdx ) const
{
if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )
{
return m_legacyMode ? m_LayersColors[aItemIdx].AsLegacyColor()
: m_LayersColors[aItemIdx];
@ -157,7 +157,7 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetItemColor( int aItemIdx ) const
void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
{
if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )
{
m_LayersColors[aItemIdx] = aColor;
}
@ -166,7 +166,7 @@ void COLORS_DESIGN_SETTINGS::SetItemColor( int aItemIdx, COLOR4D aColor )
void COLORS_DESIGN_SETTINGS::SetAllColorsAs( COLOR4D aColor )
{
for( unsigned ii = 0; ii < DIM(m_LayersColors); ii++ )
for( unsigned ii = 0; ii < arrayDim(m_LayersColors); ii++ )
m_LayersColors[ii] = aColor;
}
@ -175,7 +175,7 @@ void COLORS_DESIGN_SETTINGS::SetAllColorsAs( COLOR4D aColor )
void COLORS_DESIGN_SETTINGS::setupConfigParams()
{
wxASSERT( DIM( m_LayersColors ) >= PCB_LAYER_ID_COUNT );
wxASSERT( arrayDim( m_LayersColors ) >= PCB_LAYER_ID_COUNT );
wxString currprefix = GetConfigPrefix();

View File

@ -26,7 +26,7 @@
*/
#include <fctsys.h>
#include <macros.h> // DIM()
#include <macros.h> // arrayDim()
#include <common.h>
#include <project.h>
#include <confirm.h>
@ -94,7 +94,7 @@ void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event )
// units that do not allow too large draw areas
wxSize maxPageSize( MAX_PAGE_SIZE_EDITORS_MILS, MAX_PAGE_SIZE_EDITORS_MILS );
for( unsigned ii = 0; ii < DIM( smallSizeFrames ); ii++ )
for( unsigned ii = 0; ii < arrayDim( smallSizeFrames ); ii++ )
{
if( IsType( smallSizeFrames[ii] ) )
{
@ -157,7 +157,7 @@ void DIALOG_PAGES_SETTINGS::initDialog()
// The first shows translated strings, the second contains not translated strings
m_paperSizeComboBox->Clear();
for( unsigned ii = 0; ii < DIM(pageFmts); ii++ )
for( unsigned ii = 0; ii < arrayDim(pageFmts); ii++ )
{
m_pageFmt.Add( pageFmts[ii] );
m_paperSizeComboBox->Append( wxGetTranslation( pageFmts[ii] ) );
@ -721,7 +721,7 @@ void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
unsigned i;
for( i=0; i < DIM( papers ); ++i )
for( i=0; i < arrayDim( papers ); ++i )
{
if( paperType.Contains( papers[i] ) )
{
@ -730,7 +730,7 @@ void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
}
}
wxASSERT( i != DIM(papers) ); // dialog UI match the above list?
wxASSERT( i != arrayDim(papers) ); // dialog UI match the above list?
m_layout_size = pageInfo.GetSizeMils();

View File

@ -450,7 +450,7 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
wxString helpFile;
// Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
// or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
for( unsigned ii = 0; ii < DIM( names ); ii++ )
for( unsigned ii = 0; ii < arrayDim( names ); ii++ )
{
helpFile = SearchHelpFileFullPath( search, names[ii] );

View File

@ -103,7 +103,7 @@ bool GetAssociatedDocument( wxWindow* aParent,
wxT( "file:" )
};
for( unsigned ii = 0; ii < DIM(url_header); ii++ )
for( unsigned ii = 0; ii < arrayDim(url_header); ii++ )
{
if( aDocName.First( url_header[ii] ) == 0 ) // looks like an internet url
{

View File

@ -188,7 +188,7 @@ wxString FindKicadFile( const wxString& shortname )
};
// find binary file from possibilities list:
for( unsigned i=0; i<DIM(possibilities); ++i )
for( unsigned i=0; i<arrayDim(possibilities); ++i )
{
#ifndef __WXMAC__
fullFileName = possibilities[i] + shortname;
@ -309,7 +309,7 @@ wxString KicadDatasPath()
#endif
};
for( unsigned i=0; i<DIM(possibilities); ++i )
for( unsigned i=0; i<arrayDim(possibilities); ++i )
{
data_path = possibilities[i];

View File

@ -149,7 +149,7 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad )
{
// Since this will be called from python, cannot assume that code will
// not pass a bad aFaceId.
if( unsigned( aFaceId ) >= DIM( m_kiface ) )
if( unsigned( aFaceId ) >= arrayDim( m_kiface ) )
{
// @todo : throw an exception here for python's benefit, at least that
// way it gets some explanatory text.
@ -481,7 +481,7 @@ bool KIWAY::ProcessEvent( wxEvent& aEvent )
void KIWAY::OnKiwayEnd()
{
for( unsigned i=0; i < DIM( m_kiface ); ++i )
for( unsigned i=0; i < arrayDim( m_kiface ); ++i )
{
if( m_kiface[i] )
m_kiface[i]->OnKifaceEnd();

View File

@ -205,7 +205,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
};
SetStatusWidths( DIM( dims ), dims );
SetStatusWidths( arrayDim( dims ), dims );
// Create child subwindows.
GetClientSize( &m_FrameSize.x, &m_FrameSize.y );

View File

@ -207,7 +207,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
};
SetStatusWidths( DIM( dims ), dims );
SetStatusWidths( arrayDim( dims ), dims );
// Create child subwindows.
GetClientSize( &m_FrameSize.x, &m_FrameSize.y );

View File

@ -185,7 +185,7 @@ LSEQ LSET::CuStack() const
B_Cu, // 31
};
return Seq( sequence, DIM( sequence ) );
return Seq( sequence, arrayDim( sequence ) );
}
@ -209,7 +209,7 @@ LSEQ LSET::Technicals( LSET aSetToOmit ) const
LSET subset = ~aSetToOmit & *this;
return subset.Seq( sequence, DIM( sequence ) );
return subset.Seq( sequence, arrayDim( sequence ) );
}
@ -225,7 +225,7 @@ LSEQ LSET::Users() const
Margin,
};
return Seq( sequence, DIM( sequence ) );
return Seq( sequence, arrayDim( sequence ) );
}
@ -252,7 +252,7 @@ LSEQ LSET::TechAndUserUIOrder() const
B_Fab,
};
return Seq( sequence, DIM( sequence ) );
return Seq( sequence, arrayDim( sequence ) );
}
@ -302,7 +302,7 @@ std::string LSET::FmtHex() const
if( nibble && !( nibble % 8 ) )
ret += '_';
assert( ndx < DIM( hex ) );
assert( ndx < arrayDim( hex ) );
ret += hex[ndx];
}
@ -468,7 +468,7 @@ LSEQ LSET::SeqStackupBottom2Top() const
Edge_Cuts,
};
return Seq( sequence, DIM( sequence ) );
return Seq( sequence, arrayDim( sequence ) );
}
@ -668,7 +668,7 @@ LSET LSET::InternalCuMask()
In30_Cu,
};
static const LSET saved( cu_internals, DIM( cu_internals ) );
static const LSET saved( cu_internals, arrayDim( cu_internals ) );
return saved;
}

View File

@ -56,7 +56,7 @@ static const VECTOR2I MarkerShapeCorners[] =
VECTOR2I( 1, 8 ),
VECTOR2I( 0, 0 )
};
const unsigned CORNERS_COUNT = DIM( MarkerShapeCorners );
const unsigned CORNERS_COUNT = arrayDim( MarkerShapeCorners );
/*******************/
/* Classe MARKER_BASE */

View File

@ -675,7 +675,7 @@ bool PGM_BASE::SetLanguage( bool first_time )
m_common_settings->Read( languageCfgKey, &languageSel );
// Search for the current selection
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
{
if( s_Languages[ii].m_Lang_Label == languageSel )
{
@ -717,7 +717,7 @@ bool PGM_BASE::SetLanguage( bool first_time )
wxString languageSel;
// Search for the current selection language name
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
{
if( s_Languages[ii].m_WX_Lang_Identifier == m_language_id )
{
@ -756,9 +756,9 @@ bool PGM_BASE::SetLanguage( bool first_time )
void PGM_BASE::SetLanguageIdentifier( int menu_id )
{
wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
menu_id, DIM( s_Languages ) );
menu_id, arrayDim( s_Languages ) );
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
{
if( menu_id == s_Languages[ii].m_KI_Lang_Identifier )
{
@ -814,7 +814,7 @@ void PGM_BASE::AddMenuLanguageList( wxMenu* MasterMenu )
menu = new wxMenu;
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
{
wxString label;
@ -835,7 +835,7 @@ void PGM_BASE::AddMenuLanguageList( wxMenu* MasterMenu )
KiBitmap( language_xpm ) );
// Set Check mark on current selected language
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
{
if( m_language_id == s_Languages[ii].m_WX_Lang_Identifier )
menu->Check( s_Languages[ii].m_KI_Lang_Identifier, true );

View File

@ -48,7 +48,7 @@ void PROJECT::ElemsClear()
{
// careful here, this should work, but the virtual destructor may not
// be in the same link image as PROJECT.
for( unsigned i = 0; i < DIM( m_elems ); ++i )
for( unsigned i = 0; i < arrayDim( m_elems ); ++i )
{
SetElem( ELEM_T( i ), NULL );
}
@ -172,7 +172,7 @@ void PROJECT::SetRString( RSTRING_T aIndex, const wxString& aString )
{
unsigned ndx = unsigned( aIndex );
if( ndx < DIM( m_rstrings ) )
if( ndx < arrayDim( m_rstrings ) )
{
m_rstrings[ndx] = aString;
}
@ -187,7 +187,7 @@ const wxString& PROJECT::GetRString( RSTRING_T aIndex )
{
unsigned ndx = unsigned( aIndex );
if( ndx < DIM( m_rstrings ) )
if( ndx < arrayDim( m_rstrings ) )
{
return m_rstrings[ndx];
}
@ -206,7 +206,7 @@ PROJECT::_ELEM* PROJECT::GetElem( ELEM_T aIndex )
{
// This is virtual, so implement it out of line
if( unsigned( aIndex ) < DIM( m_elems ) )
if( unsigned( aIndex ) < arrayDim( m_elems ) )
{
return m_elems[aIndex];
}
@ -218,7 +218,7 @@ void PROJECT::SetElem( ELEM_T aIndex, _ELEM* aElem )
{
// This is virtual, so implement it out of line
if( unsigned( aIndex ) < DIM( m_elems ) )
if( unsigned( aIndex ) < arrayDim( m_elems ) )
{
#if defined(DEBUG) && 0
if( aIndex == ELEM_SCH_PART_LIBS )

View File

@ -268,7 +268,7 @@ bool isKeySpecialCode( int aKeyCode )
bool isInList = false;
for( unsigned ii = 0; ii < DIM( special_keys ) && !isInList; ii++ )
for( unsigned ii = 0; ii < arrayDim( special_keys ) && !isInList; ii++ )
{
if( special_keys[ii] == aKeyCode )
isInList = true;

View File

@ -322,7 +322,7 @@ protected:
{ SIDE_LEFT, pins_on_side( SIDE_LEFT ) },
{ SIDE_BOTTOM, pins_on_side( SIDE_BOTTOM ) },
};
std::vector<SIDE_AND_NPINS> sides( sides_init, sides_init + DIM( sides_init ) );
std::vector<SIDE_AND_NPINS> sides( sides_init, sides_init + arrayDim( sides_init ) );
int orient = m_component->GetOrientation();
int orient_angle = orient & 0xff; // enum is a bitmask
@ -386,7 +386,7 @@ protected:
std::vector<SIDE_AND_COLL> get_colliding_sides()
{
SIDE sides_init[] = { SIDE_RIGHT, SIDE_TOP, SIDE_LEFT, SIDE_BOTTOM };
std::vector<SIDE> sides( sides_init, sides_init + DIM( sides_init ) );
std::vector<SIDE> sides( sides_init, sides_init + arrayDim( sides_init ) );
std::vector<SIDE_AND_COLL> colliding;
// Iterate over all sides and find the ones that collide

View File

@ -174,7 +174,7 @@ static COLOR4D s_layerColor[LAYER_ID_COUNT];
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer )
{
unsigned layer = ( aLayer );
wxASSERT( layer < DIM( s_layerColor ) );
wxASSERT( layer < arrayDim( s_layerColor ) );
return s_layerColor[layer];
}
@ -187,7 +187,7 @@ void SetLayerColor( COLOR4D aColor, SCH_LAYER_ID aLayer )
aColor.Darken( 0.01 );
unsigned layer = aLayer;
wxASSERT( layer < DIM( s_layerColor ) );
wxASSERT( layer < arrayDim( s_layerColor ) );
s_layerColor[layer] = aColor;
}

View File

@ -57,7 +57,7 @@ static const int pin_orientation_codes[] =
PIN_UP,
PIN_DOWN
};
#define PIN_ORIENTATION_CNT DIM( pin_orientation_codes )
#define PIN_ORIENTATION_CNT arrayDim( pin_orientation_codes )
// small margin in internal units between the pin text and the pin line
#define PIN_TEXT_MARGIN 4

View File

@ -99,10 +99,10 @@ SCH_SCREEN::SCH_SCREEN( KIWAY* aKiway ) :
SetZoom( 32 );
for( unsigned i = 0; i < DIM( SchematicZoomList ); i++ )
for( unsigned i = 0; i < arrayDim( SchematicZoomList ); i++ )
m_ZoomList.push_back( SchematicZoomList[i] );
for( unsigned i = 0; i < DIM( SchematicGridList ); i++ )
for( unsigned i = 0; i < arrayDim( SchematicGridList ); i++ )
AddGrid( SchematicGridList[i] );
SetGrid( wxRealPoint( 50, 50 ) ); // Default grid size.

View File

@ -41,7 +41,7 @@ bool PANEL_GERBVIEW_SETTINGS::TransferDataToWindow( )
m_BoxUnits->SetSelection( m_Parent->GetUserUnits() ? 1 : 0 );
m_ShowPageLimitsOpt->SetValue( m_Parent->m_DisplayOptions.m_DisplayPageLimits );
for( unsigned i = 0; i < DIM( g_GerberPageSizeList ); ++i )
for( unsigned i = 0; i < arrayDim( g_GerberPageSizeList ); ++i )
{
if( g_GerberPageSizeList[i] == m_Parent->GetPageSettings().GetType() )
{

View File

@ -103,10 +103,10 @@ static GRID_TYPE gbrGridList[] =
GBR_SCREEN::GBR_SCREEN( const wxSize& aPageSizeIU ) :
BASE_SCREEN( SCREEN_T )
{
for( unsigned i = 0; i < DIM( gbrZoomList ); ++i )
for( unsigned i = 0; i < arrayDim( gbrZoomList ); ++i )
m_ZoomList.push_back( gbrZoomList[i] );
for( unsigned i = 0; i < DIM( gbrGridList ); ++i )
for( unsigned i = 0; i < arrayDim( gbrGridList ); ++i )
AddGrid( gbrGridList[i] );
// Set the working grid size to a reasonable value

View File

@ -101,7 +101,7 @@ GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( int aLayer ) :
ResetDefaultValues();
for( unsigned ii = 0; ii < DIM( m_Aperture_List ); ii++ )
for( unsigned ii = 0; ii < arrayDim( m_Aperture_List ); ii++ )
m_Aperture_List[ii] = 0;
}
@ -110,7 +110,7 @@ GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE()
{
m_Drawings.DeleteAll();
for( unsigned ii = 0; ii < DIM( m_Aperture_List ); ii++ )
for( unsigned ii = 0; ii < arrayDim( m_Aperture_List ); ii++ )
{
delete m_Aperture_List[ii];
}
@ -132,7 +132,7 @@ D_CODE* GERBER_FILE_IMAGE::GetDCODEOrCreate( int aDCODE, bool aCreateIfNoExist )
{
unsigned ndx = aDCODE - FIRST_DCODE;
if( ndx < (unsigned) DIM( m_Aperture_List ) )
if( ndx < (unsigned) arrayDim( m_Aperture_List ) )
{
// lazily create the D_CODE if it does not exist.
if( aCreateIfNoExist )
@ -152,7 +152,7 @@ D_CODE* GERBER_FILE_IMAGE::GetDCODE( int aDCODE ) const
{
unsigned ndx = aDCODE - FIRST_DCODE;
if( ndx < (unsigned) DIM( m_Aperture_List ) )
if( ndx < (unsigned) arrayDim( m_Aperture_List ) )
{
return m_Aperture_List[ndx];
}
@ -266,7 +266,7 @@ int GERBER_FILE_IMAGE::GetDcodesCount()
{
int count = 0;
for( unsigned ii = 0; ii < DIM( m_Aperture_List ); ii++ )
for( unsigned ii = 0; ii < arrayDim( m_Aperture_List ); ii++ )
{
if( m_Aperture_List[ii] )
if( m_Aperture_List[ii]->m_InUse || m_Aperture_List[ii]->m_Defined )

View File

@ -123,10 +123,10 @@ PARAM_CFG_ARRAY& GERBVIEW_FRAME::GetConfigurationSettings()
wxT("ColorLayer28Ex"), wxT("ColorLayer29Ex"), wxT("ColorLayer30Ex"), wxT("ColorLayer31Ex"),
};
wxASSERT( DIM(keys) == DIM(color_default) );
wxASSERT( DIM(keys) <= DIM(g_ColorsSettings.m_LayersColors) && DIM(keys) <= DIM(color_default) );
wxASSERT( arrayDim(keys) == arrayDim(color_default) );
wxASSERT( arrayDim(keys) <= arrayDim(g_ColorsSettings.m_LayersColors) && arrayDim(keys) <= arrayDim(color_default) );
for( unsigned i = 0; i < DIM(keys); ++i )
for( unsigned i = 0; i < arrayDim(keys); ++i )
{
COLOR4D* prm = &g_ColorsSettings.m_LayersColors[ GERBER_DRAW_LAYER( i ) ];

View File

@ -121,7 +121,7 @@ void GERBER_LAYER_WIDGET::ReFillRender()
RR( _( "Background" ), LAYER_PCB_BACKGROUND, BLACK, _( "PCB Background" ), true, false )
};
for( unsigned row=0; row<DIM(renderRows); ++row )
for( unsigned row=0; row<arrayDim(renderRows); ++row )
{
if( renderRows[row].color != COLOR4D::UNSPECIFIED ) // does this row show a color?
renderRows[row].color = myframe->GetVisibleElementColor( renderRows[row].id );
@ -130,7 +130,7 @@ void GERBER_LAYER_WIDGET::ReFillRender()
renderRows[row].state = myframe->IsElementVisible( renderRows[row].id );
}
AppendRenderRows( renderRows, DIM(renderRows) );
AppendRenderRows( renderRows, arrayDim(renderRows) );
}

View File

@ -94,9 +94,12 @@ static inline const wxChar* GetChars( const wxString& s )
return (const wxChar*) s.c_str();
}
/// # of elements in an array
#define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t
/// # of elements in an array. This implements type-safe compile time checking
template <typename T, std::size_t N>
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
{
return N;
}
/**
* Function MIRROR

View File

@ -188,7 +188,7 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
wxArrayString files;
for( unsigned ii = 0; ii < DIM( extentionList ); ii++ )
for( unsigned ii = 0; ii < arrayDim( extentionList ); ii++ )
wxDir::GetAllFiles( currdirname, &files, extentionList[ii] );
files.Sort();

View File

@ -120,7 +120,7 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
GetTextSize( _( "Inches" ), stsbar ).x + 10
};
SetStatusWidths( DIM( dims ), dims );
SetStatusWidths( arrayDim( dims ), dims );
m_auimgr.SetManagedWindow( this );
m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );

View File

@ -80,10 +80,10 @@ static GRID_TYPE pl_editorGridList[] =
PL_EDITOR_SCREEN::PL_EDITOR_SCREEN( const wxSize& aPageSizeIU ) :
BASE_SCREEN( SCREEN_T )
{
for( unsigned i = 0; i < DIM( pl_editorZoomList ); ++i )
for( unsigned i = 0; i < arrayDim( pl_editorZoomList ); ++i )
m_ZoomList.push_back( pl_editorZoomList[i] );
for( unsigned i = 0; i < DIM( pl_editorGridList ); ++i )
for( unsigned i = 0; i < arrayDim( pl_editorGridList ); ++i )
AddGrid( pl_editorGridList[i] );
// pl_editor uses the same frame position as schematic and board editors

View File

@ -1303,7 +1303,7 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
stub.NewOutline();
for( unsigned ii = 0; ii < DIM( stubBuffer ); ii++ )
for( unsigned ii = 0; ii < arrayDim( stubBuffer ); ii++ )
{
wxPoint cpos = stubBuffer[ii];
RotatePoint( &cpos, aPad.GetOrientation() );
@ -1325,7 +1325,7 @@ void CreateThermalReliefPadPolygon( SHAPE_POLY_SET& aCornerBuffer,
stub.RemoveAllContours();
stub.NewOutline();
for( unsigned ii = 0; ii < DIM( stubBuffer ); ii++ )
for( unsigned ii = 0; ii < arrayDim( stubBuffer ); ii++ )
{
wxPoint cpos = stubBuffer[ii];
RotatePoint( &cpos, aPad.GetOrientation() );

View File

@ -558,7 +558,7 @@ void BOARD::PopHighLight()
bool BOARD::SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer )
{
if( unsigned( aIndex ) < DIM( m_Layer ) )
if( unsigned( aIndex ) < arrayDim( m_Layer ) )
{
m_Layer[ aIndex ] = aLayer;
return true;

View File

@ -62,8 +62,8 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNu
_( "Alphabet, minus IOSQXZ" ),
_( "Alphabet, full 26 characters" )
};
m_choicePriAxisNumbering->Set( DIM( charSetDescriptions ), charSetDescriptions );
m_choiceSecAxisNumbering->Set( DIM( charSetDescriptions ), charSetDescriptions );
m_choicePriAxisNumbering->Set( arrayDim( charSetDescriptions ), charSetDescriptions );
m_choiceSecAxisNumbering->Set( arrayDim( charSetDescriptions ), charSetDescriptions );
m_choicePriAxisNumbering->SetSelection( 0 );
m_choiceSecAxisNumbering->SetSelection( 0 );

View File

@ -126,7 +126,7 @@ DIALOG_EXPORT_SVG::~DIALOG_EXPORT_SVG()
wxString layerKey;
for( unsigned layer = 0; layer < DIM(m_boxSelectLayer); ++layer )
for( unsigned layer = 0; layer < arrayDim(m_boxSelectLayer); ++layer )
{
if( !m_boxSelectLayer[layer].first )
continue;
@ -194,7 +194,7 @@ LSET DIALOG_EXPORT_SVG::getCheckBoxSelectedLayers() const
{
LSET ret;
for( unsigned layer = 0; layer < DIM(m_boxSelectLayer); ++layer )
for( unsigned layer = 0; layer < arrayDim(m_boxSelectLayer); ++layer )
{
if( !m_boxSelectLayer[layer].first )
continue;

View File

@ -376,7 +376,7 @@ void DIALOG_GENDRILL::GenDrillAndMapFiles( bool aGenDrill, bool aGenMap )
unsigned choice = (unsigned) m_Choice_Drill_Map->GetSelection();
if( choice >= DIM( filefmt ) )
if( choice >= arrayDim( filefmt ) )
choice = 1;
// Create output directory if it does not exist (also transform it in

View File

@ -975,7 +975,7 @@ void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event )
{
int ii = m_PadType->GetSelection();
if( (unsigned)ii >= DIM( code_type ) ) // catches < 0 also
if( (unsigned)ii >= arrayDim( code_type ) ) // catches < 0 also
ii = 0;
bool hasHole, hasConnection;
@ -1025,7 +1025,7 @@ void DIALOG_PAD_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
{
int ii = m_PadType->GetSelection();
if( (unsigned)ii >= DIM( code_type ) ) // catches < 0 also
if( (unsigned)ii >= arrayDim( code_type ) ) // catches < 0 also
ii = 0;
bool hasHole, hasConnection;
@ -1905,7 +1905,7 @@ void DIALOG_PAD_PROPERTIES::onAddPrimitive( wxCommandEvent& event )
wxString shapelist[] = { _( "Segment" ), _( "Arc" ), _( "Ring/Circle" ), _( "Polygon" ) };
int type = wxGetSingleChoiceIndex( _( "Shape type:" ), _( "Add Primitive" ),
DIM( shapelist ), shapelist, 0, this );
arrayDim( shapelist ), shapelist, 0, this );
STROKE_T listtype[] = { S_SEGMENT, S_ARC, S_CIRCLE, S_POLYGON };

View File

@ -269,7 +269,7 @@ void DIALOG_PRINT_PCBNEW::setListBoxValue( wxCheckListBox* aList, bool aValue )
bool DIALOG_PRINT_PCBNEW::isLayerEnabled( unsigned int aLayer ) const
{
wxCHECK( aLayer < DIM( m_layers ), false );
wxCHECK( aLayer < arrayDim( m_layers ), false );
const auto& layerInfo = m_layers[aLayer];
if( layerInfo.first )
@ -281,7 +281,7 @@ bool DIALOG_PRINT_PCBNEW::isLayerEnabled( unsigned int aLayer ) const
void DIALOG_PRINT_PCBNEW::enableLayer( unsigned int aLayer, bool aValue )
{
wxCHECK( aLayer < DIM( m_layers ), /* void */ );
wxCHECK( aLayer < arrayDim( m_layers ), /* void */ );
const auto& layerInfo = m_layers[aLayer];
layerInfo.first->Check( layerInfo.second, aValue );
}
@ -293,7 +293,7 @@ int DIALOG_PRINT_PCBNEW::setLayerSetFromList()
int& pageCount = settings()->m_pageCount;
pageCount = 0;
for( unsigned int layer = 0; layer < DIM( m_layers ); ++layer )
for( unsigned int layer = 0; layer < arrayDim( m_layers ); ++layer )
{
if( isLayerEnabled( layer ) )
{

View File

@ -104,7 +104,7 @@ static LSEQ dlg_layers()
Dwgs_User,
};
return LSEQ( layers, layers + DIM( layers ) );
return LSEQ( layers, layers + arrayDim( layers ) );
}
@ -315,7 +315,7 @@ void PANEL_SETUP_LAYERS::showPresets( LSET enabledLayers )
{
int presetsNdx = 0; // the "Custom" setting, matches nothing
for( unsigned i=1; i<DIM( presets ); ++i )
for( unsigned i=1; i<arrayDim( presets ); ++i )
{
if( enabledLayers == presets[i] )
{
@ -460,7 +460,7 @@ void PANEL_SETUP_LAYERS::OnPresetsChoice( wxCommandEvent& event )
if( presetNdx <= 0 ) // the Custom setting controls nothing.
return;
if( presetNdx < (int) DIM(presets) )
if( presetNdx < (int) arrayDim(presets) )
{
m_enabledLayers = presets[ presetNdx ];
LSET copperSet = m_enabledLayers & LSET::AllCuMask();

View File

@ -320,7 +320,7 @@ void EAGLE_PLUGIN::clear_cu_map()
{
// All cu layers are invalid until we see them in the <layers> section while
// loading either a board or library. See loadLayerDefs().
for( unsigned i = 0; i < DIM(m_cu_map); ++i )
for( unsigned i = 0; i < arrayDim(m_cu_map); ++i )
m_cu_map[i] = -1;
}
@ -435,7 +435,7 @@ void EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
#if 0 && defined(DEBUG)
printf( "m_cu_map:\n" );
for( unsigned i=0; i<DIM(m_cu_map); ++i )
for( unsigned i=0; i<arrayDim(m_cu_map); ++i )
{
printf( "\t[%d]:%d\n", i, m_cu_map[i] );
}
@ -2165,7 +2165,7 @@ PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
int kiLayer;
// eagle copper layer:
if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
if( aEagleLayer >= 1 && aEagleLayer < int( arrayDim( m_cu_map ) ) )
{
kiLayer = m_cu_map[aEagleLayer];
}

View File

@ -391,7 +391,7 @@ void PCB_EDIT_FRAME::GenD356File( wxCommandEvent& aEvent )
// CUST 1 would be metric but gerbtool simply ignores it!
fprintf( file, "P CODE 00\n" );
fprintf( file, "P UNITS CUST 0\n" );
fprintf( file, "P DIM N\n" );
fprintf( file, "P arrayDim N\n" );
write_D356_records( d356_records, file );
fprintf( file, "999\n" );

View File

@ -660,7 +660,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
fmt_mask( mask ).c_str(),
via->GetDrillValue() / SCALE_FACTOR );
for( LSEQ seq = mask.Seq( gc_seq, DIM( gc_seq ) ); seq; ++seq )
for( LSEQ seq = mask.Seq( gc_seq, arrayDim( gc_seq ) ); seq; ++seq )
{
PCB_LAYER_ID layer = *seq;
@ -687,7 +687,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
LSET pad_set = pad->GetLayerSet() & master_layermask;
// the special gc_seq
for( LSEQ seq = pad_set.Seq( gc_seq, DIM( gc_seq ) ); seq; ++seq )
for( LSEQ seq = pad_set.Seq( gc_seq, arrayDim( gc_seq ) ); seq; ++seq )
{
PCB_LAYER_ID layer = *seq;

View File

@ -177,7 +177,7 @@ public:
MODEL_VRML() : m_OutputPCB( (SGNODE*) NULL )
{
for( unsigned i = 0; i < DIM( m_layer_z ); ++i )
for( unsigned i = 0; i < arrayDim( m_layer_z ); ++i )
m_layer_z[i] = 0;
m_holes.GetArcParams( m_iMaxSeg, m_arcMinLen, m_arcMaxLen );
@ -254,7 +254,7 @@ public:
double GetLayerZ( LAYER_NUM aLayer )
{
if( unsigned( aLayer ) >= DIM( m_layer_z ) )
if( unsigned( aLayer ) >= arrayDim( m_layer_z ) )
return 0;
return m_layer_z[ aLayer ];

View File

@ -117,7 +117,7 @@ bool AskLoadBoardFileName( wxWindow* aParent, int* aCtl, wxString* aFileName, bo
}
else
{
for( unsigned ii = 2; ii < DIM( loaders ); ++ii )
for( unsigned ii = 2; ii < arrayDim( loaders ); ++ii )
{
if( !fileFilters.IsEmpty() )
fileFilters += wxChar( '|' );

View File

@ -657,7 +657,7 @@ void PCB_IO::formatBoardLayers( BOARD* aBoard, int aNestLevel ) const
F_Fab
};
for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, DIM( non_cu ) ); seq; ++seq )
for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
{
PCB_LAYER_ID layer = *seq;

View File

@ -890,7 +890,7 @@ public:
LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, wxT("BLUE"), false ),
};
lw->AppendLayerRows( layerRows, DIM(layerRows) );
lw->AppendLayerRows( layerRows, arrayDim(layerRows) );
// add some render rows
static const LAYER_WIDGET::ROW renderRows[] = {
@ -899,7 +899,7 @@ public:
LAYER_WIDGET::ROW( wxT("With Oval Eyes"), 1, BROWN, wxT("My eyes are upon you") ),
};
lw->AppendRenderRows( renderRows, DIM(renderRows) );
lw->AppendRenderRows( renderRows, arrayDim(renderRows) );
lw->SelectLayerRow( 1 );

View File

@ -707,7 +707,7 @@ void PCB_EDIT_FRAME::enableGALSpecificMenus()
bool enbl = IsGalCanvasActive();
for( unsigned ii = 0; ii < DIM( id_list ); ii++ )
for( unsigned ii = 0; ii < arrayDim( id_list ); ii++ )
{
if( GetMenuBar()->FindItem( id_list[ii] ) )
GetMenuBar()->FindItem( id_list[ii] )->Enable( enbl );

View File

@ -145,7 +145,7 @@ COLOR4D PCB_LAYER_WIDGET::getBackgroundLayerColor()
bool PCB_LAYER_WIDGET::isAllowedInFpMode( int aId )
{
for( unsigned ii = 0; ii < DIM( s_allowed_in_FpEditor ); ii++ )
for( unsigned ii = 0; ii < arrayDim( s_allowed_in_FpEditor ); ii++ )
if( s_allowed_in_FpEditor[ii] == aId )
return true;
@ -394,7 +394,7 @@ void PCB_LAYER_WIDGET::ReFillRender()
// Because s_render_rows is created static, we must explicitly call
// wxGetTranslation for texts which are internationalized (tool tips
// and item names)
for( unsigned row=0; row<DIM(s_render_rows); ++row )
for( unsigned row=0; row<arrayDim(s_render_rows); ++row )
{
LAYER_WIDGET::ROW renderRow = s_render_rows[row];
@ -554,7 +554,7 @@ void PCB_LAYER_WIDGET::ReFill()
{ B_Fab, _( "Footprint assembly on board's back" ) }
};
for( unsigned i=0; i<DIM( non_cu_seq ); ++i )
for( unsigned i=0; i<arrayDim( non_cu_seq ); ++i )
{
PCB_LAYER_ID layer = non_cu_seq[i].layerId;

View File

@ -62,7 +62,7 @@ PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS()
m_selectionCandidateColor = COLOR4D( 0.0, 1.0, 0.0, 0.75 );
// By default everything should be displayed as filled
for( unsigned int i = 0; i < DIM( m_sketchMode ); ++i )
for( unsigned int i = 0; i < arrayDim( m_sketchMode ); ++i )
{
m_sketchMode[i] = false;
}

View File

@ -160,13 +160,10 @@ static GRID_TYPE pcbGridList[] =
PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
BASE_SCREEN( SCREEN_T )
{
// D(wxSize displayz = wxGetDisplaySize();)
// D(printf( "displayz x:%d y:%d lastZoomFactor: %.16g\n", displayz.x, displayz.y, pcbZoomList[DIM(pcbZoomList)-1] );)
for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
for( unsigned i = 0; i < arrayDim( pcbZoomList ); ++i )
m_ZoomList.push_back( pcbZoomList[i] );
for( unsigned i = 0; i < DIM( pcbGridList ); ++i )
for( unsigned i = 0; i < arrayDim( pcbGridList ); ++i )
AddGrid( pcbGridList[i] );
// Set the working grid size to a reasonable value (in 1/10000 inch)
@ -190,5 +187,5 @@ PCB_SCREEN::~PCB_SCREEN()
int PCB_SCREEN::MilsToIuScalar()
{
return (int)IU_PER_MILS;
return static_cast<int>( IU_PER_MILS );
}

View File

@ -672,7 +672,7 @@ void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter,
SHAPE_POLY_SET outlines;
for( LSEQ seq = aLayerMask.Seq( plot_seq, DIM( plot_seq ) ); seq; ++seq )
for( LSEQ seq = aLayerMask.Seq( plot_seq, arrayDim( plot_seq ) ); seq; ++seq )
{
PCB_LAYER_ID layer = *seq;