Proper numeric sorting for intersheet refs.

Also expunges the horrifically named std::remove and std::remove_if
(neither of which remove anything).
This commit is contained in:
Jeff Young 2021-10-01 11:52:34 +01:00
parent 5d579d14c1
commit f606679164
19 changed files with 96 additions and 136 deletions

View File

@ -25,8 +25,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <core/kicad_algo.h>
#include <commit.h>
#include <eda_item.h>
#include <macros.h>
@ -137,16 +136,6 @@ int COMMIT::GetStatus( EDA_ITEM* aItem )
}
template <class Container, class F>
void eraseIf( Container& c, F&& f )
{
c.erase( std::remove_if( c.begin(),
c.end(),
std::forward<F>( f ) ),
c.end() );
}
COMMIT& COMMIT::createModified( EDA_ITEM* aItem, EDA_ITEM* aCopy, int aExtraFlags )
{
EDA_ITEM* parent = parentObject( aItem );
@ -171,10 +160,10 @@ void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy )
if( m_changedItems.find( aItem ) != m_changedItems.end() )
{
eraseIf( m_changes, [aItem] ( const COMMIT_LINE& aEnt )
{
return aEnt.m_item == aItem;
} );
alg::delete_if( m_changes, [aItem]( const COMMIT_LINE& aEnt )
{
return aEnt.m_item == aItem;
} );
}
COMMIT_LINE ent;

View File

@ -292,10 +292,11 @@ std::vector<wxString> LIB_TABLE::GetLogicalLibs()
}
// We want to allow case-sensitive duplicates but sort by case-insensitive ordering
std::sort( ret.begin(), ret.end(), []( const wxString& lhs, const wxString& rhs )
{
return lhs.CmpNoCase( rhs ) < 0;
} );
std::sort( ret.begin(), ret.end(),
[]( const wxString& lhs, const wxString& rhs )
{
return lhs.CmpNoCase( rhs ) < 0;
} );
return ret;
}

View File

@ -24,7 +24,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <core/kicad_algo.h>
#include <core/optional.h>
#include <map>

View File

@ -18,8 +18,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <common.h>
#include <core/kicad_algo.h>
#include "bus_alias.h"

View File

