From 3a07ab5ae5fb89dd44e26fe844b9242eadcc8c50 Mon Sep 17 00:00:00 2001 From: "tlepoix@localhost" Date: Thu, 12 Sep 2024 03:33:49 +0200 Subject: [PATCH] refactor : use std::unreachable() --- src/microstrip/element.cpp | 4 +- src/microstrip/mcorn.cpp | 28 +++++++++++--- src/microstrip/mcoupled.cpp | 38 +++++++++++++------ src/microstrip/mcross.cpp | 74 ++++++++++++++++++++++++++++++------- src/microstrip/mgap.cpp | 14 +++++-- src/microstrip/mlin.cpp | 34 +++++++++++------ src/microstrip/mmbend.cpp | 45 +++++++++++++++------- src/microstrip/mopen.cpp | 8 ++-- src/microstrip/mopen.hpp | 2 + src/microstrip/mrstub.cpp | 42 ++++++++++++++------- src/microstrip/mrstub.hpp | 1 - src/microstrip/mstep.cpp | 25 ++++--------- src/microstrip/mstep.hpp | 2 + src/microstrip/mtee.cpp | 54 +++++++++++++++++++-------- src/microstrip/mvia.cpp | 12 ++++-- src/microstrip/mvia.hpp | 2 + src/microstrip/pac.cpp | 20 ++++++---- src/microstrip/sp.cpp | 4 +- src/microstrip/sp.hpp | 2 +- src/microstrip/subst.cpp | 19 ++++++---- src/microstrip/subst.hpp | 1 - src/schparser.cpp | 8 ++-- src/xycalculator.cpp | 3 ++ 23 files changed, 302 insertions(+), 140 deletions(-) diff --git a/src/microstrip/element.cpp b/src/microstrip/element.cpp index 2aa2a80..bf4e104 100644 --- a/src/microstrip/element.cpp +++ b/src/microstrip/element.cpp @@ -70,12 +70,12 @@ string Element::getSubst() const { //****************************************************************************** long double Element::getX(bool const apply_shift) const { - return(m_shift_x && apply_shift ? m_x+m_shift_x : m_x); // Avoid useless float calcul. + return m_shift_x && apply_shift ? m_x+m_shift_x : m_x; } //****************************************************************************** long double Element::getY(bool const apply_shift) const { - return(m_shift_y && apply_shift ? m_y+m_shift_y : m_y); // Avoid useless float calcul. + return m_shift_y && apply_shift ? m_y+m_shift_y : m_y; } //****************************************************************************** diff --git a/src/microstrip/mcorn.cpp b/src/microstrip/mcorn.cpp index 66b95d9..c6d30ad 100644 --- a/src/microstrip/mcorn.cpp +++ b/src/microstrip/mcorn.cpp @@ -49,7 +49,8 @@ int Mcorn::getNpoint() const { //****************************************************************************** long double Mcorn::getP(int const _n, axis_t const _xy, orientation_t const /*_r*/, origin_t const _abs, bool const /*apply_shift*/) const { - return(_abs ? tab_p[_n][_xy]+(_xy ? m_y : m_x) : tab_p[_n][_xy]); + return _abs ? tab_p[_n][_xy]+(_xy ? m_y : m_x) + : tab_p[_n][_xy]; } //****************************************************************************** @@ -143,6 +144,8 @@ void Mcorn::getStep(int const _net, long double& xstep, long double& ystep) cons xstep= + m_w/2; ystep=0; } + } else { + unreachable(); } } @@ -155,6 +158,7 @@ void Mcorn::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { if(m_mirrorx==0) { @@ -163,6 +167,7 @@ void Mcorn::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMAX; break; case 180: dir=YMIN; break; case 270: dir=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -170,7 +175,10 @@ void Mcorn::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMIN; break; case 180: dir=YMAX; break; case 270: dir=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } } @@ -188,6 +196,7 @@ int Mcorn::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else if(_n==1) { if(m_mirrorx==0) { @@ -196,6 +205,7 @@ int Mcorn::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -203,7 +213,10 @@ int Mcorn::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else { return 1; @@ -225,6 +238,7 @@ int Mcorn::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else if(_net==2 &&(adjacent2.first==nullptr @@ -235,6 +249,7 @@ int Mcorn::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -242,7 +257,10 @@ int Mcorn::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } else { return 1; @@ -256,10 +274,10 @@ int Mcorn::getOemsMeshInterface(int const _net, OemsLine& line) const { //****************************************************************************** bool Mcorn::isOemsMeshInterface(int const _port, long double const _w) const { - if(_port==1 || _port==2) { - return(_w>m_w ? true : false); - } else { - return false; + switch(_port) { + case 1: [[fallthrough]]; + case 2: return _w>m_w ? true : false; + default: return false; } } diff --git a/src/microstrip/mcoupled.cpp b/src/microstrip/mcoupled.cpp index 286ec08..3cb9936 100644 --- a/src/microstrip/mcoupled.cpp +++ b/src/microstrip/mcoupled.cpp @@ -73,14 +73,16 @@ int Mcoupled::getNpoint() const { //****************************************************************************** long double Mcoupled::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) - : rotateX(tab_p[_n][X], tab_p[_n][Y]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? m_y : m_x) : coord); + long double const coord= [&]() { + switch(_r) { + case NOR: return tab_p[_n][_xy]; + case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) + : rotateX(tab_p[_n][X], tab_p[_n][Y]); + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? m_y : m_x) + : coord; } //****************************************************************************** @@ -242,6 +244,8 @@ void Mcoupled::getStep(int const _net, long double& xstep, long double& ystep) c xstep= + (m_w+m_s)/2; ystep= - m_l/2; } + } else { + unreachable(); } } @@ -254,6 +258,7 @@ void Mcoupled::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2 || _net==3) { switch(m_r) { @@ -261,6 +266,7 @@ void Mcoupled::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMIN; break; case 180: dir=XMIN; break; case 270: dir=YMAX; break; + default: unreachable(); } } } @@ -278,6 +284,7 @@ int Mcoupled::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(_n==1) { switch(m_r) { @@ -285,6 +292,7 @@ int Mcoupled::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } } else if(_n==2) { switch(m_r) { @@ -292,6 +300,7 @@ int Mcoupled::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(4, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(4, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(4, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(_n==3) { switch(m_r) { @@ -299,6 +308,7 @@ int Mcoupled::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(6, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(6, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(6, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } } else { return 1; @@ -323,6 +333,7 @@ int Mcoupled::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else if((_net==2 &&(adjacent2.first==nullptr @@ -335,6 +346,7 @@ int Mcoupled::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else { return 1; @@ -348,10 +360,12 @@ int Mcoupled::getOemsMeshInterface(int const _net, OemsLine& line) const { //****************************************************************************** bool Mcoupled::isOemsMeshInterface(int const _port, long double const _w) const { - if(_port==1 || _port==2 || _port==3 || _port==4) { - return(_w>m_w ? true : false); - } else { - return false; + switch(_port) { + case 1: [[fallthrough]]; + case 2: [[fallthrough]]; + case 3: [[fallthrough]]; + case 4: return _w>m_w ? true : false; + default: return false; } } diff --git a/src/microstrip/mcross.cpp b/src/microstrip/mcross.cpp index 00d3685..611d8e4 100644 --- a/src/microstrip/mcross.cpp +++ b/src/microstrip/mcross.cpp @@ -82,14 +82,16 @@ int Mcross::getNpoint() const { //****************************************************************************** long double Mcross::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) - : rotateX(tab_p[_n][X], tab_p[_n][Y]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? m_y : m_x) : coord); + long double const coord= [&]() { + switch(_r) { + case NOR: return tab_p[_n][_xy]; + case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) + : rotateX(tab_p[_n][X], tab_p[_n][Y]); + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? m_y : m_x) + : coord; } int Mcross::setNet1(string const& _net1) { @@ -203,6 +205,8 @@ int Mcross::setP() { tab_p[4][Y]=s2*m_w1/2; tab_p[5][X]= -m_w2/2; tab_p[5][Y]=s2*m_w1/2; + } else { + unreachable(); } } return 0; @@ -355,6 +359,8 @@ void Mcross::getStep(int const _net, long double& xstep, long double& ystep) con ystep=0; xstep= + (Wlong)/2; } + } else { + unreachable(); } } @@ -367,6 +373,7 @@ void Mcross::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { edge=m_w2; @@ -376,6 +383,7 @@ void Mcross::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMIN; break; case 180: dir=YMAX; break; case 270: dir=XMAX; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -383,7 +391,10 @@ void Mcross::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMAX; break; case 180: dir=YMIN; break; case 270: dir=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else if(_net==3) { edge=m_w3; @@ -392,6 +403,7 @@ void Mcross::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMIN; break; case 180: dir=XMIN; break; case 270: dir=YMAX; break; + default: unreachable(); } } else if(_net==4) { edge=m_w4; @@ -401,6 +413,7 @@ void Mcross::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMAX; break; case 180: dir=YMIN; break; case 270: dir=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -408,7 +421,10 @@ void Mcross::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMIN; break; case 180: dir=YMAX; break; case 270: dir=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } } @@ -432,6 +448,7 @@ int Mcross::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(3, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(3, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(3, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -439,7 +456,10 @@ int Mcross::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(3, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(3, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(3, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } else if(m_w1>m_w3 && m_w2m_w4) { switch(m_r) { @@ -470,6 +495,7 @@ int Mcross::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(4, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(4, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(4, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else { return 1; @@ -481,6 +507,7 @@ int Mcross::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(3, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(3, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(3, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else if(m_w1>m_w3 && m_w2m_w4) { if(m_mirrorx==0) { @@ -512,6 +544,7 @@ int Mcross::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(4, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(4, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(4, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -519,7 +552,10 @@ int Mcross::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(4, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(4, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(4, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } else { return 1; @@ -548,6 +584,7 @@ int Mcross::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else if(_net==2 &&(adjacent2.first==nullptr @@ -560,6 +597,7 @@ int Mcross::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(p, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(p, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -567,7 +605,10 @@ int Mcross::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(p, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(p, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else if(_net==3 &&(adjacent3.first==nullptr @@ -581,6 +622,7 @@ int Mcross::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(p, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(p, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else if(_net==4 &&(adjacent4.first==nullptr @@ -596,6 +638,7 @@ int Mcross::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(p, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(p, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -603,7 +646,10 @@ int Mcross::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(p, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(p, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } else { return 1; @@ -621,16 +667,16 @@ bool Mcross::isOemsMeshInterface(int const _port, long double const _w) const { long double Wlong13= (m_w1>m_w3) ? m_w1 : m_w3; long double Wlong24= (m_w2>m_w4) ? m_w2 : m_w4; switch(_port) { - case 1: case 3: return(_w>Wlong13 ? true : false); - case 2: case 4: return(_w>Wlong24 ? true : false); + case 1: case 3: return _w>Wlong13 ? true : false; + case 2: case 4: return _w>Wlong24 ? true : false; default : return false; } } else { switch(_port) { - case 1: return(_w>m_w1 ? true : false); - case 2: return(_w>m_w2 ? true : false); - case 3: return(_w>m_w3 ? true : false); - case 4: return(_w>m_w4 ? true : false); + case 1: return _w>m_w1 ? true : false; + case 2: return _w>m_w2 ? true : false; + case 3: return _w>m_w3 ? true : false; + case 4: return _w>m_w4 ? true : false; default: return false; } } diff --git a/src/microstrip/mgap.cpp b/src/microstrip/mgap.cpp index ebfa7d1..45ae7fc 100644 --- a/src/microstrip/mgap.cpp +++ b/src/microstrip/mgap.cpp @@ -4,6 +4,8 @@ /// @author Thomas Lepoix ///***************************************************************************** +#include + #include "mgap.hpp" using namespace std; @@ -102,6 +104,8 @@ void Mgap::getStep(int const _net, long double& xstep, long double& ystep) const xstep=0; ystep= + m_s/2; } + } else { + unreachable(); } } @@ -114,6 +118,7 @@ void Mgap::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { edge=m_w2; @@ -122,15 +127,16 @@ void Mgap::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMIN; break; case 180: dir=XMIN; break; case 270: dir=YMAX; break; + default: unreachable(); } } } //****************************************************************************** bool Mgap::isOemsMeshInterface(int const _port, long double const /*_w*/) const { - if(_port==1 || _port==2) { - return true; - } else { - return false; + switch(_port) { + case 1: [[fallthrough]]; + case 2: return true; + default: return false; } } diff --git a/src/microstrip/mlin.cpp b/src/microstrip/mlin.cpp index 46fcdf0..fdcfe58 100644 --- a/src/microstrip/mlin.cpp +++ b/src/microstrip/mlin.cpp @@ -56,14 +56,16 @@ int Mlin::getNpoint() const { //****************************************************************************** long double Mlin::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) - : rotateX(tab_p[_n][X], tab_p[_n][Y]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? m_y : m_x) : coord); + long double const coord= [&]() { + switch(_r) { + case NOR: return tab_p[_n][_xy]; + case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) + : rotateX(tab_p[_n][X], tab_p[_n][Y]); + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? m_y : m_x) + : coord; } //****************************************************************************** @@ -125,6 +127,8 @@ void Mlin::getStep(int const _net, long double& xstep, long double& ystep) const xstep=0; ystep= + m_l/2; } + } else { + unreachable(); } } @@ -137,6 +141,7 @@ void Mlin::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { switch(m_r) { @@ -144,6 +149,7 @@ void Mlin::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMIN; break; case 180: dir=XMIN; break; case 270: dir=YMAX; break; + default: unreachable(); } } } @@ -169,6 +175,7 @@ int Mlin::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(_n==1) { // line.position=getP(2, axis, R, ABS); @@ -177,6 +184,7 @@ int Mlin::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } } else { return 1; @@ -206,6 +214,7 @@ int Mlin::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else if(_net==2 &&(adjacent2.first==nullptr @@ -216,6 +225,7 @@ int Mlin::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else { return 1; @@ -229,10 +239,10 @@ int Mlin::getOemsMeshInterface(int const _net, OemsLine& line) const { //****************************************************************************** bool Mlin::isOemsMeshInterface(int const _port, long double const _w) const { - if(_port==1 || _port==2) { - return(_w>m_w ? true : false); - } else { - return false; + switch(_port) { + case 1: [[fallthrough]]; + case 2: return _w>m_w ? true : false; + default: return false; } } diff --git a/src/microstrip/mmbend.cpp b/src/microstrip/mmbend.cpp index 12c1687..69385c5 100644 --- a/src/microstrip/mmbend.cpp +++ b/src/microstrip/mmbend.cpp @@ -49,14 +49,16 @@ int Mmbend::getNpoint() const { //****************************************************************************** long double Mmbend::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) - : rotateX(tab_p[_n][X], tab_p[_n][Y]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? m_y : m_x) : coord); + long double const coord= [&]() { + switch(_r) { + case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) + : rotateX(tab_p[_n][X], tab_p[_n][Y]); + case NOR: return tab_p[_n][_xy]; + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? m_y : m_x) + : coord; } //****************************************************************************** @@ -150,6 +152,8 @@ void Mmbend::getStep(int const _net, long double& xstep, long double& ystep) con xstep= + m_w/2; ystep=0; } + } else { + unreachable(); } } @@ -162,6 +166,7 @@ void Mmbend::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { if(m_mirrorx==0) { @@ -170,6 +175,7 @@ void Mmbend::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMAX; break; case 180: dir=YMIN; break; case 270: dir=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -177,7 +183,10 @@ void Mmbend::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMIN; break; case 180: dir=YMAX; break; case 270: dir=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } } @@ -196,6 +205,7 @@ int Mmbend::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -203,7 +213,10 @@ int Mmbend::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } else if(_n==1) { switch(m_r) { @@ -211,6 +224,7 @@ int Mmbend::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(1, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(1, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(1, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else if(_n==2) { if(m_mirrorx==0) { @@ -219,14 +233,18 @@ int Mmbend::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } - } else { + } else if(m_mirrorx==1) { switch(m_r) { case 0: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; case 90: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else if(_n==3) { switch(m_r) { @@ -234,6 +252,7 @@ int Mmbend::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else { return 1; @@ -248,9 +267,9 @@ int Mmbend::getOemsMeshCore(int const _n, OemsLine& line) const { //****************************************************************************** bool Mmbend::isOemsMeshInterface(int const _port, long double const _w) const { - if(_port==1 || _port==2) { - return(_w>m_w ? true : false); - } else { - return false; + switch(_port) { + case 1: [[fallthrough]]; + case 2: return _w>m_w ? true : false; + default: return false; } } diff --git a/src/microstrip/mopen.cpp b/src/microstrip/mopen.cpp index 8e08438..c7b5a7f 100644 --- a/src/microstrip/mopen.cpp +++ b/src/microstrip/mopen.cpp @@ -51,15 +51,15 @@ void Mopen::getEdge(int const /*_net*/, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } //****************************************************************************** bool Mopen::isOemsMeshInterface(int const _port, long double const /*_w*/) const { - if(_port==1) { - return true; - } else { - return false; + switch(_port) { + case 1: return true; + default: return false; } } diff --git a/src/microstrip/mopen.hpp b/src/microstrip/mopen.hpp index 6d3158d..9c88928 100644 --- a/src/microstrip/mopen.hpp +++ b/src/microstrip/mopen.hpp @@ -6,6 +6,8 @@ #pragma once +#include + #include "element.hpp" //****************************************************************************** diff --git a/src/microstrip/mrstub.cpp b/src/microstrip/mrstub.cpp index d78e3ad..c00c229 100644 --- a/src/microstrip/mrstub.cpp +++ b/src/microstrip/mrstub.cpp @@ -7,6 +7,7 @@ #define _USE_MATH_DEFINES #include +#include #include "mrstub.hpp" using namespace std; @@ -74,14 +75,16 @@ int Mrstub::getNpoint() const { //****************************************************************************** long double Mrstub::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) - : rotateX(tab_p[_n][X], tab_p[_n][Y]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? m_y : m_x) : coord); + long double const coord= [&]() { + switch(_r) { + case NOR: return tab_p[_n][_xy]; + case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) + : rotateX(tab_p[_n][X], tab_p[_n][Y]); + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? m_y : m_x) + : coord; } //****************************************************************************** @@ -124,6 +127,7 @@ void Mrstub::getEdge(int const /*_net*/, long double& edge, short& dir) const { case 90: dir=XMAX; break; case 180: dir=YMIN; break; case 270: dir=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -131,7 +135,10 @@ void Mrstub::getEdge(int const /*_net*/, long double& edge, short& dir) const { case 90: dir=XMIN; break; case 180: dir=YMAX; break; case 270: dir=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } @@ -149,6 +156,7 @@ int Mrstub::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -156,7 +164,10 @@ int Mrstub::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } else if(_n==1) { switch(m_r) { @@ -164,6 +175,7 @@ int Mrstub::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else if(_n==2) { int p=(m_npoint-5)/2+3; @@ -173,14 +185,18 @@ int Mrstub::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(p, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(p, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } - } else { + } else if(m_mirrorx==1) { switch(m_r) { case 0: line.position=getP(p, Y, R, ABS); line.direction=YMAX; break; case 90: line.position=getP(p, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(p, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else if(_n==3) { int p=m_npoint-1; @@ -189,6 +205,7 @@ int Mrstub::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(p, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(p, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(p, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else { return 1; @@ -203,9 +220,8 @@ int Mrstub::getOemsMeshCore(int const _n, OemsLine& line) const { //****************************************************************************** bool Mrstub::isOemsMeshInterface(int const _port, long double const _w) const { - if(_port==1) { - return(_w>m_w ? true : false); - } else { - return false; + switch(_port) { + case 1: return _w>m_w ? true : false; + default: return false; } } diff --git a/src/microstrip/mrstub.hpp b/src/microstrip/mrstub.hpp index 9f4e322..614d631 100644 --- a/src/microstrip/mrstub.hpp +++ b/src/microstrip/mrstub.hpp @@ -7,7 +7,6 @@ #pragma once #include -#include #include "element.hpp" diff --git a/src/microstrip/mstep.cpp b/src/microstrip/mstep.cpp index 20db300..d85f32e 100644 --- a/src/microstrip/mstep.cpp +++ b/src/microstrip/mstep.cpp @@ -70,6 +70,7 @@ void Mstep::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { edge=m_w2; @@ -78,6 +79,7 @@ void Mstep::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMIN; break; case 180: dir=XMIN; break; case 270: dir=YMAX; break; + default: unreachable(); } } } @@ -103,26 +105,15 @@ int Mstep::getOemsMeshCore(int const _n, OemsLine& line) const { && adjacent2.first!=nullptr) { is_w1_longer=false; } else { - return 1; // Unreachable + unreachable(); } switch(m_r) { - case 0: - line.position=m_x; - line.direction=(is_w1_longer ? XMAX : XMIN); - break; - case 90: - line.position=m_y; - line.direction=(is_w1_longer ? YMIN : YMAX); - break; - case 180: - line.position=m_x; - line.direction=(is_w1_longer ? XMIN : XMAX); - break; - case 270: - line.position=m_y; - line.direction=(is_w1_longer ? YMAX : YMIN); - break; + case 0: line.position=m_x; line.direction=(is_w1_longer ? XMAX : XMIN); break; + case 90: line.position=m_y; line.direction=(is_w1_longer ? YMIN : YMAX); break; + case 180: line.position=m_x; line.direction=(is_w1_longer ? XMIN : XMAX); break; + case 270: line.position=m_y; line.direction=(is_w1_longer ? YMAX : YMIN); break; + default: unreachable(); } line.label=m_label; diff --git a/src/microstrip/mstep.hpp b/src/microstrip/mstep.hpp index f347cd7..77bb976 100644 --- a/src/microstrip/mstep.hpp +++ b/src/microstrip/mstep.hpp @@ -6,6 +6,8 @@ #pragma once +#include + #include "element.hpp" //****************************************************************************** diff --git a/src/microstrip/mtee.cpp b/src/microstrip/mtee.cpp index 5a247c5..57c8771 100644 --- a/src/microstrip/mtee.cpp +++ b/src/microstrip/mtee.cpp @@ -70,14 +70,16 @@ int Mtee::getNpoint() const { //****************************************************************************** long double Mtee::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][0], tab_p[_n][1]) - : rotateX(tab_p[_n][0], tab_p[_n][1]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? m_y : m_x) : coord); + long double const coord= [&]() { + switch(_r) { + case NOR: return tab_p[_n][_xy]; + case R: return _xy ? rotateY(tab_p[_n][0], tab_p[_n][1]) + : rotateX(tab_p[_n][0], tab_p[_n][1]); + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? m_y : m_x) + : coord; } //****************************************************************************** @@ -234,6 +236,8 @@ void Mtee::getStep(int const _net, long double& xstep, long double& ystep) const xstep= + (Wlong)/2; ystep=0; } + } else { + unreachable(); } } @@ -246,6 +250,7 @@ void Mtee::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { edge=m_w2; @@ -254,6 +259,7 @@ void Mtee::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMIN; break; case 180: dir=XMIN; break; case 270: dir=YMAX; break; + default: unreachable(); } } else if(_net==3) { edge=m_w3; @@ -263,6 +269,7 @@ void Mtee::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMAX; break; case 180: dir=YMIN; break; case 270: dir=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -270,7 +277,10 @@ void Mtee::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=XMIN; break; case 180: dir=YMAX; break; case 270: dir=XMAX; break; + default: unreachable(); } + } else { + unreachable(); } } } @@ -293,6 +303,7 @@ int Mtee::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -300,7 +311,10 @@ int Mtee::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(2, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else if(_n==1) { switch(m_r) { @@ -308,6 +322,7 @@ int Mtee::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(4, Y, R, ABS); line.direction=(m_w1>m_w2 ? YMIN : YMAX); break; case 180: line.position=getP(4, X, R, ABS); line.direction=(m_w1>m_w2 ? XMIN : XMAX); break; case 270: line.position=getP(4, Y, R, ABS); line.direction=(m_w1>m_w2 ? YMAX : YMIN); break; + default: unreachable(); } } else if(_n==2) { if(m_mirrorx==0) { @@ -316,6 +331,7 @@ int Mtee::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(5, X, R, ABS); line.direction=XMIN; break; case 180: line.position=getP(5, Y, R, ABS); line.direction=YMAX; break; case 270: line.position=getP(5, X, R, ABS); line.direction=XMAX; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -323,7 +339,10 @@ int Mtee::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=getP(5, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(5, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(5, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else { return 1; @@ -345,6 +364,7 @@ int Mtee::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break; case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; + default: unreachable(); } } else if(_net==2 &&(adjacent2.first==nullptr @@ -354,6 +374,7 @@ int Mtee::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break; case 180: line.position=getP(2, X, R, ABS); line.direction=XMIN; break; case 270: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break; + default: unreachable(); } } else if(_net==3 &&(adjacent3.first==nullptr @@ -364,6 +385,7 @@ int Mtee::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } } else if(m_mirrorx==1) { switch(m_r) { @@ -371,7 +393,10 @@ int Mtee::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break; case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break; case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break; + default: unreachable(); } + } else { + unreachable(); } } else { return 1; @@ -385,14 +410,11 @@ int Mtee::getOemsMeshInterface(int const _net, OemsLine& line) const { //****************************************************************************** bool Mtee::isOemsMeshInterface(int const _port, long double const _w) const { - if(_port==1) { - return(_w>m_w1 ? true : false); - } else if(_port==2) { - return(_w>m_w2 ? true : false); - } else if(_port==3) { - return(_w>m_w3 ? true : false); - } else { - return false; + switch(_port) { + case 1: return _w>m_w1 ? true : false; + case 2: return _w>m_w2 ? true : false; + case 3: return _w>m_w3 ? true : false; + default: return false; } } diff --git a/src/microstrip/mvia.cpp b/src/microstrip/mvia.cpp index bfb01ff..464c60c 100644 --- a/src/microstrip/mvia.cpp +++ b/src/microstrip/mvia.cpp @@ -51,6 +51,7 @@ void Mvia::getEdge(int const /*_net*/, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } @@ -67,6 +68,7 @@ int Mvia::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=m_x+m_d/2; line.direction=XMAX; break; case 180: line.position=m_y-m_d/2; line.direction=YMIN; break; case 270: line.position=m_x-m_d/2; line.direction=XMIN; break; + default: unreachable(); } } else if(_n==1) { switch(m_r) { @@ -74,6 +76,7 @@ int Mvia::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=m_y-m_d/2; line.direction=YMIN; break; case 180: line.position=m_x-m_d/2; line.direction=XMIN; break; case 270: line.position=m_y+m_d/2; line.direction=YMAX; break; + default: unreachable(); } } else if(_n==2) { switch(m_r) { @@ -81,6 +84,7 @@ int Mvia::getOemsMeshCore(int const _n, OemsLine& line) const { case 90: line.position=m_x-m_d/2; line.direction=XMIN; break; case 180: line.position=m_y+m_d/2; line.direction=YMAX; break; case 270: line.position=m_x+m_d/2; line.direction=XMAX; break; + default: unreachable(); } } else { return 1; @@ -102,6 +106,7 @@ int Mvia::getOemsMeshInterface(int const _net, OemsLine& line) const { case 90: line.position=m_y+m_d/2; line.direction=YMAX; break; case 180: line.position=m_x+m_d/2; line.direction=XMAX; break; case 270: line.position=m_y-m_d/2; line.direction=YMIN; break; + default: unreachable(); } } else { return 1; @@ -115,10 +120,9 @@ int Mvia::getOemsMeshInterface(int const _net, OemsLine& line) const { //****************************************************************************** bool Mvia::isOemsMeshInterface(int const _port, long double const _w) const { - if(_port==1) { - return(_w>m_d ? true : false); - } else { - return false; + switch(_port) { + case 1: return _w>m_d ? true : false; + default: return false; } } diff --git a/src/microstrip/mvia.hpp b/src/microstrip/mvia.hpp index 0d3674a..82c6526 100644 --- a/src/microstrip/mvia.hpp +++ b/src/microstrip/mvia.hpp @@ -6,6 +6,8 @@ #pragma once +#include + #include "element.hpp" //****************************************************************************** diff --git a/src/microstrip/pac.cpp b/src/microstrip/pac.cpp index da4a4e9..ead92b2 100644 --- a/src/microstrip/pac.cpp +++ b/src/microstrip/pac.cpp @@ -81,14 +81,16 @@ int Pac::getNpoint() const { //****************************************************************************** long double Pac::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const apply_shift) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) - : rotateX(tab_p[_n][X], tab_p[_n][Y]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? getY(apply_shift) : getX(apply_shift)) : coord); + long double const coord = [&](){ + switch(_r) { + case NOR: return tab_p[_n][_xy]; + case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) + : rotateX(tab_p[_n][X], tab_p[_n][Y]); + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? getY(apply_shift) : getX(apply_shift)) + : coord; } //****************************************************************************** @@ -100,6 +102,7 @@ void Pac::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMAX; break; case 180: dir=XMAX; break; case 270: dir=YMIN; break; + default: unreachable(); } } else if(_net==2) { switch(m_r) { @@ -107,6 +110,7 @@ void Pac::getEdge(int const _net, long double& edge, short& dir) const { case 90: dir=YMIN; break; case 180: dir=XMIN; break; case 270: dir=YMAX; break; + default: unreachable(); } } } diff --git a/src/microstrip/sp.cpp b/src/microstrip/sp.cpp index 1456a55..4e0ad36 100644 --- a/src/microstrip/sp.cpp +++ b/src/microstrip/sp.cpp @@ -15,12 +15,12 @@ Sp::Sp(string _label, string _type, bool const _mirrorx, short const _r, - std::string const _simtype, + string _simtype, long double const _fstart, long double const _fstop, unsigned long const _n) : Element(std::move(_label), std::move(_type), true, _mirrorx, _r, 0, ""), - m_simtype(_simtype), + m_simtype(std::move(_simtype)), m_fstart(_fstart), m_fstop(_fstop), m_n(_n) diff --git a/src/microstrip/sp.hpp b/src/microstrip/sp.hpp index 7fb8a6a..7240c5f 100644 --- a/src/microstrip/sp.hpp +++ b/src/microstrip/sp.hpp @@ -21,7 +21,7 @@ public : std::string _type, bool const _mirrorx, short const _r, - std::string const _simtype, + std::string _simtype, long double const _fstart, long double const _fstop, unsigned long const _n); diff --git a/src/microstrip/subst.cpp b/src/microstrip/subst.cpp index ef624a0..ed134ec 100644 --- a/src/microstrip/subst.cpp +++ b/src/microstrip/subst.cpp @@ -4,6 +4,8 @@ /// @author Thomas Lepoix ///***************************************************************************** +#include + #include "subst.hpp" using namespace std; @@ -113,13 +115,16 @@ int Subst::getNpoint() const { //****************************************************************************** long double Subst::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const { - long double coord; - if(_r) { - coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) : rotateX(tab_p[_n][X], tab_p[_n][Y]); - } else { - coord=tab_p[_n][_xy]; - } - return(_abs ? coord+(_xy ? m_y : m_x) : coord); + long double const coord= [&]() { + switch(_r) { + case NOR: return tab_p[_n][_xy]; + case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y]) + : rotateX(tab_p[_n][X], tab_p[_n][Y]); + default: unreachable(); + } + } (); + return _abs ? coord+(_xy ? m_y : m_x) + : coord; } //****************************************************************************** diff --git a/src/microstrip/subst.hpp b/src/microstrip/subst.hpp index e535f42..0879fd4 100644 --- a/src/microstrip/subst.hpp +++ b/src/microstrip/subst.hpp @@ -7,7 +7,6 @@ #pragma once #include -#include #include "element.hpp" diff --git a/src/schparser.cpp b/src/schparser.cpp index 5fd46de..afcb0f4 100644 --- a/src/schparser.cpp +++ b/src/schparser.cpp @@ -952,9 +952,9 @@ string SchParser::check_void(string const match, string const label) const { //****************************************************************************** string SchParser::mstub_shift(bool const xy, string const str, string const r) const { - if(r=="0") return(xy ? to_string(stoi(str)-10) : str); - else if(r=="1") return(xy ? str : to_string(stoi(str)-10)); - else if(r=="2") return(xy ? to_string(stoi(str)+10) : str); - else if(r=="3") return(xy ? str : to_string(stoi(str)+10)); + if(r=="0") return xy ? to_string(stoi(str)-10) : str; + else if(r=="1") return xy ? str : to_string(stoi(str)-10); + else if(r=="2") return xy ? to_string(stoi(str)+10) : str; + else if(r=="3") return xy ? str : to_string(stoi(str)+10); else return str; // Never happens } diff --git a/src/xycalculator.cpp b/src/xycalculator.cpp index c17df18..43bb407 100644 --- a/src/xycalculator.cpp +++ b/src/xycalculator.cpp @@ -79,6 +79,7 @@ void XyCalculator::resolve_pac_shapes() { // Only axis matters case XMIN: case XMAX: pac->setR(0); break; case YMIN: case YMAX: pac->setR(90); break; + default: unreachable(); } } } @@ -288,6 +289,8 @@ void XyCalculator::place_blocks() { if(is_new_subst) shift_y+=prev->margin+block->margin; shift_y+=prev->margin+block->margin; } break; + default: + unreachable(); } //shift=set_margin(prev, block, data); cout << "Xshift : " << shift_x << endl;