KiCad PCB EDA Suite
FOOTPRINT_FILTER::ITERATOR Class Reference

Inner iterator class returned by begin() and end(). More...

#include <footprint_filter.h>

Inheritance diagram for FOOTPRINT_FILTER::ITERATOR:

Public Member Functions

 ITERATOR ()
 
 ITERATOR (const ITERATOR &aOther)
 
 ITERATOR (FOOTPRINT_FILTER &aFilter)
 

Private Member Functions

void increment ()
 
bool equal (const ITERATOR &aOther) const
 
FOOTPRINT_INFOdereference () const
 
bool FootprintFilterMatch (FOOTPRINT_INFO &aItem)
 Check if the stored component matches an item by footprint filter. More...
 
bool PinCountMatch (FOOTPRINT_INFO &aItem)
 Check if the stored component matches an item by pin count. More...
 

Private Attributes

size_t m_pos
 
FOOTPRINT_FILTERm_filter
 

Friends

class boost::iterator_core_access
 
class FOOTPRINT_FILTER
 

Detailed Description

Inner iterator class returned by begin() and end().

Definition at line 82 of file footprint_filter.h.

Constructor & Destructor Documentation

◆ ITERATOR() [1/3]

FOOTPRINT_FILTER::ITERATOR::ITERATOR ( )

Definition at line 28 of file footprint_filter.cpp.

28 : m_pos( 0 ), m_filter( nullptr )
29{
30}
FOOTPRINT_FILTER * m_filter

◆ ITERATOR() [2/3]

FOOTPRINT_FILTER::ITERATOR::ITERATOR ( const ITERATOR aOther)

Definition at line 33 of file footprint_filter.cpp.

34 : m_pos( aOther.m_pos ), m_filter( aOther.m_filter )
35{
36}

◆ ITERATOR() [3/3]

FOOTPRINT_FILTER::ITERATOR::ITERATOR ( FOOTPRINT_FILTER aFilter)

Definition at line 39 of file footprint_filter.cpp.

40 : m_pos( (size_t) -1 ), m_filter( &aFilter )
41{
42 increment();
43}

References increment().

Member Function Documentation

◆ dereference()

FOOTPRINT_INFO & FOOTPRINT_FILTER_IT::dereference ( ) const
private

Definition at line 118 of file footprint_filter.cpp.

119{
120 if( m_filter && m_filter->m_list && m_pos < m_filter->m_list->GetCount() )
121 return m_filter->m_list->GetItem( m_pos );
122 else
123 throw std::out_of_range( "Attempt to dereference past FOOTPRINT_FILTER::end()" );
124}
FOOTPRINT_LIST * m_list
unsigned GetCount() const
FOOTPRINT_INFO & GetItem(unsigned aIdx) const
Get info for a footprint by index.

References FOOTPRINT_LIST::GetCount(), and FOOTPRINT_FILTER::m_list.

◆ equal()

bool FOOTPRINT_FILTER_IT::equal ( const ITERATOR aOther) const
private

Definition at line 111 of file footprint_filter.cpp.

112{
113 // Invalid iterators are always equal
114 return ( m_pos == aOther.m_pos ) && ( m_filter == aOther.m_filter || m_pos == (size_t) -1 );
115}

References m_filter, and m_pos.

◆ FootprintFilterMatch()

bool FOOTPRINT_FILTER_IT::FootprintFilterMatch ( FOOTPRINT_INFO aItem)
private

Check if the stored component matches an item by footprint filter.

Definition at line 127 of file footprint_filter.cpp.

128{
129 if( m_filter->m_footprint_filters.empty() )
130 return true;
131
132 // The matching is case insensitive
133 wxString name;
134
135 for( const std::unique_ptr<EDA_PATTERN_MATCH>& each_filter : m_filter->m_footprint_filters )
136 {
137 name.Empty();
138
139 // If the filter contains a ':' character, include the library name in the pattern
140 if( each_filter->GetPattern().Contains( wxS( ":" ) ) )
141 {
142 name = aItem.GetLibNickname().Lower() + wxS( ":" );
143 }
144
145 name += aItem.GetFootprintName().Lower();
146
147 if( each_filter->Find( name ) )
148 {
149 return true;
150 }
151 }
152
153 return false;
154}
const char * name
Definition: DXF_plotter.cpp:56
std::vector< std::unique_ptr< EDA_PATTERN_MATCH > > m_footprint_filters
wxString GetLibNickname() const override
const wxString & GetFootprintName() const

