KiCad PCB EDA Suite
PIN_NUMBERS Class Reference

#include <pin_numbers.h>

Classes

struct  less
 

Public Types

typedef container_type::value_type value_type
 
typedef container_type::iterator iterator
 
typedef container_type::const_iterator const_iterator
 

Public Member Functions

wxString GetSummary () const
 
wxString GetDuplicates () const
 Gets a formatted string of all the pins that have duplicate numbers. More...
 
void insert (value_type const &v)
 
container_type::size_type size () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 

Static Public Member Functions

static int Compare (const wxString &lhs, const wxString &rhs)
 

Private Types

typedef std::set< wxString, lesscontainer_type
 

Static Private Member Functions

static wxString getNextSymbol (const wxString &str, wxString::size_type &cursor)
 

Private Attributes

container_type pins
 
std::set< wxString > duplicate_pins
 

Detailed Description

Definition at line 32 of file pin_numbers.h.

Member Typedef Documentation

◆ const_iterator

typedef container_type::const_iterator PIN_NUMBERS::const_iterator

Definition at line 61 of file pin_numbers.h.

◆ container_type

typedef std::set<wxString, less> PIN_NUMBERS::container_type
private

Definition at line 54 of file pin_numbers.h.

◆ iterator

typedef container_type::iterator PIN_NUMBERS::iterator

Definition at line 60 of file pin_numbers.h.

◆ value_type

typedef container_type::value_type PIN_NUMBERS::value_type

Definition at line 59 of file pin_numbers.h.

Member Function Documentation

◆ begin() [1/2]

iterator PIN_NUMBERS::begin ( )
inline

Definition at line 77 of file pin_numbers.h.

77{ return pins.begin(); }
container_type pins
Definition: pin_numbers.h:83

References pins.

Referenced by getNextSymbol(), and GetSummary().

◆ begin() [2/2]

const_iterator PIN_NUMBERS::begin ( ) const
inline

Definition at line 79 of file pin_numbers.h.

79{ return pins.begin(); }

References pins.

◆ Compare()

int PIN_NUMBERS::Compare ( const wxString &  lhs,
const wxString &  rhs 
)
static

Definition at line 130 of file pin_numbers.cpp.

131{
132 wxString::size_type cursor1 = 0;
133 wxString::size_type cursor2 = 0;
134
135 wxString symbol1, symbol2;
136
137 for( ; ; )
138 {
139 symbol1 = getNextSymbol( lhs, cursor1 );
140 symbol2 = getNextSymbol( rhs, cursor2 );
141
142 if( symbol1.empty() && symbol2.empty() )
143 return 0;
144
145 if( symbol1.empty() )
146 return -2;
147
148 if( symbol2.empty() )
149 return 2;
150
151 bool sym1_isnumeric = symbol1.find_first_of( "0123456789" ) != wxString::npos;
152 bool sym2_isnumeric = symbol2.find_first_of( "0123456789" ) != wxString::npos;
153
154 if( sym1_isnumeric )
155 {
156 if( sym2_isnumeric )
157 {
158 // numeric comparison
159 wxString::size_type v1 = symbol1.find_first_of( "vV" );
160
161 if( v1 != wxString::npos )
162 symbol1[v1] = '.';
163
164 wxString::size_type v2 = symbol2.find_first_of( "vV" );
165
166 if( v2 != wxString::npos )
167 symbol2[v2] = '.';
168
169 double val1, val2;
170
171 symbol1.ToCDouble( &val1 );
172 symbol2.ToCDouble( &val2 );
173
174 if( val1 < val2 )
175 {
176 if( val1 == val2 - 1 )
177 return -1;
178 else
179 return -2;
180 }
181
182 if( val1 > val2 )
183 {
184 if( val1 == val2 + 1 )
185 return 1;
186 else
187 return 2;
188 }
189 }
190 else
191 return -2;
192 }
193 else
194 {
195 if( sym2_isnumeric )
196 return 2;
197
198 int res = symbol1.Cmp( symbol2 );
199
200 if( res != 0 )
201 return res;
202 }
203 }
204}
static wxString getNextSymbol(const wxString &str, wxString::size_type &cursor)
Definition: pin_numbers.cpp:30
VECTOR2I v2(1, 0)
Test suite for KiCad math code.

References getNextSymbol(), and v2.

Referenced by BOOST_AUTO_TEST_CASE(), PIN_TABLE_DATA_MODEL::compare(), SCH_PIN_TABLE_DATA_MODEL::compare(), GetSummary(), and PIN_NUMBERS::less::operator()().

◆ end() [1/2]

