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 (ITERATOR const &aOther)
 
 ITERATOR (FOOTPRINT_FILTER &aFilter)
 

Private Member Functions

void increment ()
 
bool equal (ITERATOR const &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

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
FOOTPRINT_FILTER::ITERATOR::ITERATOR ( ITERATOR const &  aOther)

Definition at line 33 of file footprint_filter.cpp.

34  : m_pos( aOther.m_pos ), m_filter( aOther.m_filter )
35 {
36 }
FOOTPRINT_FILTER * m_filter
FOOTPRINT_FILTER::ITERATOR::ITERATOR ( FOOTPRINT_FILTER aFilter)

Definition at line 39 of file footprint_filter.cpp.

References increment().

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

Member Function Documentation

FOOTPRINT_INFO & FOOTPRINT_FILTER_IT::dereference ( ) const
private

Definition at line 114 of file footprint_filter.cpp.

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

115 {
116  if( m_filter && m_filter->m_list && m_pos < m_filter->m_list->GetCount() )
117  return m_filter->m_list->GetItem( m_pos );
118  else
119  throw std::out_of_range( "Attempt to dereference past FOOTPRINT_FILTER::end()" );
120 }
unsigned GetCount() const
FOOTPRINT_INFO & GetItem(unsigned aIdx)
Get info for a module by index.
FOOTPRINT_LIST * m_list
FOOTPRINT_FILTER * m_filter
bool FOOTPRINT_FILTER_IT::equal ( ITERATOR const &  aOther) const
private

Definition at line 107 of file footprint_filter.cpp.

References m_filter, FOOTPRINT_FILTER::m_filter, and m_pos.

108 {
109  // Invalid iterators are always equal
110  return ( m_pos == aOther.m_pos ) && ( m_filter == aOther.m_filter || m_pos == (size_t) -1 );
111 }
EDA_PATTERN_MATCH_WILDCARD m_filter
FOOTPRINT_FILTER * m_filter
bool FOOTPRINT_FILTER_IT::FootprintFilterMatch ( FOOTPRINT_INFO aItem)
private

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

Definition at line 123 of file footprint_filter.cpp.

References EDA_PATTERN_NOT_FOUND, FOOTPRINT_INFO::GetFootprintName(), FOOTPRINT_INFO::GetNickname(), FOOTPRINT_FILTER::m_filter, and name.

124 {
125  if( m_filter->m_footprint_filters.empty() )
126  return true;
127 
128  // The matching is case insensitive
129  wxString name;
130 
131  EDA_PATTERN_MATCH_WILDCARD patternFilter;
132 
133  for( auto const& each_filter : m_filter->m_footprint_filters )
134  {
135  name.Empty();
136 
137  // If the filter contains a ':' character, include the library name in the pattern
138  if( each_filter->GetPattern().Contains( ":" ) )
139  {
140  name = aItem.GetNickname().Lower() + ":";
141  }
142 
143  name += aItem.GetFootprintName().Lower();
144 
145  if( each_filter->Find( name ) != EDA_PATTERN_NOT_FOUND )
146  {
147  return true;
148  }
149  }
150 
151  return false;
152 }
const wxString & GetFootprintName() const
std::vector< std::unique_ptr< EDA_PATTERN_MATCH > > m_footprint_filters
static const int EDA_PATTERN_NOT_FOUND
const char * name
FOOTPRINT_FILTER * m_filter
const wxString & GetNickname() const
void FOOTPRINT_FILTER_IT::increment ( )
private

Definition at line 46 of file footprint_filter.cpp.

References EDA_PATTERN_NOT_FOUND, FOOTPRINT_FILTER::FILTERING_BY_COMPONENT_KEYWORD, FOOTPRINT_FILTER::FILTERING_BY_LIBRARY, FOOTPRINT_FILTER::FILTERING_BY_NAME, FOOTPRINT_FILTER::FILTERING_BY_PIN_COUNT, FOOTPRINT_FILTER::m_filter, and FOOTPRINT_FILTER::UNFILTERED_FP_LIST.

Referenced by ITERATOR().

47 {
48  bool found = false;
49 
50  if( !m_filter || !m_filter->m_list || m_filter->m_list->GetCount() == 0 )
51  {
52  m_pos = 0;
53  return;
54  }
55 
56  auto filter_type = m_filter->m_filter_type;
57  auto list = m_filter->m_list;
58  auto& lib_name = m_filter->m_lib_name;
59  auto& filter_pattern = m_filter->m_filter_pattern;
60  auto& filter = m_filter->m_filter;
61 
62  for( ++m_pos; m_pos < list->GetCount() && !found; ++m_pos )
63  {
64  found = true;
65 
66  if( ( filter_type & FOOTPRINT_FILTER::FILTERING_BY_LIBRARY ) && !lib_name.IsEmpty()
67  && !list->GetItem( m_pos ).InLibrary( lib_name ) )
68  found = false;
69 
71  && !FootprintFilterMatch( list->GetItem( m_pos ) ) )
72  found = false;
73 
74  if( ( filter_type & FOOTPRINT_FILTER::FILTERING_BY_PIN_COUNT )
75  && !PinCountMatch( list->GetItem( m_pos ) ) )
76  found = false;
77 
78  if( ( filter_type & FOOTPRINT_FILTER::FILTERING_BY_NAME ) && !filter_pattern.IsEmpty() )
79  {
80  wxString currname;
81 
82  // If the search string contains a ':' character,
83  // include the library name in the search string
84  // e.g. LibName:FootprintName
85  if( filter_pattern.Contains( ":" ) )
86  currname = list->GetItem( m_pos ).GetNickname().Lower() + ":";
87 
88  currname += list->GetItem( m_pos ).GetFootprintName().Lower();
89 
90  if( filter.Find( currname ) == EDA_PATTERN_NOT_FOUND )
91  found = false;
92  }
93 
94  if( filter_type == FOOTPRINT_FILTER::UNFILTERED_FP_LIST )
95  {
96  // override
97  found = true;
98  }
99  }
100 
101  // for loop will stop one past the correct item
102  if( found )
103  --m_pos;
104 }
bool PinCountMatch(FOOTPRINT_INFO &aItem)
Check if the stored component matches an item by pin count.
unsigned GetCount() const
bool FootprintFilterMatch(FOOTPRINT_INFO &aItem)
Check if the stored component matches an item by footprint filter.
static const int EDA_PATTERN_NOT_FOUND
EDA_PATTERN_MATCH_WILDCARD m_filter
FOOTPRINT_LIST * m_list
FOOTPRINT_FILTER * m_filter
bool FOOTPRINT_FILTER_IT::PinCountMatch ( FOOTPRINT_INFO aItem)
private

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

Definition at line 155 of file footprint_filter.cpp.

References FOOTPRINT_INFO::GetUniquePadCount(), and FOOTPRINT_FILTER::m_filter.

156 {
157  return (unsigned) m_filter->m_pin_count == aItem.GetUniquePadCount();
158 }
unsigned GetUniquePadCount()
FOOTPRINT_FILTER * m_filter

Friends And Related Function Documentation

friend class boost::iterator_core_access
friend

Definition at line 91 of file footprint_filter.h.

friend class FOOTPRINT_FILTER
friend

Definition at line 92 of file footprint_filter.h.

Member Data Documentation

FOOTPRINT_FILTER* FOOTPRINT_FILTER::ITERATOR::m_filter
private

Definition at line 99 of file footprint_filter.h.

Referenced by equal().

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: