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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
29#ifndef EDA_PATTERN_MATCH_H
30#define EDA_PATTERN_MATCH_H
31
32#include <kicommon.h>
33#include <vector>
34#include <map>
35#include <memory>
36#include <wx/string.h>
37#include <wx/regex.h>
38
39static const int EDA_PATTERN_NOT_FOUND = wxNOT_FOUND;
40
48{
49 SEARCH_TERM( const wxString& aText, int aScore ) :
50 Text( aText ),
51 Score( aScore ),
52 Normalized( false )
53 {}
54
55 wxString Text;
56 int Score;
58};
59
60
65{
66public:
68 {
70 int length = 0;
71
72 bool valid() const
73 {
74 return start != EDA_PATTERN_NOT_FOUND;
75 }
76
77 explicit operator bool() const
78 {
79 return valid();
80 }
81 };
82
83 virtual ~EDA_PATTERN_MATCH() {}
84
90 virtual bool SetPattern( const wxString& aPattern ) = 0;
91
95 virtual wxString const& GetPattern() const = 0;
96
103 virtual FIND_RESULT Find( const wxString& aCandidate ) const = 0;
104};
105
106
111{
112public:
113
114 virtual bool SetPattern( const wxString& aPattern ) override;
115 virtual wxString const& GetPattern() const override;
116 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
117
118protected:
119 wxString m_pattern;
120};
121
122
127{
128public:
129
130 virtual bool SetPattern( const wxString& aPattern ) override;
131 virtual wxString const& GetPattern() const override;
132 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
133
134protected:
135 wxString m_pattern;
136 wxRegEx m_regex;
137};
138
139
141{
142public:
143 virtual bool SetPattern( const wxString& aPattern ) override;
144};
145
146
148{
149public:
150
151 virtual bool SetPattern( const wxString& aPattern ) override;
152 virtual wxString const& GetPattern() const override;
153 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
154
155protected:
157};
158
159
161{
162public:
163 virtual bool SetPattern( const wxString& aPattern ) override;
164};
165
166
181{
182public:
183 virtual bool SetPattern( const wxString& aPattern ) override;
184 virtual wxString const& GetPattern() const override;
185 virtual FIND_RESULT Find( const wxString& aCandidate ) const override;
186 int FindOne( const wxString& aCandidate ) const;
187
188protected:
189
190 enum RELATION { LT, LE, EQ, GE, GT, ANY };
191
192 wxString m_pattern;
193 wxString m_key;
195 double m_value;
196
197 static const std::map<wxString, double> m_units;
198};
199
200
202{
209
210
212{
213public:
214 EDA_COMBINED_MATCHER( const wxString& aPattern, COMBINED_MATCHER_CONTEXT aContext );
215
221
227
237 bool Find( const wxString& aTerm, int& aMatchersTriggered, int& aPosition );
238
239 bool Find( const wxString& aTerm );
240
241 bool StartsWith( const wxString& aTerm );
242
243 const wxString& GetPattern() const;
244
245 int ScoreTerms( std::vector<SEARCH_TERM>& aWeightedTerms );
246
247private:
249 void AddMatcher( const wxString& aPattern, std::unique_ptr<EDA_PATTERN_MATCH> aMatcher );
250
251 std::vector<std::unique_ptr<EDA_PATTERN_MATCH>> m_matchers;
252 wxString m_pattern;
253};
254
255#endif // EDA_PATTERN_MATCH_H
std::vector< std::unique_ptr< EDA_PATTERN_MATCH > > m_matchers
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 ...
Match regular expression.
static const std::map< wxString, double > m_units
Match simple substring.
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...
virtual ~EDA_PATTERN_MATCH()
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:28
A structure for storing weighted search terms.
SEARCH_TERM(const wxString &aText, int aScore)