xref: /netbsd-src/external/bsd/elftosb/dist/common/ExcludesListMatcher.h (revision 993229b6fea628ff8b1fa09146c80b0cfb2768eb)
1 /*
2  * File:	ExcludesListMatcher.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_ExcludesListMatcher_h_)
8 #define _ExcludesListMatcher_h_
9 
10 #include "GlobMatcher.h"
11 #include <vector>
12 #include <string>
13 
14 namespace elftosb
15 {
16 
17 /*!
18  * \brief Matches strings using a series of include and exclude glob patterns.
19  *
20  * This string matcher class uses a sequential, ordered list of glob patterns to
21  * determine whether a string matches.  Attached to each pattern is an include/exclude
22  * action. The patterns in the list effectively form a Boolean expression. Includes
23  * act as an OR operator while excludes act as an AND NOT operator.
24  *
25  * Examples (plus prefix is include, minus prefix is exclude):
26  * - +foo: foo
27  * - -foo: !foo
28  * - +foo, +bar: foo || bar
29  * - +foo, -bar: foo && !bar
30  * - +foo, -bar, +baz: foo && !bar || baz
31  *
32  * The only reason for inheriting from GlobMatcher is so we can access the protected
33  * globMatch() method.
34  */
35 class ExcludesListMatcher : public GlobMatcher
36 {
37 public:
38 	//! \brief Default constructor.
39 	ExcludesListMatcher();
40 
41 	//! \brief Destructor.
42 	~ExcludesListMatcher();
43 
44 	//! \name Pattern list
45 	//@{
46 	//! \brief Add one include or exclude pattern to the end of the match list.
47 	void addPattern(bool isInclude, const std::string & pattern);
48 	//@}
49 
50 	//! \brief Performs a single string match test against testValue.
51 	virtual bool match(const std::string & testValue);
52 
53 protected:
54 	//! \brief Information about one glob pattern entry in a match list.
55 	struct glob_list_item_t
56 	{
57 		bool m_isInclude;	//!< True if include, false if exclude.
58 		std::string m_glob;	//!< The glob pattern to match.
59 	};
60 
61 	typedef std::vector<glob_list_item_t> glob_list_t;
62 	glob_list_t m_patterns;	//!< Ordered list of include and exclude patterns.
63 };
64 
65 }; // namespace elftosb
66 
67 #endif // _ExcludesListMatcher_h_
68