iterator PIN_NUMBERS::end ( )
inline

Definition at line 78 of file pin_numbers.h.

78{ return pins.end(); }

References pins.

Referenced by GetSummary().

◆ end() [2/2]

const_iterator PIN_NUMBERS::end ( ) const
inline

Definition at line 80 of file pin_numbers.h.

80{ return pins.end(); }

References pins.

◆ GetDuplicates()

wxString PIN_NUMBERS::GetDuplicates ( ) const

Gets a formatted string of all the pins that have duplicate numbers.

Returns

Definition at line 110 of file pin_numbers.cpp.

111{
112 wxString ret;
113
114 for( const wxString& pinNumber : duplicate_pins )
115 {
116 ret += pinNumber;
117 ret += ',';
118 }
119
120 // Remove the trailing comma
121 ret.RemoveLast();
122
123 if( ret.IsEmpty() )
124 ret = _( "none" );
125
126 return ret;
127}
std::set< wxString > duplicate_pins
Definition: pin_numbers.h:84
#define _(s)

References _, and duplicate_pins.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::updateSummary().

◆ getNextSymbol()

wxString PIN_NUMBERS::getNextSymbol ( const wxString &  str,
wxString::size_type &  cursor 
)
staticprivate

Definition at line 30 of file pin_numbers.cpp.

31{
32 if( str.size() <= cursor )
33 return wxEmptyString;
34
35 wxString::size_type begin = cursor;
36
37 wxChar c = str[cursor];
38
39 // Need to check that there is a digit in the string before we parse it as a numeric
40 if( ( wxIsdigit( c ) || ( ( c == '+' || c == '-' ) && ( cursor < str.size() - 1 ) && wxIsdigit( str[cursor + 1] ) ) ) )
41 {
42 // number, possibly with sign
43 while( ++cursor < str.size() )
44 {
45 c = str[cursor];
46
47 if( wxIsdigit( c ) || c == 'v' || c == 'V' || c == '.' )
48 continue;
49 else
50 break;
51 }
52 }
53 else
54 {
55 while( ++cursor < str.size() )
56 {
57 c = str[cursor];
58
59 if( wxIsdigit( c ) )
60 break;
61 else
62 continue;
63 }
64 }
65
66 return str.substr( begin, cursor - begin );
67}
iterator begin()
Definition: pin_numbers.h:77

References begin(), and cursor.

Referenced by Compare().

◆ GetSummary()

wxString PIN_NUMBERS::GetSummary ( ) const

Definition at line 70 of file pin_numbers.cpp.

71{
72 wxString ret;
73
75 if( i == end() )
76 return ret;
77
78 const_iterator begin_of_range = i;
79 const_iterator last;
80
81 for( ;; )
82 {
83 last = i;
84 ++i;
85
86 int rc = ( i != end() ) ? Compare( *last, *i ) : -2;
87
88 assert( rc == -1 || rc == -2 );
89
90 if( rc == -1 )
91 // adjacent elements
92 continue;
93
94 ret += *begin_of_range;
95 if( begin_of_range != last )
96 {
97 ret += '-';
98 ret += *last;
99 }
100 if( i == end() )
101 break;
102 begin_of_range = i;
103 ret += ',';
104 }
105
106 return ret;
107}
static int Compare(const wxString &lhs, const wxString &rhs)
iterator end()
Definition: pin_numbers.h:78
container_type::const_iterator const_iterator
Definition: pin_numbers.h:61

References begin(), Compare(), and end().

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::updateSummary().

◆ insert()

void PIN_NUMBERS::insert ( value_type const &  v)
inline

Definition at line 63 of file pin_numbers.h.

64 {
65 // Check if the insertion occurred. If no insertion was performed then
66 // the pin number is a duplicate so add it to the duplicate set.
67 bool not_duplicate = pins.insert( v ).second;
68
69 if( not_duplicate == false )
70 {
71 duplicate_pins.insert( v );
72 }
73 }

References duplicate_pins, and pins.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::updateSummary().

◆ size()

container_type::size_type PIN_NUMBERS::size ( ) const
inline

Definition at line 75 of file pin_numbers.h.

75{ return pins.size(); }

References pins.

Member Data Documentation

◆ duplicate_pins

std::set<wxString> PIN_NUMBERS::duplicate_pins
private

Definition at line 84 of file pin_numbers.h.

Referenced by GetDuplicates(), and insert().

◆ pins

container_type PIN_NUMBERS::pins
private

Definition at line 83 of file pin_numbers.h.

Referenced by begin(), end(), insert(), and size().


The documentation for this class was generated from the following files: