xref: /netbsd-src/external/bsd/elftosb/dist/common/StringMatcher.h (revision 993229b6fea628ff8b1fa09146c80b0cfb2768eb)
1*993229b6Sjkunz /*
2*993229b6Sjkunz  * File:	GlobSectionSelector.h
3*993229b6Sjkunz  *
4*993229b6Sjkunz  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5*993229b6Sjkunz  * See included license file for license details.
6*993229b6Sjkunz  */
7*993229b6Sjkunz #if !defined(_StringMatcher_h_)
8*993229b6Sjkunz #define _StringMatcher_h_
9*993229b6Sjkunz 
10*993229b6Sjkunz #include <string>
11*993229b6Sjkunz 
12*993229b6Sjkunz namespace elftosb
13*993229b6Sjkunz {
14*993229b6Sjkunz 
15*993229b6Sjkunz /*!
16*993229b6Sjkunz  * \brief Abstract interface class used to select strings by name.
17*993229b6Sjkunz  */
18*993229b6Sjkunz class StringMatcher
19*993229b6Sjkunz {
20*993229b6Sjkunz public:
21*993229b6Sjkunz 	//! \brief Performs a single string match test against testValue.
22*993229b6Sjkunz 	//!
23*993229b6Sjkunz 	//! \retval true The \a testValue argument matches.
24*993229b6Sjkunz 	//! \retval false No match was made against the argument.
25*993229b6Sjkunz 	virtual bool match(const std::string & testValue)=0;
26*993229b6Sjkunz };
27*993229b6Sjkunz 
28*993229b6Sjkunz /*!
29*993229b6Sjkunz  * \brief String matcher subclass that matches all test strings.
30*993229b6Sjkunz  */
31*993229b6Sjkunz class WildcardMatcher : public StringMatcher
32*993229b6Sjkunz {
33*993229b6Sjkunz public:
34*993229b6Sjkunz 	//! \brief Always returns true, indicating a positive match.
match(const std::string & testValue)35*993229b6Sjkunz 	virtual bool match(const std::string & testValue) { return true; }
36*993229b6Sjkunz };
37*993229b6Sjkunz 
38*993229b6Sjkunz /*!
39*993229b6Sjkunz  * \brief Simple string matcher that compares against a fixed value.
40*993229b6Sjkunz  */
41*993229b6Sjkunz class FixedMatcher : public StringMatcher
42*993229b6Sjkunz {
43*993229b6Sjkunz public:
44*993229b6Sjkunz 	//! \brief Constructor. Sets the string to compare against to be \a fixedValue.
FixedMatcher(const std::string & fixedValue)45*993229b6Sjkunz 	FixedMatcher(const std::string & fixedValue) : m_value(fixedValue) {}
46*993229b6Sjkunz 
47*993229b6Sjkunz 	//! \brief Returns whether \a testValue is the same as the value passed to the constructor.
48*993229b6Sjkunz 	//!
49*993229b6Sjkunz 	//! \retval true The \a testValue argument matches the fixed compare value.
50*993229b6Sjkunz 	//! \retval false The argument is not the same as the compare value.
match(const std::string & testValue)51*993229b6Sjkunz 	virtual bool match(const std::string & testValue)
52*993229b6Sjkunz 	{
53*993229b6Sjkunz 		return testValue == m_value;
54*993229b6Sjkunz 	}
55*993229b6Sjkunz 
56*993229b6Sjkunz protected:
57*993229b6Sjkunz 	const std::string & m_value;	//!< The section name to look for.
58*993229b6Sjkunz };
59*993229b6Sjkunz 
60*993229b6Sjkunz }; // namespace elftosb
61*993229b6Sjkunz 
62*993229b6Sjkunz #endif // _StringMatcher_h_
63