KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_pattern_match.h
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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
24
25#ifndef EDA_PATTERN_MATCH_H
26#define EDA_PATTERN_MATCH_H
27
28#include <kicommon.h>
29#include <vector>
30#include <map>
31#include <memory>
32#include <wx/string.h>
33#include <wx/regex.h>
34
35static const int EDA_PATTERN_NOT_FOUND = wxNOT_FOUND;
36
44{
45 SEARCH_TERM( const wxString& aText, int aScore, bool aIsName = false ) :
46 Text( aText ),
47 Score( aScore ),
48 Normalized( false ),
49 IsName( aIsName )
50 {}
51
52 wxString Text;
53 int Score;
55
59 bool IsName;
60};
61
62
67{
68public:
70 {
72 int length = 0;
73
74 bool valid() const
75 {
77 }
78
79 explicit operator bool() const
80 {
81 return valid();
82 }
83 };
84
85 virtual ~EDA_PATTERN_MATCH() {}
86
92 virtual bool SetPattern( const wxString& aPattern ) = 0;
93
97 virtual wxString const& GetPattern() const = 0;
98
105 virtual FIND_RESULT Find( const wxString& aCandidate ) const = 0;
106};
107
108
113{
114public:
115
116 virtual bool SetPattern( const wxString& aPattern ) override;
117 virtual wxString const& GetPattern() const override;
118 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
119
120protected:
121 wxString m_pattern;
122};
123
124
129{
130public:
131
132 virtual bool SetPattern( const wxString& aPattern ) override;
133 virtual wxString const& GetPattern() const override;
134 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
135
136protected:
137 wxString m_pattern;
138 wxRegEx m_regex;
139};
140
141
143{
144public:
145 virtual bool SetPattern( const wxString& aPattern ) override;
146};
147
148
150{
151public:
152
153 virtual bool SetPattern( const wxString& aPattern ) override;
154 virtual wxString const& GetPattern() const override;
155 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
156
157protected:
159};
160
161
163{
164public:
165 virtual bool SetPattern( const wxString& aPattern ) override;
166};
167
168
183{
184public:
185 virtual bool SetPattern( const wxString& aPattern ) override;
186 virtual wxString const& GetPattern() const override;
187 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
188 int FindOne( const wxString& aCandidate ) const;
189
190protected:
191
192 enum RELATION { LT, LE, EQ, GE, GT, ANY };
193
194 wxString m_pattern;
195 wxString m_key;
197 double m_value;
198
199 static const std::map<wxString, double> m_units;
200};
201
202
211
212
214{
215public:
216 EDA_COMBINED_MATCHER( const wxString& aPattern, COMBINED_MATCHER_CONTEXT aContext );
217
223
229
239 bool Find( const wxString& aTerm, int& aMatchersTriggered, int& aPosition );
240
241 bool Find( const wxString& aTerm );
242
243 bool StartsWith( const wxString& aTerm );
244
245 const wxString& GetPattern() const;
246
247 int ScoreTerms( std::vector<SEARCH_TERM>& aWeightedTerms, bool* aExactMatch = nullptr );
248
249private:
251 void AddMatcher( const wxString& aPattern, std::unique_ptr<EDA_PATTERN_MATCH> aMatcher );
252
253 std::vector<std::unique_ptr<EDA_PATTERN_MATCH>> m_matchers;
254 wxString m_pattern;
255};
256
257#endif // EDA_PATTERN_MATCH_H
int ScoreTerms(std::vector< SEARCH_TERM > &aWeightedTerms, bool *aExactMatch=nullptr)
std::vector< std::unique_ptr< EDA_PATTERN_MATCH > > m_matchers
void AddMatcher(const wxString &aPattern, std::unique_ptr< EDA_PATTERN_MATCH > aMatcher)
Add matcher if it can compile the pattern.
EDA_COMBINED_MATCHER(const wxString &aPattern, COMBINED_MATCHER_CONTEXT aContext)
EDA_COMBINED_MATCHER & operator=(EDA_COMBINED_MATCHER const &)=delete
Deleted copy or else we have to implement copy constructors for all EDA_PATTERN_MATCH classes due to ...
EDA_COMBINED_MATCHER(EDA_COMBINED_MATCHER const &)=delete
Deleted copy or else we have to implement copy constructors for all EDA_PATTERN_MATCH classes due to ...
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
Look in all existing matchers, return the earliest match of any of the existing.
const wxString & GetPattern() const
bool StartsWith(const wxString &aTerm)
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
Match regular expression.
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
virtual FIND_RESULT Find(const wxString &aCandidate) const override
Return the location and possibly length of a match if a given candidate string matches the set patter...
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
int FindOne(const wxString &aCandidate) const
virtual FIND_RESULT Find(const wxString &aCandidate) const override
Return the location and possibly length of a match if a given candidate string matches the set patter...
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
static const std::map< wxString, double > m_units
Match simple substring.
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
virtual FIND_RESULT Find(const wxString &aCandidate) const override
Return the location and possibly length of a match if a given candidate string matches the set patter...
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
virtual FIND_RESULT Find(const wxString &aCandidate) const override
Return the location and possibly length of a match if a given candidate string matches the set patter...
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
Interface for a pattern matcher for which there are several implementations.
virtual bool SetPattern(const wxString &aPattern)=0
Set the pattern against which candidates will be matched.
virtual wxString const & GetPattern() const =0
Return the pattern passed to SetPattern().
virtual FIND_RESULT Find(const wxString &aCandidate) const =0
Return the location and possibly length of a match if a given candidate string matches the set patter...
static const int EDA_PATTERN_NOT_FOUND
COMBINED_MATCHER_CONTEXT
@ CTX_NET
@ CTX_SIGNAL
@ CTX_NETCLASS
@ CTX_SEARCH
@ CTX_LIBITEM
#define KICOMMON_API
Definition kicommon.h:27
bool IsName
True if this term is the item's own name or LIB_ID rather than an incidental field (keyword,...
SEARCH_TERM(const wxString &aText, int aScore, bool aIsName=false)