References FOOTPRINT_INFO::GetFootprintName(), FOOTPRINT_INFO::GetLibNickname(), and name.

◆ increment()

void FOOTPRINT_FILTER_IT::increment ( )
private

Definition at line 46 of file footprint_filter.cpp.

47{
48 if( !m_filter || !m_filter->m_list || m_filter->m_list->GetCount() == 0 )
49 {
50 m_pos = 0;
51 return;
52 }
53
54 int filter_type = m_filter->m_filter_type;
56 wxString& lib_name = m_filter->m_lib_name;
57
58 for( ++m_pos; m_pos < list->GetCount(); ++m_pos )
59 {
60 FOOTPRINT_INFO& candidate = list->GetItem( m_pos );
61
62 if( filter_type == FOOTPRINT_FILTER::UNFILTERED_FP_LIST )
63 break;
64
66 {
67 if( !PinCountMatch( candidate ) )
68 continue;
69 }
70
72 {
73 if( !lib_name.IsEmpty() && !candidate.InLibrary( lib_name ) )
74 continue;
75 }
76
78 {
79 if( !FootprintFilterMatch( candidate ) )
80 continue;
81 }
82
84 {
85 wxString searchStr = wxString::Format( wxT( "%s:%s %s" ),
86 candidate.GetLibNickname(),
87 candidate.GetFootprintName(),
88 candidate.GetSearchText() );
89 int matches, position;
90 bool exclude = false;
91
92 for( std::unique_ptr<EDA_COMBINED_MATCHER>& matcher : m_filter->m_pattern_filters )
93 {
94 if( !matcher->Find( searchStr.Lower(), matches, position ) )
95 {
96 exclude = true;
97 break;
98 }
99 }
100
101 if( exclude )
102 continue;
103 }
104
105 // Candidate passed all filters; exit loop
106 break;
107 }
108}
bool PinCountMatch(FOOTPRINT_INFO &aItem)
Check if the stored component matches an item by pin count.
bool FootprintFilterMatch(FOOTPRINT_INFO &aItem)
Check if the stored component matches an item by footprint filter.
std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > m_pattern_filters
wxString GetSearchText() override
bool InLibrary(const wxString &aLibrary) const
Test if the FOOTPRINT_INFO object was loaded from aLibrary.
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References FOOTPRINT_FILTER::FILTERING_BY_COMPONENT_FP_FILTER, FOOTPRINT_FILTER::FILTERING_BY_LIBRARY, FOOTPRINT_FILTER::FILTERING_BY_PIN_COUNT, FOOTPRINT_FILTER::FILTERING_BY_TEXT_PATTERN, Format(), FOOTPRINT_LIST::GetCount(), FOOTPRINT_INFO::GetFootprintName(), FOOTPRINT_LIST::GetItem(), FOOTPRINT_INFO::GetLibNickname(), FOOTPRINT_INFO::GetSearchText(), FOOTPRINT_INFO::InLibrary(), FOOTPRINT_LIST::m_list, and FOOTPRINT_FILTER::UNFILTERED_FP_LIST.

Referenced by ITERATOR().

◆ PinCountMatch()

bool FOOTPRINT_FILTER_IT::PinCountMatch ( FOOTPRINT_INFO aItem)
private

Check if the stored component matches an item by pin count.

Definition at line 157 of file footprint_filter.cpp.

158{
159 return m_filter->m_pin_count >= 0 &&
160 (unsigned) m_filter->m_pin_count == aItem.GetUniquePadCount();
161}
unsigned GetUniquePadCount()

References FOOTPRINT_INFO::GetUniquePadCount().

Friends And Related Function Documentation

◆ boost::iterator_core_access

friend class boost::iterator_core_access
friend

Definition at line 91 of file footprint_filter.h.

◆ FOOTPRINT_FILTER

friend class FOOTPRINT_FILTER
friend

Definition at line 92 of file footprint_filter.h.

Member Data Documentation

◆ m_filter

FOOTPRINT_FILTER* FOOTPRINT_FILTER::ITERATOR::m_filter
private

Definition at line 99 of file footprint_filter.h.

Referenced by equal().

◆ m_pos

size_t FOOTPRINT_FILTER::ITERATOR::m_pos
private

Definition at line 98 of file footprint_filter.h.

Referenced by FOOTPRINT_FILTER::end(), and equal().


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