kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #22211
[PATCH 2/5] Move comparison helper class to generic header
This class wraps the comparison function in a way that is compatible with
std::map and std::set. This, too is generally useful, so it should be moved
to the generic header.
At the same time, the criterium for less-than is changed from "equal to -1"
to "smaller than 0", because technically the comparison function may return
other values.
---
eeschema/dialogs/dialog_lib_edit_pin_table.cpp | 13 +------------
eeschema/pin_number.h | 8 ++++++++
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp
index b94cf26..2145403 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp
+++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp
@@ -284,17 +284,6 @@ unsigned int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetChildren( const wxData
}
-namespace {
-class CompareLess
-{
-public:
- bool operator()( const wxString& lhs, const wxString& rhs )
- {
- return PinNumbers::Compare( lhs, rhs ) == -1;
- }
-};
-}
-
int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Compare( const wxDataViewItem& aItem1,
const wxDataViewItem& aItem2,
unsigned int aCol,
@@ -398,7 +387,7 @@ void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::GetValue( wxVariant& aValu
}
else
{
- std::set<wxString, CompareLess> values;
+ std::set<wxString, PinNumbers::less> values;
for( std::list<Pin*>::const_iterator i = m_Members.begin(); i != m_Members.end(); ++i )
{
diff --git a/eeschema/pin_number.h b/eeschema/pin_number.h
index c337d72..d3fb6f2 100644
--- a/eeschema/pin_number.h
+++ b/eeschema/pin_number.h
@@ -33,6 +33,14 @@ class PinNumbers
{
public:
static int Compare( PinNumber const &lhs, PinNumber const &rhs );
+
+ struct less
+ {
+ bool operator()( PinNumber const &lhs, PinNumber const &rhs ) const
+ {
+ return Compare( lhs, rhs ) < 0;
+ }
+ };
};
#endif
Follow ups
References