KiCad PCB EDA Suite
Loading...
Searching...
No Matches
jumper_group.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "jumper_group.h"
21
22#include <utility>
23
24
25JUMPER_GROUP::JUMPER_GROUP( std::set<wxString> aNames ) :
26 m_names( std::move( aNames ) )
27{
28}
29
30
31std::optional<JUMPER_GROUP> JUMPER_GROUP::Make( std::set<wxString> aNames )
32{
33 // A blank name can never resolve to a pin or pad.
34 std::erase_if( aNames,
35 []( const wxString& aName )
36 {
37 return aName.IsEmpty();
38 } );
39
40 if( aNames.empty() )
41 return std::nullopt;
42
43 return JUMPER_GROUP( std::move( aNames ) );
44}
45
46
47bool JUMPER_GROUP::Contains( const wxString& aName ) const
48{
49 return m_names.find( aName ) != m_names.end();
50}
51
52
54{
55 m_groups.push_back( std::move( aGroup ) );
56}
57
58
59void JUMPER_GROUP_SET::Add( std::set<wxString> aNames )
60{
61 std::optional<JUMPER_GROUP> group = JUMPER_GROUP::Make( std::move( aNames ) );
62
63 if( group )
64 Add( std::move( *group ) );
65}
66
67
68const JUMPER_GROUP* JUMPER_GROUP_SET::FindContaining( const wxString& aName ) const
69{
70 for( const JUMPER_GROUP& group : m_groups )
71 {
72 if( group.Contains( aName ) )
73 return &group;
74 }
75
76 return nullptr;
77}
void Add(JUMPER_GROUP aGroup)
Add a JUMPER_GROUP to the set.
std::vector< JUMPER_GROUP > m_groups
const JUMPER_GROUP * FindContaining(const wxString &aName) const
Represents a group of jumper pins or pads, keyed by name.
static std::optional< JUMPER_GROUP > Make(std::set< wxString > aNames)
Factory method to create a JUMPER_GROUP from a set of names.
std::set< wxString > m_names
JUMPER_GROUP(std::set< wxString > aNames)
bool Contains(const wxString &aName) const
STL namespace.