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 ) :
46 Text( aText ),
47 Score( aScore ),
48 Normalized( false )
49 {}
50
51 wxString Text;
52 int Score;
54};
55
56
61{
62public:
64 {
66 int length = 0;
67
68 bool valid() const
69 {
71 }
72
73 explicit operator bool() const
74 {
75 return valid();
76 }
77 };
78
79 virtual ~EDA_PATTERN_MATCH() {}
80
86 virtual bool SetPattern( const wxString& aPattern ) = 0;
87
91 virtual wxString const& GetPattern() const = 0;
92
99 virtual FIND_RESULT Find( const wxString& aCandidate ) const = 0;
100};
101
102
107{
108public:
109
110 virtual bool SetPattern( const wxString& aPattern ) override;
111 virtual wxString const& GetPattern() const override;
112 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
113
114protected:
115 wxString m_pattern;
116};
117
118
123{
124public:
125
126 virtual bool SetPattern( const wxString& aPattern ) override;
127 virtual wxString const& GetPattern() const override;
128 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
129
130protected:
131 wxString m_pattern;
132 wxRegEx m_regex;
133};
134
135
137{
138public:
139 virtual bool SetPattern( const wxString& aPattern ) override;
140};
141
142
144{
145public:
146
147 virtual bool SetPattern( const wxString& aPattern ) override;
148 virtual wxString const& GetPattern() const override;
149 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
150
151protected:
153};
154
155
157{
158public:
159 virtual bool SetPattern( const wxString& aPattern ) override;
160};
161
162
177{
178public:
179 virtual bool SetPattern( const wxString& aPattern ) override;
180 virtual wxString const& GetPattern() const override;
181 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
182 int FindOne( const wxString& aCandidate ) const;
183
184protected:
185
186 enum RELATION { LT, LE, EQ, GE, GT, ANY };
187
188 wxString m_pattern;
189 wxString m_key;
191 double m_value;
192
193 static const std::map<wxString, double> m_units;
194};
195
196
205
206
208{
209public:
210 EDA_COMBINED_MATCHER( const wxString& aPattern, COMBINED_MATCHER_CONTEXT aContext );
211
217
223
233 bool Find( const wxString& aTerm, int& aMatchersTriggered, int& aPosition );
234
235 bool Find( const wxString& aTerm );
236
237 bool StartsWith( const wxString& aTerm );
238
239 const wxString& GetPattern() const;
240
241 int ScoreTerms( std::vector<SEARCH_TERM>& aWeightedTerms, bool* aExactMatch = nullptr );
242
243private:
245 void AddMatcher( const wxString& aPattern, std::unique_ptr<EDA_PATTERN_MATCH> aMatcher );
246
247 std::vector<std::unique_ptr<EDA_PATTERN_MATCH>> m_matchers;
248 wxString m_pattern;
249};
250
251#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
SEARCH_TERM(const wxString &aText, int aScore)