From 31e626f279709301bc2498b0fc89497398cac18c Mon Sep 17 00:00:00 2001 From: Ian McInerney <ian.s.mcinerney@ieee.org> Date: Mon, 26 Oct 2020 23:49:11 +0000 Subject: [PATCH] Cleanup creation of all our smart pointers --- common/fp_lib_table.cpp | 2 +- common/libeval_compiler/libeval_compiler.cpp | 6 +-- common/pgm_base.cpp | 2 +- eeschema/class_library.cpp | 2 +- eeschema/dialogs/dialog_sheet_properties.cpp | 2 +- eeschema/eeschema.cpp | 4 +- eeschema/libarch.cpp | 2 +- eeschema/project_rescue.cpp | 4 +- .../sch_plugins/eagle/sch_eagle_plugin.cpp | 30 ++++++------ .../sch_plugins/kicad/sch_sexpr_parser.cpp | 46 +++++++++---------- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 4 +- .../sch_plugins/legacy/sch_legacy_plugin.cpp | 34 +++++++------- eeschema/sheet.cpp | 2 +- eeschema/sim/spice_simulator.cpp | 2 +- eeschema/symbol_lib_table.cpp | 2 +- gerbview/gerbview_printout.cpp | 2 +- pcb_calculator/datafile_read_write.cpp | 3 +- pcbnew/class_dimension.cpp | 2 +- pcbnew/class_zone.cpp | 2 +- pcbnew/fp_tree_model_adapter.cpp | 2 +- pcbnew/graphics_cleaner.cpp | 6 +-- .../import_gfx/graphics_importer_buffer.cpp | 2 +- .../import_gfx/graphics_importer_pcbnew.cpp | 2 +- pcbnew/netlist_reader/netlist_reader.cpp | 2 +- pcbnew/pcb_expr_evaluator.cpp | 14 ++---- pcbnew/pcb_shape.cpp | 2 +- pcbnew/pcbnew_printout.cpp | 2 +- pcbnew/plugins/eagle/eagle_plugin.cpp | 2 +- pcbnew/plugins/geda/gpcb_plugin.cpp | 2 +- pcbnew/plugins/kicad/pcb_parser.cpp | 29 ++++++------ pcbnew/plugins/legacy/legacy_plugin.cpp | 20 ++++---- pcbnew/router/pns_kicad_iface.cpp | 34 ++++++-------- pcbnew/router/pns_node.cpp | 2 +- pcbnew/tracks_cleaner.cpp | 6 +-- qa/eeschema/eeschema_test_utils.cpp | 2 +- qa/eeschema/test_lib_part.cpp | 6 +-- 36 files changed, 137 insertions(+), 151 deletions(-) diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 18a775c024..0d5d6da677 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -87,7 +87,7 @@ void FP_LIB_TABLE::Parse( LIB_TABLE_LEXER* in ) while( ( tok = in->NextTok() ) != T_RIGHT ) { - std::unique_ptr< FP_LIB_TABLE_ROW > row( new FP_LIB_TABLE_ROW ); + std::unique_ptr<FP_LIB_TABLE_ROW> row = std::make_unique<FP_LIB_TABLE_ROW>(); if( tok == T_EOF ) in->Expecting( T_RIGHT ); diff --git a/common/libeval_compiler/libeval_compiler.cpp b/common/libeval_compiler/libeval_compiler.cpp index 69081171f8..eabc4da0cd 100644 --- a/common/libeval_compiler/libeval_compiler.cpp +++ b/common/libeval_compiler/libeval_compiler.cpp @@ -690,7 +690,7 @@ void TREE_NODE::SetUop( int aOp, double aValue ) { delete uop; - std::unique_ptr<VALUE> val( new VALUE( aValue ) ); + std::unique_ptr<VALUE> val = std::make_unique<VALUE>( aValue ); uop = new UOP( aOp, std::move( val ) ); } @@ -699,7 +699,7 @@ void TREE_NODE::SetUop( int aOp, const wxString& aValue, bool aStringIsWildcard { delete uop; - std::unique_ptr<VALUE> val( new VALUE( aValue, aStringIsWildcard ) ); + std::unique_ptr<VALUE> val = std::make_unique<VALUE>( aValue, aStringIsWildcard ); uop = new UOP( aOp, std::move( val ) ); } @@ -785,7 +785,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext ) if( !m_tree ) { - std::unique_ptr<VALUE> val( new VALUE( 1.0 ) ); + std::unique_ptr<VALUE> val = std::make_unique<VALUE>( 1.0 ); // Empty expression returns true aCode->AddOp( new UOP( TR_UOP_PUSH_VALUE, std::move(val) ) ); return true; diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index b48f78c8fb..d0bbf01231 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -219,7 +219,7 @@ bool PGM_BASE::InitPgm() return false; } - m_settings_manager = std::unique_ptr<SETTINGS_MANAGER>( new SETTINGS_MANAGER ); + m_settings_manager = std::make_unique<SETTINGS_MANAGER>(); // Something got in the way of settings load: can't continue if( !m_settings_manager->IsOK() ) diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 66a0b546fa..9022fe0c2c 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -237,7 +237,7 @@ LIB_PART* PART_LIB::ReplacePart( LIB_PART* aOldPart, LIB_PART* aNewPart ) PART_LIB* PART_LIB::LoadLibrary( const wxString& aFileName ) { - std::unique_ptr<PART_LIB> lib( new PART_LIB( SCH_LIB_TYPE::LT_EESCHEMA, aFileName ) ); + std::unique_ptr<PART_LIB> lib = std::make_unique<PART_LIB>( SCH_LIB_TYPE::LT_EESCHEMA, aFileName ); std::vector<LIB_PART*> parts; // This loads the library. diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index 236e077add..54b551f754 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -541,7 +541,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena if( useScreen ) { // Create a temporary sheet for recursion testing to prevent a possible recursion error. - std::unique_ptr< SCH_SHEET> tmpSheet( new SCH_SHEET ); + std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>(); tmpSheet->GetFields()[SHEETNAME] = m_fields->at( SHEETNAME ); tmpSheet->GetFields()[SHEETFILENAME].SetText( nativeFileName.GetFullPath() ); tmpSheet->SetScreen( useScreen ); diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 4a2202e61d..79c30af7d3 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -62,7 +62,7 @@ namespace SCH { static std::unique_ptr<SCHEMATIC> readSchematicFromFile( const std::string& aFilename ) { auto pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ); - std::unique_ptr<SCHEMATIC> schematic( new SCHEMATIC ( nullptr ) ); + std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>( nullptr ); auto &manager = Pgm().GetSettingsManager(); @@ -100,7 +100,7 @@ static std::unique_ptr<SCHEMATIC> readSchematicFromFile( const std::string& aFil bool generateSchematicNetlist( const wxString& aFilename, wxString& aNetlist ) { - std::unique_ptr<SCHEMATIC> schematic ( readSchematicFromFile( aFilename.ToStdString() ) ); + std::unique_ptr<SCHEMATIC> schematic = readSchematicFromFile( aFilename.ToStdString() ); NETLIST_EXPORTER_KICAD exporter( schematic.get() ); STRING_FORMATTER formatter; diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index 33d526ea9a..24bfc4f83a 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -69,7 +69,7 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) SCH_SCREENS screens( Schematic().Root() ); // Create a new empty library to archive components: - std::unique_ptr<PART_LIB> archLib( new PART_LIB( SCH_LIB_TYPE::LT_EESCHEMA, aFileName ) ); + std::unique_ptr<PART_LIB> archLib = std::make_unique<PART_LIB>( SCH_LIB_TYPE::LT_EESCHEMA, aFileName ); // Save symbols to file only when the library will be fully filled archLib->EnableBuffering(); diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index da470ff9ae..6b8ad2445e 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -643,8 +643,8 @@ void LEGACY_RESCUER::OpenRescueLibrary() { wxFileName fn = GetRescueLibraryFileName( m_schematic ); - std::unique_ptr<PART_LIB> rescue_lib( - new PART_LIB( SCH_LIB_TYPE::LT_EESCHEMA, fn.GetFullPath() ) ); + std::unique_ptr<PART_LIB> rescue_lib = std::make_unique<PART_LIB>( SCH_LIB_TYPE::LT_EESCHEMA, + fn.GetFullPath() ); m_rescue_lib = std::move( rescue_lib ); m_rescue_lib->EnableBuffering(); diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index 541d7f8522..0f36aac11a 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -556,7 +556,7 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode ) while( partNode ) { - std::unique_ptr<EPART> epart( new EPART( partNode ) ); + std::unique_ptr<EPART> epart = std::make_unique<EPART>( partNode ); // N.B. Eagle parts are case-insensitive in matching but we keep the display case m_partlist[epart->name.Upper()] = std::move( epart ); @@ -596,8 +596,8 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode ) while( sheetNode ) { - wxPoint pos = wxPoint( x * Mils2iu( 1000 ), y * Mils2iu( 1000 ) ); - std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET( m_rootSheet, pos ) ); + wxPoint pos = wxPoint( x * Mils2iu( 1000 ), y * Mils2iu( 1000 ) ); + std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>( m_rootSheet, pos ); SCH_SCREEN* screen = new SCH_SCREEN( m_schematic ); sheet->SetScreen( screen ); @@ -964,7 +964,7 @@ void SCH_EAGLE_PLUGIN::loadSegments( SCH_LINE* SCH_EAGLE_PLUGIN::loadWire( wxXmlNode* aWireNode ) { - std::unique_ptr<SCH_LINE> wire( new SCH_LINE ); + std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>(); auto ewire = EWIRE( aWireNode ); @@ -989,7 +989,7 @@ SCH_LINE* SCH_EAGLE_PLUGIN::loadWire( wxXmlNode* aWireNode ) SCH_JUNCTION* SCH_EAGLE_PLUGIN::loadJunction( wxXmlNode* aJunction ) { - std::unique_ptr<SCH_JUNCTION> junction( new SCH_JUNCTION ); + std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>(); auto ejunction = EJUNCTION( aJunction ); wxPoint pos( ejunction.x.ToSchUnits(), -ejunction.y.ToSchUnits() ); @@ -1011,9 +1011,9 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadLabel( wxXmlNode* aLabelNode, const wxString& aN std::unique_ptr<SCH_TEXT> label; if( global ) - label.reset( new SCH_GLOBALLABEL ); + label = std::make_unique<SCH_GLOBALLABEL>(); else - label.reset( new SCH_LABEL ); + label = std::make_unique<SCH_LABEL>(); label->SetPosition( elabelpos ); label->SetText( escapeName( elabel.netname ) ); @@ -1131,7 +1131,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) } LIB_ID libId( getLibName(), kisymbolname ); - std::unique_ptr<SCH_COMPONENT> component( new SCH_COMPONENT() ); + std::unique_ptr<SCH_COMPONENT> component = std::make_unique<SCH_COMPONENT>(); component->SetLibId( libId ); component->SetUnit( unit ); component->SetPosition( wxPoint( einstance.x.ToSchUnits(), -einstance.y.ToSchUnits() ) ); @@ -1596,7 +1596,7 @@ LIB_ITEM* SCH_EAGLE_PLUGIN::loadSymbolWire( // if the wire is an arc if( ewire.curve ) { - std::unique_ptr<LIB_ARC> arc( new LIB_ARC( aPart.get() ) ); + std::unique_ptr<LIB_ARC> arc = std::make_unique<LIB_ARC>( aPart.get() ); wxPoint center = ConvertArcCenter( begin, end, *ewire.curve * -1 ); double radius = sqrt( abs( ( ( center.x - begin.x ) * ( center.x - begin.x ) ) @@ -1651,7 +1651,7 @@ LIB_ITEM* SCH_EAGLE_PLUGIN::loadSymbolWire( } else { - std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart.get() ) ); + std::unique_ptr<LIB_POLYLINE> polyLine = std::make_unique<LIB_POLYLINE>( aPart.get() ); polyLine->AddPoint( begin ); polyLine->AddPoint( end ); @@ -1666,7 +1666,7 @@ LIB_ITEM* SCH_EAGLE_PLUGIN::loadSymbolWire( LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aPolygonNode, int aGateNumber ) { - std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart.get() ) ); + std::unique_ptr<LIB_POLYLINE> polyLine = std::make_unique<LIB_POLYLINE>( aPart.get() ); EPOLYGON epoly( aPolygonNode ); wxXmlNode* vertex = aPolygonNode->GetChildren(); @@ -1696,7 +1696,7 @@ LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolPolyLine( LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aPin, EPIN* aEPin, int aGateNumber ) { - std::unique_ptr<LIB_PIN> pin( new LIB_PIN( aPart.get() ) ); + std::unique_ptr<LIB_PIN> pin = std::make_unique<LIB_PIN>( aPart.get() ); pin->SetPosition( wxPoint( aEPin->x.ToSchUnits(), aEPin->y.ToSchUnits() ) ); pin->SetName( aEPin->name ); pin->SetUnit( aGateNumber ); @@ -1799,7 +1799,7 @@ LIB_PIN* SCH_EAGLE_PLUGIN::loadPin( LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( std::unique_ptr<LIB_PART>& aPart, wxXmlNode* aLibText, int aGateNumber ) { - std::unique_ptr<LIB_TEXT> libtext( new LIB_TEXT( aPart.get() ) ); + std::unique_ptr<LIB_TEXT> libtext = std::make_unique<LIB_TEXT>( aPart.get() ); ETEXT etext( aLibText ); libtext->SetUnit( aGateNumber ); @@ -1823,8 +1823,8 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( SCH_TEXT* SCH_EAGLE_PLUGIN::loadPlainText( wxXmlNode* aSchText ) { - std::unique_ptr<SCH_TEXT> schtext( new SCH_TEXT() ); - ETEXT etext = ETEXT( aSchText ); + std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>(); + ETEXT etext = ETEXT( aSchText ); const wxString& thetext = aSchText->GetNodeContent(); schtext->SetText( thetext.IsEmpty() ? "\" \"" : escapeName( thetext ) ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 7100ff4ed0..a71846a532 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -129,7 +129,7 @@ LIB_PART* SCH_SEXPR_PARSER::ParseSymbol( LIB_PART_MAP& aSymbolLibMap, int aFileV wxString name; wxString error; LIB_ITEM* item; - std::unique_ptr<LIB_PART> symbol( new LIB_PART( wxEmptyString ) ); + std::unique_ptr<LIB_PART> symbol = std::make_unique<LIB_PART>( wxEmptyString ); m_requiredVersion = aFileVersion; symbol->SetUnitCount( 1 ); @@ -722,7 +722,7 @@ void SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_PART>& aSymbol ) wxString error; wxString name; wxString value; - std::unique_ptr<LIB_FIELD> field( new LIB_FIELD( aSymbol.get(), MANDATORY_FIELDS ) ); + std::unique_ptr<LIB_FIELD> field = std::make_unique<LIB_FIELD>( aSymbol.get(), MANDATORY_FIELDS ); T token = NextTok(); @@ -849,7 +849,7 @@ LIB_ARC* SCH_SEXPR_PARSER::parseArc() wxPoint pos; FILL_PARAMS fill; bool hasMidPoint = false; - std::unique_ptr<LIB_ARC> arc( new LIB_ARC( nullptr ) ); + std::unique_ptr<LIB_ARC> arc = std::make_unique<LIB_ARC>( nullptr ); arc->SetUnit( m_unit ); arc->SetConvert( m_convert ); @@ -967,7 +967,7 @@ LIB_BEZIER* SCH_SEXPR_PARSER::parseBezier() T token; FILL_PARAMS fill; - std::unique_ptr<LIB_BEZIER> bezier( new LIB_BEZIER( nullptr ) ); + std::unique_ptr<LIB_BEZIER> bezier = std::make_unique<LIB_BEZIER>( nullptr ); bezier->SetUnit( m_unit ); bezier->SetConvert( m_convert ); @@ -1032,7 +1032,7 @@ LIB_CIRCLE* SCH_SEXPR_PARSER::parseCircle() T token; FILL_PARAMS fill; - std::unique_ptr<LIB_CIRCLE> circle( new LIB_CIRCLE( nullptr ) ); + std::unique_ptr<LIB_CIRCLE> circle = std::make_unique<LIB_CIRCLE>( nullptr ); circle->SetUnit( m_unit ); circle->SetConvert( m_convert ); @@ -1135,7 +1135,7 @@ LIB_PIN* SCH_SEXPR_PARSER::parsePin() T token; wxString tmp; wxString error; - std::unique_ptr<LIB_PIN> pin( new LIB_PIN( nullptr ) ); + std::unique_ptr<LIB_PIN> pin = std::make_unique<LIB_PIN>( nullptr ); pin->SetUnit( m_unit ); pin->SetConvert( m_convert ); @@ -1309,7 +1309,7 @@ LIB_POLYLINE* SCH_SEXPR_PARSER::parsePolyLine() T token; FILL_PARAMS fill; - std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( nullptr ) ); + std::unique_ptr<LIB_POLYLINE> polyLine = std::make_unique<LIB_POLYLINE>( nullptr ); polyLine->SetUnit( m_unit ); polyLine->SetConvert( m_convert ); @@ -1374,7 +1374,7 @@ LIB_RECTANGLE* SCH_SEXPR_PARSER::parseRectangle() T token; FILL_PARAMS fill; - std::unique_ptr<LIB_RECTANGLE> rectangle( new LIB_RECTANGLE( nullptr ) ); + std::unique_ptr<LIB_RECTANGLE> rectangle = std::make_unique<LIB_RECTANGLE>( nullptr ); rectangle->SetUnit( m_unit ); rectangle->SetConvert( m_convert ); @@ -1432,7 +1432,7 @@ LIB_TEXT* SCH_SEXPR_PARSER::parseText() T token; wxString tmp; wxString error; - std::unique_ptr<LIB_TEXT> text( new LIB_TEXT( nullptr ) ); + std::unique_ptr<LIB_TEXT> text = std::make_unique<LIB_TEXT>( nullptr ); text->SetUnit( m_unit ); text->SetConvert( m_convert ); @@ -1674,7 +1674,7 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) // Empty property values are valid. value = FromUTF8(); - std::unique_ptr<SCH_FIELD> field( new SCH_FIELD( wxDefaultPosition, -1, aParent, name ) ); + std::unique_ptr<SCH_FIELD> field = std::make_unique<SCH_FIELD>( wxDefaultPosition, -1, aParent, name ); field->SetText( value ); field->SetVisible( true ); @@ -1741,7 +1741,7 @@ SCH_SHEET_PIN* SCH_SEXPR_PARSER::parseSchSheetPin( SCH_SHEET* aSheet ) THROW_IO_ERROR( error ); } - std::unique_ptr<SCH_SHEET_PIN> sheetPin( new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), name ) ); + std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( aSheet, wxPoint( 0, 0 ), name ); token = NextTok(); @@ -2119,7 +2119,7 @@ SCH_COMPONENT* SCH_SEXPR_PARSER::parseSchematicSymbol() wxString error; wxString libName; SCH_FIELD* field; - std::unique_ptr<SCH_COMPONENT> symbol( new SCH_COMPONENT() ); + std::unique_ptr<SCH_COMPONENT> symbol = std::make_unique<SCH_COMPONENT>(); TRANSFORM transform; std::set<int> fieldIDsRead; @@ -2331,7 +2331,7 @@ SCH_BITMAP* SCH_SEXPR_PARSER::parseImage() wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as an image." ) ); T token; - std::unique_ptr<SCH_BITMAP> bitmap( new SCH_BITMAP() ); + std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>(); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -2404,7 +2404,7 @@ SCH_SHEET* SCH_SEXPR_PARSER::parseSheet() FILL_PARAMS fill; SCH_FIELD* field; std::vector<SCH_FIELD> fields; - std::unique_ptr<SCH_SHEET> sheet( new SCH_SHEET() ); + std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>(); std::set<int> fieldIDsRead; for( token = NextTok(); token != T_RIGHT; token = NextTok() ) @@ -2499,7 +2499,7 @@ SCH_JUNCTION* SCH_SEXPR_PARSER::parseJunction() wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a junction." ) ); T token; - std::unique_ptr<SCH_JUNCTION> junction( new SCH_JUNCTION() ); + std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>(); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -2549,7 +2549,7 @@ SCH_NO_CONNECT* SCH_SEXPR_PARSER::parseNoConnect() wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a no connect." ) ); T token; - std::unique_ptr<SCH_NO_CONNECT> no_connect( new SCH_NO_CONNECT() ); + std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>(); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -2581,7 +2581,7 @@ SCH_BUS_WIRE_ENTRY* SCH_SEXPR_PARSER::parseBusEntry() T token; STROKE_PARAMS stroke; - std::unique_ptr<SCH_BUS_WIRE_ENTRY> busEntry( new SCH_BUS_WIRE_ENTRY() ); + std::unique_ptr<SCH_BUS_WIRE_ENTRY> busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>(); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -2626,7 +2626,7 @@ SCH_LINE* SCH_SEXPR_PARSER::parseLine() { T token; STROKE_PARAMS stroke; - std::unique_ptr<SCH_LINE> line( new SCH_LINE() ); + std::unique_ptr<SCH_LINE> line = std::make_unique<SCH_LINE>(); switch( CurTok() ) { @@ -2688,10 +2688,10 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText() switch( CurTok() ) { - case T_text: text.reset( new SCH_TEXT ); break; - case T_label: text.reset( new SCH_LABEL ); break; - case T_global_label: text.reset( new SCH_GLOBALLABEL ); break; - case T_hierarchical_label: text.reset( new SCH_HIERLABEL ); break; + case T_text: text = std::make_unique<SCH_TEXT>(); break; + case T_label: text = std::make_unique<SCH_LABEL>(); break; + case T_global_label: text = std::make_unique<SCH_GLOBALLABEL>(); break; + case T_hierarchical_label: text = std::make_unique<SCH_HIERLABEL>(); break; default: wxCHECK_MSG( false, nullptr, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as text." ) ); @@ -2783,7 +2783,7 @@ void SCH_SEXPR_PARSER::parseBusAlias( SCH_SCREEN* aScreen ) wxCHECK( aScreen, /* void */ ); T token; - auto busAlias = std::make_shared< BUS_ALIAS >( aScreen ); + auto busAlias = std::make_shared<BUS_ALIAS>( aScreen ); NeedSYMBOL(); busAlias->SetName( FromUTF8() ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index a44263a00a..df9d45873d 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -431,7 +431,7 @@ SCH_SHEET* SCH_SEXPR_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema if( aAppendToMe == NULL ) { // Clean up any allocated memory if an exception occurs loading the schematic. - std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET( aSchematic ) ); + std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic ); newSheet->SetFileName( aFileName ); m_rootSheet = newSheet.get(); loadHierarchy( newSheet.get() ); @@ -1481,7 +1481,7 @@ void SCH_SEXPR_PLUGIN_CACHE::Save() // Write through symlinks, don't replace them. wxFileName fn = GetRealFile(); - std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) ); + auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() ); formatter->Print( 0, "(kicad_symbol_lib (version %d) (generator kicad_symbol_editor)\n", SEXPR_SYMBOL_LIB_FILE_VERSION ); diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index e654af96dc..9d5fca9855 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -632,7 +632,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchem if( aAppendToMe == NULL ) { // Clean up any allocated memory if an exception occurs loading the schematic. - std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET( aSchematic ) ); + std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic ); newSheet->SetFileName( aFileName ); m_rootSheet = newSheet.get(); loadHierarchy( newSheet.get() ); @@ -970,7 +970,7 @@ void SCH_LEGACY_PLUGIN::loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScr SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader ) { - std::unique_ptr< SCH_SHEET > sheet( new SCH_SHEET() ); + std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>(); const char* line = aReader.ReadLine(); @@ -1018,7 +1018,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader ) else // Sheet pin. { // Use a unique_ptr so that we clean up in the case of a throw - std::unique_ptr< SCH_SHEET_PIN > sheetPin( new SCH_SHEET_PIN( sheet.get() ) ); + std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( sheet.get() ); sheetPin->SetNumber( fieldId ); @@ -1080,7 +1080,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader ) SCH_BITMAP* SCH_LEGACY_PLUGIN::loadBitmap( LINE_READER& aReader ) { - std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP ); + std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>(); const char* line = aReader.Line(); @@ -1165,7 +1165,7 @@ SCH_BITMAP* SCH_LEGACY_PLUGIN::loadBitmap( LINE_READER& aReader ) SCH_JUNCTION* SCH_LEGACY_PLUGIN::loadJunction( LINE_READER& aReader ) { - std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION ); + std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>(); const char* line = aReader.Line(); @@ -1187,7 +1187,7 @@ SCH_JUNCTION* SCH_LEGACY_PLUGIN::loadJunction( LINE_READER& aReader ) SCH_NO_CONNECT* SCH_LEGACY_PLUGIN::loadNoConnect( LINE_READER& aReader ) { - std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT ); + std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>(); const char* line = aReader.Line(); @@ -1209,7 +1209,7 @@ SCH_NO_CONNECT* SCH_LEGACY_PLUGIN::loadNoConnect( LINE_READER& aReader ) SCH_LINE* SCH_LEGACY_PLUGIN::loadWire( LINE_READER& aReader ) { - std::unique_ptr< SCH_LINE > wire( new SCH_LINE ); + std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>(); const char* line = aReader.Line(); @@ -1311,18 +1311,18 @@ SCH_BUS_ENTRY_BASE* SCH_LEGACY_PLUGIN::loadBusEntry( LINE_READER& aReader ) wxCHECK( strCompare( "Entry", line, &line ), NULL ); - std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry; + std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry; if( strCompare( "Wire", line, &line ) ) { - busEntry.reset( new SCH_BUS_WIRE_ENTRY ); + busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>(); if( !strCompare( "Line", line, &line ) ) SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line ); } else if( strCompare( "Bus", line, &line ) ) { - busEntry.reset( new SCH_BUS_BUS_ENTRY ); + busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>(); if( !strCompare( "Bus", line, &line ) ) SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line ); @@ -1367,7 +1367,7 @@ SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader ) wxCHECK( strCompare( "Text", line, &line ), NULL ); - std::unique_ptr< SCH_TEXT> text; + std::unique_ptr<SCH_TEXT> text; if( strCompare( "Notes", line, &line ) ) text.reset( new SCH_TEXT ); @@ -1379,9 +1379,9 @@ SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader ) { // Prior to version 2, the SCH_GLOBALLABEL object did not exist. if( m_version == 1 ) - text.reset( new SCH_HIERLABEL ); + text = std::make_unique<SCH_HIERLABEL>(); else - text.reset( new SCH_GLOBALLABEL ); + text = std::make_unique<SCH_GLOBALLABEL>(); } else SCH_PARSE_ERROR( "unknown Text type", aReader, line ); @@ -1484,7 +1484,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader ) wxCHECK( strCompare( "$Comp", line, &line ), NULL ); - std::unique_ptr< SCH_COMPONENT > component( new SCH_COMPONENT() ); + std::unique_ptr<SCH_COMPONENT> component = std::make_unique<SCH_COMPONENT>(); line = aReader.ReadLine(); @@ -1796,7 +1796,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader ) std::shared_ptr<BUS_ALIAS> SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen ) { - auto busAlias = std::make_shared< BUS_ALIAS >( aScreen ); + auto busAlias = std::make_shared<BUS_ALIAS>( aScreen ); const char* line = aReader.Line(); wxCHECK( strCompare( "BusAlias", line, &line ), NULL ); @@ -2789,7 +2789,7 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::LoadPart( LINE_READER& aReader, int aMajorVer SCH_PARSE_ERROR( "invalid symbol definition", aReader, line ); // Read DEF line: - std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) ); + std::unique_ptr<LIB_PART> part = std::make_unique<LIB_PART>( wxEmptyString ); wxString name, prefix, tmp; @@ -3727,7 +3727,7 @@ void SCH_LEGACY_PLUGIN_CACHE::Save( bool aSaveDocFile ) // Write through symlinks, don't replace them wxFileName fn = GetRealFile(); - std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) ); + auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() ); formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR ); formatter->Print( 0, "#encoding utf-8\n"); diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index f5e208f658..a1b30e96af 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -112,7 +112,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier SCH_SCREEN* currentScreen = aHierarchy->LastScreen(); SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( aFileName ); SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( schFileType ) ); - std::unique_ptr< SCH_SHEET> newSheet( new SCH_SHEET( &Schematic() ) ); + std::unique_ptr< SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( &Schematic() ); // This will cause the sheet UUID to be set to the loaded schematic UUID. This is required // to ensure all of the sheet paths in any subsheets are correctly generated. diff --git a/eeschema/sim/spice_simulator.cpp b/eeschema/sim/spice_simulator.cpp index 2065071038..5b97e89aec 100644 --- a/eeschema/sim/spice_simulator.cpp +++ b/eeschema/sim/spice_simulator.cpp @@ -33,7 +33,7 @@ std::shared_ptr<SPICE_SIMULATOR> SPICE_SIMULATOR::CreateInstance( const std::str static std::shared_ptr<SPICE_SIMULATOR> ngspiceInstance; if( !ngspiceInstance ) - ngspiceInstance.reset( new NGSPICE ); + ngspiceInstance = std::make_shared<NGSPICE>(); return ngspiceInstance; } diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 3b9c7410cb..67a645dd62 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -115,7 +115,7 @@ void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in ) while( ( tok = in->NextTok() ) != T_RIGHT ) { - std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row( new SYMBOL_LIB_TABLE_ROW ); + std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row = std::make_unique<SYMBOL_LIB_TABLE_ROW>(); if( tok == T_EOF ) in->Expecting( T_RIGHT ); diff --git a/gerbview/gerbview_printout.cpp b/gerbview/gerbview_printout.cpp index df854c5f2c..76d656df7c 100644 --- a/gerbview/gerbview_printout.cpp +++ b/gerbview/gerbview_printout.cpp @@ -105,5 +105,5 @@ EDA_RECT GERBVIEW_PRINTOUT::getBoundingBox() std::unique_ptr<KIGFX::PAINTER> GERBVIEW_PRINTOUT::getPainter( KIGFX::GAL* aGal ) { - return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::GERBVIEW_PAINTER( aGal ) ); + return std::make_unique<KIGFX::GERBVIEW_PAINTER>( aGal ); } diff --git a/pcb_calculator/datafile_read_write.cpp b/pcb_calculator/datafile_read_write.cpp index 077c164085..d813f8f496 100644 --- a/pcb_calculator/datafile_read_write.cpp +++ b/pcb_calculator/datafile_read_write.cpp @@ -86,8 +86,7 @@ bool PCB_CALCULATOR_FRAME::WriteDataFile() // Switch the locale to standard C (needed to read/write floating point numbers) LOCALE_IO toggle; - std::unique_ptr<PCB_CALCULATOR_DATAFILE> - datafile( new PCB_CALCULATOR_DATAFILE( &m_RegulatorList ) ); + auto datafile = std::make_unique<PCB_CALCULATOR_DATAFILE>( &m_RegulatorList ); try { diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index 05ea548d71..8f43747963 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -387,7 +387,7 @@ std::vector<SHAPE*> DIMENSION::MakeEffectiveShapes() const std::shared_ptr<SHAPE> DIMENSION::GetEffectiveShape( PCB_LAYER_ID aLayer ) const { - return std::shared_ptr<SHAPE>( new SHAPE_COMPOUND( MakeEffectiveShapes() ) ); + return std::make_shared<SHAPE_COMPOUND>( MakeEffectiveShapes() ); } diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 09b66365ce..0dca567ac5 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -1353,7 +1353,7 @@ std::shared_ptr<SHAPE> ZONE_CONTAINER::GetEffectiveShape( PCB_LAYER_ID aLayer ) if( m_FilledPolysList.find( aLayer ) == m_FilledPolysList.end() ) { - shape.reset( new SHAPE_NULL ); + shape = std::make_shared<SHAPE_NULL>(); } else { diff --git a/pcbnew/fp_tree_model_adapter.cpp b/pcbnew/fp_tree_model_adapter.cpp index b5772f0bc8..ce2c765c3f 100644 --- a/pcbnew/fp_tree_model_adapter.cpp +++ b/pcbnew/fp_tree_model_adapter.cpp @@ -59,7 +59,7 @@ std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString auto fullListStart = GFootprintList.GetList().begin(); auto fullListEnd = GFootprintList.GetList().end(); - std::unique_ptr<FOOTPRINT_INFO> dummy( new FOOTPRINT_INFO_IMPL( aLibName, wxEmptyString ) ); + std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString ); // List is sorted, so use a binary search to find the range of footnotes for our library auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy, diff --git a/pcbnew/graphics_cleaner.cpp b/pcbnew/graphics_cleaner.cpp index b513a5197b..79734266e6 100644 --- a/pcbnew/graphics_cleaner.cpp +++ b/pcbnew/graphics_cleaner.cpp @@ -145,7 +145,7 @@ void GRAPHICS_CLEANER::cleanupSegments() if( isNullSegment( segment ) ) { - std::shared_ptr<CLEANUP_ITEM> item( new CLEANUP_ITEM( CLEANUP_NULL_GRAPHIC ) ); + std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_NULL_GRAPHIC ); item->SetItems( segment ); m_itemsList->push_back( item ); @@ -164,7 +164,7 @@ void GRAPHICS_CLEANER::cleanupSegments() if( areEquivalent( segment, segment2 ) ) { - std::shared_ptr<CLEANUP_ITEM> item( new CLEANUP_ITEM( CLEANUP_DUPLICATE_GRAPHIC ) ); + std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_DUPLICATE_GRAPHIC ); item->SetItems( segment2 ); m_itemsList->push_back( item ); @@ -292,7 +292,7 @@ void GRAPHICS_CLEANER::mergeRects() right->shape->SetFlags( IS_DELETED ); bottom->shape->SetFlags( IS_DELETED ); - std::shared_ptr<CLEANUP_ITEM> item( new CLEANUP_ITEM( CLEANUP_LINES_TO_RECT ) ); + std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_LINES_TO_RECT ); item->SetItems( left->shape, top->shape, right->shape, bottom->shape ); m_itemsList->push_back( item ); diff --git a/pcbnew/import_gfx/graphics_importer_buffer.cpp b/pcbnew/import_gfx/graphics_importer_buffer.cpp index 9d74822c14..45dc6839c6 100644 --- a/pcbnew/import_gfx/graphics_importer_buffer.cpp +++ b/pcbnew/import_gfx/graphics_importer_buffer.cpp @@ -30,7 +30,7 @@ using namespace std; template <typename T, typename... Args> static std::unique_ptr<T> make_shape( const Args&... aArguments ) { - return std::unique_ptr<T>( new T( aArguments... ) ); + return std::make_unique<T>( aArguments... ); } void GRAPHICS_IMPORTER_BUFFER::AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth ) diff --git a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp index 9b0a2431bf..f19328d836 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp @@ -189,7 +189,7 @@ std::pair<std::unique_ptr<BOARD_ITEM>, EDA_TEXT*> GRAPHICS_IMPORTER_BOARD::creat std::unique_ptr<PCB_SHAPE> GRAPHICS_IMPORTER_MODULE::createDrawing() { - return std::unique_ptr<PCB_SHAPE>( new FP_SHAPE( m_module ) ); + return std::make_unique<FP_SHAPE>( m_module ); } diff --git a/pcbnew/netlist_reader/netlist_reader.cpp b/pcbnew/netlist_reader/netlist_reader.cpp index 7c335cc4d0..d3a485e6f6 100644 --- a/pcbnew/netlist_reader/netlist_reader.cpp +++ b/pcbnew/netlist_reader/netlist_reader.cpp @@ -82,7 +82,7 @@ NETLIST_READER* NETLIST_READER::GetNetlistReader( NETLIST* aNetlist, { wxASSERT( aNetlist != NULL ); - std::unique_ptr< FILE_LINE_READER > file_rdr(new FILE_LINE_READER( aNetlistFileName ) ); + std::unique_ptr<FILE_LINE_READER> file_rdr = std::make_unique<FILE_LINE_READER>( aNetlistFileName ); NETLIST_FILE_T type = GuessNetlistFileType( file_rdr.get() ); file_rdr->Rewind(); diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 36abeefba7..721f36c731 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -585,21 +585,13 @@ std::unique_ptr<LIBEVAL::VAR_REF> PCB_EXPR_UCODE::CreateVarRef( const wxString& std::unique_ptr<PCB_EXPR_VAR_REF> vref; if( aVar == "A" ) - { - vref.reset( new PCB_EXPR_VAR_REF( 0 ) ); - } + vref = std::make_unique<PCB_EXPR_VAR_REF>( 0 ); else if( aVar == "B" ) - { - vref.reset( new PCB_EXPR_VAR_REF( 1 ) ); - } + vref = std::make_unique<PCB_EXPR_VAR_REF>( 1 ); else if( aVar == "L" ) - { - vref.reset( new PCB_EXPR_VAR_REF( 2 ) ); - } + vref = std::make_unique<PCB_EXPR_VAR_REF>( 2 ); else - { return nullptr; - } if( aField.length() == 0 ) // return reference to base object { diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index 037511b17a..c6b758860d 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -1172,7 +1172,7 @@ std::vector<SHAPE*> PCB_SHAPE::MakeEffectiveShapes() const std::shared_ptr<SHAPE> PCB_SHAPE::GetEffectiveShape( PCB_LAYER_ID aLayer ) const { - return std::shared_ptr<SHAPE>( new SHAPE_COMPOUND( MakeEffectiveShapes() ) ); + return std::make_shared<SHAPE_COMPOUND>( MakeEffectiveShapes() ); } diff --git a/pcbnew/pcbnew_printout.cpp b/pcbnew/pcbnew_printout.cpp index 4f635623b6..b09f404abd 100644 --- a/pcbnew/pcbnew_printout.cpp +++ b/pcbnew/pcbnew_printout.cpp @@ -274,7 +274,7 @@ EDA_RECT PCBNEW_PRINTOUT::getBoundingBox() std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal ) { - return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::PCB_PRINT_PAINTER( aGal ) ); + return std::make_unique<KIGFX::PCB_PRINT_PAINTER>( aGal ); } diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp index 9a6aab5ad8..91b4f70fcd 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.cpp +++ b/pcbnew/plugins/eagle/eagle_plugin.cpp @@ -1528,7 +1528,7 @@ void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e, FP_TEXT* txt, MODULE* EAGLE_PLUGIN::makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) { - std::unique_ptr<MODULE> m( new MODULE( m_board ) ); + std::unique_ptr<MODULE> m = std::make_unique<MODULE>( m_board ); LIB_ID fpID; fpID.Parse( aPkgName, LIB_ID::ID_PCB, true ); diff --git a/pcbnew/plugins/geda/gpcb_plugin.cpp b/pcbnew/plugins/geda/gpcb_plugin.cpp index 0d3343903b..ef49d07b02 100644 --- a/pcbnew/plugins/geda/gpcb_plugin.cpp +++ b/pcbnew/plugins/geda/gpcb_plugin.cpp @@ -323,7 +323,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) wxPoint textPos; wxString msg; wxArrayString parameters; - std::unique_ptr<MODULE> module( new MODULE( NULL ) ); + std::unique_ptr<MODULE> module = std::make_unique<MODULE>( nullptr ); if( aLineReader->ReadLine() == NULL ) diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index 50a6f5a123..4e7676e374 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -2096,7 +2096,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE( bool aAllowCirclesZeroWidth ) T token; wxPoint pt; - std::unique_ptr<PCB_SHAPE> shape( new PCB_SHAPE( NULL ) ); + std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( nullptr ); switch( CurTok() ) { @@ -2296,7 +2296,7 @@ PCB_TEXT* PCB_PARSER::parsePCB_TEXT() T token; - std::unique_ptr<PCB_TEXT> text( new PCB_TEXT( m_board ) ); + std::unique_ptr<PCB_TEXT> text = std::make_unique<PCB_TEXT>( m_board ); NeedSYMBOLorNUMBER(); text->SetText( FromUTF8() ); @@ -2786,7 +2786,7 @@ MODULE* PCB_PARSER::parseMODULE_unchecked( wxArrayString* aInitialComments ) LIB_ID fpid; int attributes = 0; - std::unique_ptr<MODULE> module( new MODULE( m_board ) ); + std::unique_ptr<MODULE> module = std::make_unique<MODULE>( m_board ); std::map<wxString, wxString> properties; @@ -3110,7 +3110,7 @@ FP_TEXT* PCB_PARSER::parseFP_TEXT() T token = NextTok(); - std::unique_ptr<FP_TEXT> text( new FP_TEXT( NULL ) ); + std::unique_ptr<FP_TEXT> text = std::make_unique<FP_TEXT>( nullptr ); switch( token ) { @@ -3211,7 +3211,7 @@ FP_SHAPE* PCB_PARSER::parseFP_SHAPE() wxPoint pt; T token; - std::unique_ptr<FP_SHAPE> shape( new FP_SHAPE( NULL ) ); + std::unique_ptr<FP_SHAPE> shape = std::make_unique<FP_SHAPE>( nullptr ); switch( CurTok() ) { @@ -3418,7 +3418,7 @@ D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent ) wxSize sz; wxPoint pt; - std::unique_ptr< D_PAD > pad( new D_PAD( aParent ) ); + std::unique_ptr<D_PAD> pad = std::make_unique<D_PAD>( aParent ); // File only contains a token if KeepTopBottom is true pad->SetKeepTopBottom( false ); @@ -4017,7 +4017,7 @@ ARC* PCB_PARSER::parseARC() wxPoint pt; T token; - std::unique_ptr<ARC> arc( new ARC( m_board ) ); + std::unique_ptr<ARC> arc = std::make_unique<ARC>( m_board ); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -4094,7 +4094,7 @@ TRACK* PCB_PARSER::parseTRACK() wxPoint pt; T token; - std::unique_ptr< TRACK > track( new TRACK( m_board ) ); + std::unique_ptr<TRACK> track = std::make_unique<TRACK>( m_board ); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -4165,7 +4165,7 @@ VIA* PCB_PARSER::parseVIA() wxPoint pt; T token; - std::unique_ptr< VIA > via( new VIA( m_board ) ); + std::unique_ptr<VIA> via = std::make_unique<VIA>( m_board ); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -4280,9 +4280,12 @@ ZONE_CONTAINER* PCB_PARSER::parseZONE_CONTAINER( BOARD_ITEM_CONTAINER* aParent ) if( dynamic_cast<MODULE*>( aParent ) ) // The zone belongs a footprint inModule = true; - std::unique_ptr<ZONE_CONTAINER> zone( inModule ? - new MODULE_ZONE_CONTAINER( aParent ) : - new ZONE_CONTAINER( aParent ) ); + std::unique_ptr<ZONE_CONTAINER> zone; + + if( inModule ) + zone = std::make_unique<MODULE_ZONE_CONTAINER>( aParent ); + else + zone = std::make_unique<ZONE_CONTAINER>( aParent ); zone->SetPriority( 0 ); @@ -4817,7 +4820,7 @@ PCB_TARGET* PCB_PARSER::parsePCB_TARGET() wxPoint pt; T token; - std::unique_ptr< PCB_TARGET > target( new PCB_TARGET( NULL ) ); + std::unique_ptr<PCB_TARGET> target = std::make_unique<PCB_TARGET>( nullptr ); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { diff --git a/pcbnew/plugins/legacy/legacy_plugin.cpp b/pcbnew/plugins/legacy/legacy_plugin.cpp index 24c82405b4..f108bc7dc4 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.cpp +++ b/pcbnew/plugins/legacy/legacy_plugin.cpp @@ -237,10 +237,6 @@ static inline char* ReadLine( LINE_READER* rdr, const char* caller ) #endif - -using std::unique_ptr; - - static EDA_TEXT_HJUSTIFY_T horizJustify( const char* horizontal ) { if( !strcmp( "L", horizontal ) ) @@ -406,7 +402,7 @@ BOARD* LEGACY_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, m_board->SetFileName( aFileName ); // delete on exception, iff I own m_board, according to aAppendToMe - unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board ); + std::unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board ); FILE_LINE_READER reader( aFileName ); @@ -438,7 +434,7 @@ void LEGACY_PLUGIN::loadAllSections( bool doAppend ) if( TESTLINE( "$MODULE" ) ) { - unique_ptr<MODULE> module( new MODULE( m_board ) ); + std::unique_ptr<MODULE> module = std::make_unique<MODULE>( m_board ); LIB_ID fpid; std::string fpName = StrPurge( line + SZ( "$MODULE" ) ); @@ -1402,7 +1398,7 @@ void LEGACY_PLUGIN::loadMODULE( MODULE* aModule ) void LEGACY_PLUGIN::loadPAD( MODULE* aModule ) { - unique_ptr<D_PAD> pad( new D_PAD( aModule ) ); + std::unique_ptr<D_PAD> pad = std::make_unique<D_PAD>( aModule ); char* line; char* saveptr; @@ -1656,7 +1652,7 @@ void LEGACY_PLUGIN::loadMODULE_EDGE( MODULE* aModule ) THROW_IO_ERROR( m_error ); } - unique_ptr<FP_SHAPE> dwg( new FP_SHAPE( aModule, shape ) ); // a drawing + std::unique_ptr<FP_SHAPE> dwg = std::make_unique<FP_SHAPE>( aModule, shape ); // a drawing const char* data; @@ -1921,7 +1917,7 @@ void LEGACY_PLUGIN::loadPCB_LINE() $EndDRAWSEGMENT */ - unique_ptr<PCB_SHAPE> dseg( new PCB_SHAPE( m_board ) ); + std::unique_ptr<PCB_SHAPE> dseg = std::make_unique<PCB_SHAPE>( m_board ); char* line; char* saveptr; @@ -2438,7 +2434,7 @@ void LEGACY_PLUGIN::loadNETCLASS() void LEGACY_PLUGIN::loadZONE_CONTAINER() { - unique_ptr<ZONE_CONTAINER> zc( new ZONE_CONTAINER( m_board ) ); + std::unique_ptr<ZONE_CONTAINER> zc = std::make_unique<ZONE_CONTAINER>( m_board ); ZONE_BORDER_DISPLAY_STYLE outline_hatch = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; bool endContour = false; @@ -2732,7 +2728,7 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER() void LEGACY_PLUGIN::loadDIMENSION() { - unique_ptr<ALIGNED_DIMENSION> dim( new ALIGNED_DIMENSION( m_board ) ); + std::unique_ptr<ALIGNED_DIMENSION> dim = std::make_unique<ALIGNED_DIMENSION>( m_board ); char* line; @@ -3248,7 +3244,7 @@ void LP_CACHE::LoadModules( LINE_READER* aReader ) // test first for the $MODULE, even before reading because of INDEX bug. if( TESTLINE( "$MODULE" ) ) { - unique_ptr<MODULE> module( new MODULE( m_owner->m_board ) ); + std::unique_ptr<MODULE> module = std::make_unique<MODULE>( m_owner->m_board ); std::string footprintName = StrPurge( line + SZ( "$MODULE" ) ); diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index ecd61c3283..7a4780d587 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -798,7 +798,7 @@ std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( D_PAD* aPad ) return NULL; } - std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID ); + std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>(); if( aPad->GetDrillSize().x > 0 ) { @@ -862,9 +862,8 @@ std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( D_PAD* aPad ) std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( TRACK* aTrack ) { - std::unique_ptr< PNS::SEGMENT > segment( - new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() ) - ); + auto segment = std::make_unique<PNS::SEGMENT>( SEG( aTrack->GetStart(), aTrack->GetEnd() ), + aTrack->GetNetCode() ); segment->SetWidth( aTrack->GetWidth() ); segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) ); @@ -879,10 +878,9 @@ std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( TRACK* aTrack ) std::unique_ptr<PNS::ARC> PNS_KICAD_IFACE_BASE::syncArc( ARC* aArc ) { - std::unique_ptr< PNS::ARC > arc( - new PNS::ARC( SHAPE_ARC( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), - aArc->GetWidth() ), aArc->GetNetCode() ) - ); + auto arc = std::make_unique<PNS::ARC>( SHAPE_ARC( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), + aArc->GetWidth() ), + aArc->GetNetCode() ); arc->SetLayers( LAYER_RANGE( aArc->GetLayer() ) ); arc->SetParent( aArc ); @@ -901,14 +899,12 @@ std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE_BASE::syncVia( VIA* aVia ) PCB_LAYER_ID top, bottom; aVia->LayerPair( &top, &bottom ); - std::unique_ptr<PNS::VIA> via( new PNS::VIA( - aVia->GetPosition(), - LAYER_RANGE( aVia->TopLayer(), aVia->BottomLayer() ), - aVia->GetWidth(), - aVia->GetDrillValue(), - aVia->GetNetCode(), - aVia->GetViaType() ) - ); + auto via = std::make_unique<PNS::VIA>( aVia->GetPosition(), + LAYER_RANGE( aVia->TopLayer(), aVia->BottomLayer() ), + aVia->GetWidth(), + aVia->GetDrillValue(), + aVia->GetNetCode(), + aVia->GetViaType() ); via->SetParent( aVia ); @@ -968,7 +964,7 @@ bool PNS_KICAD_IFACE_BASE::syncZone( PNS::NODE* aWorld, ZONE_CONTAINER* aZone, triShape->Append( b ); triShape->Append( c ); - std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID ); + std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>(); solid->SetLayer( layer ); solid->SetNet( -1 ); @@ -1002,7 +998,7 @@ bool PNS_KICAD_IFACE_BASE::syncTextItem( PNS::NODE* aWorld, EDA_TEXT* aText, PCB { VECTOR2I start( textShape[jj] ); VECTOR2I end( textShape[jj+1] ); - std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID ); + std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>(); solid->SetLayer( aLayer ); solid->SetNet( -1 ); @@ -1048,7 +1044,7 @@ bool PNS_KICAD_IFACE_BASE::syncGraphicalItem( PNS::NODE* aWorld, PCB_SHAPE* aIte for( SHAPE* shape : aItem->MakeEffectiveShapes() ) { - std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID ); + std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>(); if( aItem->GetLayer() == Edge_Cuts ) solid->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) ); diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index 4906e1cbe4..bb353c6710 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -602,7 +602,7 @@ void NODE::Add( LINE& aLine, bool aAllowRedundant ) } else { - std::unique_ptr< SEGMENT > newseg( new SEGMENT( aLine, s ) ); + std::unique_ptr<SEGMENT> newseg = std::make_unique<SEGMENT>( aLine, s ); aLine.Link( newseg.get() ); Add( std::move( newseg ), true ); } diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index 5d5bcce6d6..243d2833dd 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -192,7 +192,7 @@ bool TRACKS_CLEANER::deleteDanglingTracks( bool aVia ) int errorCode = ( track->Type() != PCB_VIA_T ) ? CLEANUP_DANGLING_TRACK : CLEANUP_DANGLING_VIA; - std::shared_ptr<CLEANUP_ITEM> item( new CLEANUP_ITEM( errorCode ) ); + std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( errorCode ); item->SetItems( track ); m_itemsList->push_back( item ); @@ -241,7 +241,7 @@ void TRACKS_CLEANER::deleteTracksInPads() if( poly.IsEmpty() ) { - std::shared_ptr<CLEANUP_ITEM> item( new CLEANUP_ITEM( CLEANUP_TRACK_IN_PAD ) ); + std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_TRACK_IN_PAD ); item->SetItems( track ); m_itemsList->push_back( item ); @@ -473,7 +473,7 @@ bool TRACKS_CLEANER::mergeCollinearSegments( TRACK* aSeg1, TRACK* aSeg2 ) return false; } - std::shared_ptr<CLEANUP_ITEM> item( new CLEANUP_ITEM( CLEANUP_MERGE_TRACKS ) ); + std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_MERGE_TRACKS ); item->SetItems( aSeg1, aSeg2 ); m_itemsList->push_back( item ); diff --git a/qa/eeschema/eeschema_test_utils.cpp b/qa/eeschema/eeschema_test_utils.cpp index 5bfbe6e5b7..57227da33d 100644 --- a/qa/eeschema/eeschema_test_utils.cpp +++ b/qa/eeschema/eeschema_test_utils.cpp @@ -63,7 +63,7 @@ wxFileName KI_TEST::GetEeschemaTestDataDir() std::unique_ptr<SCHEMATIC> ReadSchematicFromFile( const std::string& aFilename ) { auto pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ); - std::unique_ptr<SCHEMATIC> schematic( new SCHEMATIC ( nullptr ) ); + std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>( nullptr ); schematic->Reset(); schematic->SetRoot( pi->Load( aFilename, schematic.get() ) ); diff --git a/qa/eeschema/test_lib_part.cpp b/qa/eeschema/test_lib_part.cpp index 23635235de..20770927f0 100644 --- a/qa/eeschema/test_lib_part.cpp +++ b/qa/eeschema/test_lib_part.cpp @@ -441,9 +441,9 @@ BOOST_AUTO_TEST_CASE( GetUnitDrawItems ) */ BOOST_AUTO_TEST_CASE( Inheritance ) { - std::unique_ptr< LIB_PART > parent( new LIB_PART( "parent" ) ); + std::unique_ptr<LIB_PART> parent = std::make_unique<LIB_PART>( "parent" ); BOOST_CHECK( parent->IsRoot() ); - std::unique_ptr< LIB_PART > child1( new LIB_PART( "child1", parent.get() ) ); + std::unique_ptr<LIB_PART> child1 = std::make_unique<LIB_PART>( "child1", parent.get() ); BOOST_CHECK( child1->IsAlias() ); PART_SPTR parentRef = child1->GetParent().lock(); BOOST_CHECK( parentRef ); @@ -464,7 +464,7 @@ BOOST_AUTO_TEST_CASE( Inheritance ) */ BOOST_AUTO_TEST_CASE( CopyConstructor ) { - std::shared_ptr< LIB_PART > copy( new LIB_PART( m_part_no_data ) ); + std::shared_ptr<LIB_PART> copy = std::make_shared<LIB_PART>( m_part_no_data ); BOOST_CHECK( m_part_no_data == *copy.get() ); }