@ -22,12 +22,12 @@
#include <list>
#include <thread>
#include <algorithm>
#include <future>
#include <vector>
#include <unordered_map>
#include <profile.h>
#include <common.h>
#include <core/kicad_algo.h>
#include <erc.h>
#include <pin_type.h>
#include <sch_bus_entry.h>
@ -1054,7 +1054,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
wxLogTrace( ConnTrace, "%ld (%s) is weakly driven and not unique. Changing to %s.",
subgraph->m_code, name, new_name );
vec->erase( std::remove( vec->begin(), vec->end(), subgraph ), vec->end() );
alg::delete_matching( *vec, subgraph );
m_net_name_to_subgraphs_map[new_name].emplace_back( subgraph );
@ -1307,12 +1307,10 @@ void CONNECTION_GRAPH::buildConnectionGraph()
}
// Absorbed subgraphs should no longer be considered
m_driver_subgraphs.erase( std::remove_if( m_driver_subgraphs.begin(), m_driver_subgraphs.end(),
[&] ( const CONNECTION_SUBGRAPH* candidate ) -> bool
{
return candidate->m_absorbed;
} ),
m_driver_subgraphs.end() );
alg::delete_if( m_driver_subgraphs, [&]( const CONNECTION_SUBGRAPH* candidate ) -> bool
{
return candidate->m_absorbed;
} );
// Store global subgraphs for later reference
std::vector<CONNECTION_SUBGRAPH*> global_subgraphs;
@ -2031,7 +2029,7 @@ void CONNECTION_GRAPH::recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph,
if( it != m_net_name_to_subgraphs_map.end() )
{
std::vector<CONNECTION_SUBGRAPH*>& vec = it->second;
vec.erase( std::remove( vec.begin(), vec.end(), aSubgraph ), vec.end() );
alg::delete_matching( vec, aSubgraph );
}
wxLogTrace( ConnTrace, "recacheSubgraphName: %s => %s", aOldName,

View File

@ -22,12 +22,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <symbol_library.h>
#include <dialog_choose_symbol.h>
#include <eeschema_settings.h>
#include <kiface_base.h>
#include <sch_base_frame.h>
#include <core/kicad_algo.h>
#include <template_fieldnames.h>
#include <widgets/footprint_preview_widget.h>
#include <widgets/footprint_select_widget.h>
@ -487,12 +487,10 @@ void DIALOG_CHOOSE_SYMBOL::OnFootprintSelected( wxCommandEvent& aEvent )
{
m_fp_override = aEvent.GetString();
m_field_edits.erase( std::remove_if( m_field_edits.begin(), m_field_edits.end(),
[]( std::pair<int, wxString> const& i )
{
return i.first == FOOTPRINT_FIELD;
} ),
m_field_edits.end() );
alg::delete_if( m_field_edits, []( std::pair<int, wxString> const& i )
{
return i.first == FOOTPRINT_FIELD;
} );
m_field_edits.emplace_back( std::make_pair( FOOTPRINT_FIELD, m_fp_override ) );

View File

@ -27,6 +27,7 @@
#include "dialog_spice_model.h"
#include <sim/spice_value.h>
#include <core/kicad_algo.h>
#include <confirm.h>
#include <project.h>
#include <common.h>
@ -311,21 +312,17 @@ bool DIALOG_SPICE_MODEL::TransferDataFromWindow()
if( m_useSchFields )
{
m_schfields->erase( std::remove_if( m_schfields->begin(), m_schfields->end(),
[&]( const SCH_FIELD& f )
{
return f.GetName() == spiceField;
} ),
m_schfields->end() );
alg::delete_if( *m_schfields, [&]( const SCH_FIELD& f )
{
return f.GetName() == spiceField;
} );
}
else
{
m_libfields->erase( std::remove_if( m_libfields->begin(), m_libfields->end(),
[&]( const LIB_FIELD& f )
{
return f.GetName() == spiceField;
} ),
m_libfields->end() );
alg::delete_if( *m_libfields, [&]( const LIB_FIELD& f )
{
return f.GetName() == spiceField;
} );
}
}
}

View File

@ -18,8 +18,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <core/kicad_algo.h>
#include <dialog_update_symbol_fields.h>
#include <lib_symbol.h>

View File

@ -23,7 +23,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <core/kicad_algo.h>
#include <symbol_library.h>
#include <confirm.h>
#include <eeschema_id.h>
@ -181,12 +181,10 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SCHLIB_FILTER* aFilte
if( sel.LibId.IsValid() )
{
aHistoryList.erase( std::remove_if( aHistoryList.begin(), aHistoryList.end(),
[ &sel ]( PICKED_SYMBOL const& i )
{
return i.LibId == sel.LibId;
} ),
aHistoryList.end() );
alg::delete_if( aHistoryList, [&sel]( PICKED_SYMBOL const& i )
{
return i.LibId == sel.LibId;
} );
aHistoryList.insert( aHistoryList.begin(), sel );
}

View File

