← Back to team overview

kicad-developers team mailing list archive

[PATCH 4/6] Avoid C-style array member init (illegal in C++)

 

This is not part of the C++ language, and only supported in some compilers.
---
 common/common_plotDXF_functions.cpp | 26 ++++++++++++++------------
 eeschema/sch_line.cpp               | 21 ++++++++++++++-------
 include/class_plotter.h             |  1 -
 3 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/common/common_plotDXF_functions.cpp b/common/common_plotDXF_functions.cpp
index d66631539..8807591a2 100644
--- a/common/common_plotDXF_functions.cpp
+++ b/common/common_plotDXF_functions.cpp
@@ -94,18 +94,20 @@ static const struct
     { "YELLOW4",    2 }
 };
 
-/**
- * Line types in the boilerplate DXF header.  The
- * element indices correspond to the eeschema line
- * types.
- */
-static const char *dxf_lines[] =
+
+static const char* getDXFLineType( PlotDashType aType )
 {
-    [ PLOTDASHTYPE_SOLID ]   = "CONTINUOUS",
-    [ PLOTDASHTYPE_DASH ]    = "DASHED",
-    [ PLOTDASHTYPE_DOT ]     = "DOTTED",
-    [ PLOTDASHTYPE_DASHDOT ] = "DASHDOT"
-};
+    switch( aType )
+    {
+    case PLOTDASHTYPE_SOLID:    return "CONTINUOUS";
+    case PLOTDASHTYPE_DASH:     return "DASHED";
+    case PLOTDASHTYPE_DOT:      return "DOTTED";
+    case PLOTDASHTYPE_DASHDOT:  return "DASHDOT";
+    }
+
+    wxFAIL_MSG( "Unhandled PlotDashType" );
+    return "CONTINUOUS";
+}
 
 
 // A helper function to create a color name acceptable in DXF files
@@ -565,7 +567,7 @@ void DXF_PLOTTER::PenTo( const wxPoint& pos, char plume )
         wxASSERT( m_currentLineType >= 0 && m_currentLineType < 4 );
         // DXF LINE
         wxString cname = getDXFColorName( m_currentColor );
-        const char *lname = dxf_lines[ m_currentLineType ];
+        const char *lname = getDXFLineType( (PlotDashType) m_currentLineType );
         fprintf( outputFile, "0\nLINE\n8\n%s\n6\n%s\n10\n%g\n20\n%g\n11\n%g\n21\n%g\n",
                  TO_UTF8( cname ), lname,
                  pen_lastpos_dev.x, pen_lastpos_dev.y, pos_dev.x, pos_dev.y );
diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp
index bd1deef88..61e5128ed 100644
--- a/eeschema/sch_line.cpp
+++ b/eeschema/sch_line.cpp
@@ -42,13 +42,20 @@
 
 #include <dialogs/dialog_edit_line_style.h>
 
-const enum wxPenStyle SCH_LINE::PenStyle[] =
+
+static wxPenStyle getwxPenStyle( PlotDashType aType )
 {
-        [PLOTDASHTYPE_SOLID] = wxPENSTYLE_SOLID,
-        [PLOTDASHTYPE_DASH] = wxPENSTYLE_SHORT_DASH,
-        [PLOTDASHTYPE_DOT] = wxPENSTYLE_DOT,
-        [PLOTDASHTYPE_DASHDOT] = wxPENSTYLE_DOT_DASH
-};
+    switch( aType )
+    {
+    case PLOTDASHTYPE_SOLID:    return wxPENSTYLE_SOLID;
+    case PLOTDASHTYPE_DASH:     return wxPENSTYLE_SHORT_DASH;
+    case PLOTDASHTYPE_DOT:      return wxPENSTYLE_DOT;
+    case PLOTDASHTYPE_DASHDOT:  return wxPENSTYLE_DOT_DASH;
+    }
+
+    wxFAIL_MSG( "Unhandled PlotDashType" );
+    return wxPENSTYLE_SOLID;
+}
 
 
 SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
@@ -321,7 +328,7 @@ void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
         end += offset;
 
     GRLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color,
-            PenStyle[ GetLineStyle() ] );
+            getwxPenStyle( (PlotDashType) GetLineStyle() ) );
 
     if( m_startIsDangling )
         DrawDanglingSymbol( panel, DC, start, color );
diff --git a/include/class_plotter.h b/include/class_plotter.h
index e84db08aa..e86fd4fec 100644
--- a/include/class_plotter.h
+++ b/include/class_plotter.h
@@ -85,7 +85,6 @@ enum PlotDashType {
     PLOTDASHTYPE_DASH,
     PLOTDASHTYPE_DOT,
     PLOTDASHTYPE_DASHDOT,
-    PLOTDASHTYPE_COUNT,
 };
 
 /**

References