← Back to team overview

kicad-developers team mailing list archive

[PATCH 12/19] ElectricPinType: Separate PINTYPE_COUNT from enum

 

This allows us to use compiler warnings for enum coverage in switch
statements.
---
 eeschema/lib_pin.cpp | 6 +++---
 eeschema/pin_type.h  | 7 +++++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index e210d11..99be160 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -92,7 +92,7 @@ static const BITMAP_DEF iconsPinsElectricalType[] =
 
 const wxString LIB_PIN::GetCanonicalElectricalTypeName( ElectricPinType aType )
 {
-    assert( aType >= 0 && aType < PINTYPE_COUNT );
+    assert( aType >= 0 && aType < (int) PINTYPE_COUNT );
 
     // These strings are the canonical name of the electrictal type
     // Not translated, no space in name, only ASCII chars.
@@ -113,7 +113,7 @@ const wxString LIB_PIN::GetCanonicalElectricalTypeName( ElectricPinType aType )
         wxT( "NotConnected" )
     };
 
-    if( aType > PINTYPE_COUNT )
+    if( aType > (int) PINTYPE_COUNT )
         return wxT( "???" );
 
     return msgPinElectricType[ aType ];
@@ -354,7 +354,7 @@ void LIB_PIN::SetShape( PinShape aShape )
 
 void LIB_PIN::SetType( ElectricPinType aType )
 {
-    assert( aType >= 0 && aType < PINTYPE_COUNT );
+    assert( aType >= 0 && aType < (int) PINTYPE_COUNT );
 
     if( m_type != aType )
     {
diff --git a/eeschema/pin_type.h b/eeschema/pin_type.h
index f525347..d1bfbcc 100644
--- a/eeschema/pin_type.h
+++ b/eeschema/pin_type.h
@@ -42,8 +42,11 @@ enum ElectricPinType {
     PIN_POWER_OUT,
     PIN_OPENCOLLECTOR,
     PIN_OPENEMITTER,
-    PIN_NC,             /* No connect */
-    PINTYPE_COUNT       /* End of List (no used as pin type) */
+    PIN_NC              /* No connect */
+};
+
+enum {
+    PINTYPE_COUNT = PIN_NC + 1
 };
 
 #endif

Follow ups

References