@ -37,6 +37,7 @@
#include <sch_edit_frame.h>
#include <plotters/plotter.h>
#include <bitmaps.h>
#include <core/kicad_algo.h>
#include <core/mirror.h>
#include <kiway.h>
#include <general.h>
@ -52,7 +53,6 @@
#include <tool/tool_manager.h>
#include <tools/ee_actions.h>
SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_ITEM* aParent,
const wxString& aName ) :
SCH_ITEM( aParent, SCH_FIELD_T ),
@ -531,19 +531,21 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame )
std::vector<wxString> pageListCopy;
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
std::sort( pageListCopy.begin(), pageListCopy.end() );
if( !Schematic()->Settings().m_IntersheetRefsListOwnPage )
{
wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
pageListCopy.erase( std::remove( pageListCopy.begin(),
pageListCopy.end(),
currentPage ), pageListCopy.end() );
alg::delete_matching( pageListCopy, currentPage );
if( pageListCopy.empty() )
return;
}
std::sort( pageListCopy.begin(), pageListCopy.end(),
[]( const wxString& a, const wxString& b ) -> bool
{
return StrNumCmp( a, b, true ) < 0;
} );
for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() )
{
if( sheet.size() == 1 )

View File

@ -46,6 +46,7 @@
#include <project/project_file.h>
#include <project/net_settings.h>
#include <core/mirror.h>
#include <core/kicad_algo.h>
#include <trigo.h>
using KIGFX::SCH_RENDER_SETTINGS;
@ -1249,14 +1250,16 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
std::vector<wxString> pageListCopy;
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
std::sort( pageListCopy.begin(), pageListCopy.end() );
std::sort( pageListCopy.begin(), pageListCopy.end(),
[]( const wxString& a, const wxString& b ) -> bool
{
return StrNumCmp( a, b, true ) <= 0;
} );
if( !settings.m_IntersheetRefsListOwnPage )
{
wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
pageListCopy.erase( std::remove( pageListCopy.begin(),
pageListCopy.end(),
currentPage ), pageListCopy.end() );
alg::delete_matching( pageListCopy, currentPage );
}
if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) )

View File

@ -66,7 +66,6 @@
#include <symbol_editor_settings.h>
#include <dialogs/dialog_text_and_label_properties.h>
#include <core/kicad_algo.h>
//#include <wx/filedlg.h>
#include <wx/textdlg.h>

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -22,16 +22,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file collector.h
* @brief COLLECTOR class definition.
*/
#ifndef COLLECTOR_H
#define COLLECTOR_H
#include <vector>
#include <core/kicad_algo.h>
#include <eda_item.h> // SEARCH_RESULT
#include <eda_rect.h>
@ -124,12 +119,10 @@ public:
*/
void Remove( const EDA_ITEM* aItem )
{
m_list.erase( std::remove_if( m_list.begin(), m_list.end(),
[&aItem]( const EDA_ITEM* aCandidate )
{
return aCandidate == aItem;
} ),
m_list.end() );
alg::delete_if( m_list, [&aItem]( const EDA_ITEM* aCandidate )
{
return aCandidate == aItem;
} );
}
/**

View File

@ -153,6 +153,28 @@ bool within_wrapped_range( T __val, T __minval, T __maxval, T __wrap )
return __val >= __minval || __val <= __maxval;
}
/**
* Covers for the horrifically named std::remove and std::remove_if (neither of which remove
* anything).
*/
/**
* @brief Deletes all values from \a __c which match \a __value.
*/
template <class _Container, typename _Value>
void delete_matching( _Container& __c, _Value __value )
{
__c.erase( std::remove( __c.begin(), __c.end(), __value ), __c.end() );
}
/**
* @brief Deletes all values from \a __c for which \a __f returns true.
*/
template <class _Container, class _Function>
void delete_if( _Container& __c, _Function&& __f )
{
__c.erase( std::remove_if( __c.begin(), __c.end(), std::forward<_Function>( __f ) ), __c.end() );
}
} // namespace alg

View File

@ -25,7 +25,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <limits.h> // for INT_MAX
#include <math.h> // for hypot
#include <map>

View File

@ -25,7 +25,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <iterator>
#include <drc/drc_rtree.h>
#include <pcb_base_frame.h>
@ -744,45 +743,25 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode )
}
case PCB_MARKER_T:
m_markers.erase( std::remove_if( m_markers.begin(), m_markers.end(),
[aBoardItem]( BOARD_ITEM* aItem )
{
return aItem == aBoardItem;
} ) );
alg::delete_matching( m_markers, aBoardItem );
break;
case PCB_GROUP_T:
m_groups.erase( std::remove_if( m_groups.begin(), m_groups.end(),
[aBoardItem]( BOARD_ITEM* aItem )
{
return aItem == aBoardItem;
} ) );
alg::delete_matching( m_groups, aBoardItem );
break;
case PCB_ZONE_T:
m_zones.erase( std::remove_if( m_zones.begin(), m_zones.end(),
[aBoardItem]( BOARD_ITEM* aItem )
{
return aItem == aBoardItem;
} ) );
alg::delete_matching( m_zones, aBoardItem );
break;
case PCB_FOOTPRINT_T:
m_footprints.erase( std::remove_if( m_footprints.begin(), m_footprints.end(),
[aBoardItem]( BOARD_ITEM* aItem )
{
return aItem == aBoardItem;
} ) );
alg::delete_matching( m_footprints, aBoardItem );
break;
case PCB_TRACE_T:
case PCB_ARC_T:
case PCB_VIA_T:
m_tracks.erase( std::remove_if( m_tracks.begin(), m_tracks.end(),
[aBoardItem]( BOARD_ITEM* aItem )
{
return aItem == aBoardItem;
} ) );
alg::delete_matching( m_tracks, aBoardItem );
break;
case PCB_DIM_ALIGNED_T:
@ -792,11 +771,7 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode )
case PCB_SHAPE_T:
case PCB_TEXT_T:
case PCB_TARGET_T:
m_drawings.erase( std::remove_if( m_drawings.begin(), m_drawings.end(),
[aBoardItem](BOARD_ITEM* aItem)
{
return aItem == aBoardItem;
} ) );
alg::delete_matching( m_drawings, aBoardItem );
break;
// other types may use linked list

View File

@ -1563,9 +1563,7 @@ void DIALOG_NET_INSPECTOR::buildNetsList()
m_netsList->UnselectAll();
}
prev_selected_netcodes.erase( std::remove( prev_selected_netcodes.begin(),
prev_selected_netcodes.end(), -1 ),
prev_selected_netcodes.end() );
alg::delete_matching( prev_selected_netcodes, -1 );
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->SetHighlight( false );

View File

@ -206,16 +206,13 @@ FABMASTER::section_type FABMASTER::detectType( size_t aOffset )
std::string row3{};
/// We strip the underscores from all column names as some export variants use them and some do not
row1.erase( std::remove_if( row1.begin(), row1.end(), []( char c ){ return c == '_'; } ),
row1.end() );
row2.erase( std::remove_if( row2.begin(), row2.end(), []( char c ){ return c == '_'; } ),
row2.end() );
alg::delete_if( row1, []( char c ){ return c == '_'; } );
alg::delete_if( row2, []( char c ){ return c == '_'; } );
if( row.size() > 3 )
{
row3 = row[3];
row3.erase( std::remove_if( row3.begin(), row3.end(), []( char c ){ return c == '_'; } ),
row3.end() );
alg::delete_if( row3, []( char c ){ return c == '_'; } );
}
if( row1 == "REFDES" && row2 == "COMPCLASS" )
@ -303,14 +300,13 @@ int FABMASTER::getColFromName( size_t aRow, const std::string& aStr )
if( aRow >= rows.size() )
return -1;
auto header = rows[aRow];
std::vector<std::string> header = rows[aRow];
for( size_t i = 0; i < header.size(); i++ )
{
/// Some Fabmaster headers include the underscores while others do not
/// so we strip them uniformly before comparing
header[i].erase( std::remove_if( header[i].begin(), header[i].end(),
[]( const char c ){ return c == '_'; } ), header[i].end() );
alg::delete_if( header[i], []( const char c ) { return c == '_'; } );
if( header[i] == aStr )
return i;

View File

@ -24,9 +24,8 @@
*/
#include <thread>
#include <algorithm>
#include <future>
#include <core/kicad_algo.h>
#include <advanced_config.h>
#include <board.h>
#include <board_design_settings.h>
@ -284,12 +283,10 @@ bool ZONE_FILLER::Fill( std::vector<ZONE*>& aZones, bool aCheck, wxWindow* aPare
}
}
toFill.erase( std::remove_if( toFill.begin(), toFill.end(),
[&] ( const std::pair<ZONE*, PCB_LAYER_ID> pair ) -> bool
{
return pair.first->GetFillFlag( pair.second );
} ),
toFill.end() );
alg::delete_if( toFill, [&]( const std::pair<ZONE*, PCB_LAYER_ID> pair ) -> bool
{
return pair.first->GetFillFlag( pair.second );
} );
if( m_progressReporter && m_progressReporter->IsCancelled() )
break;