summaryrefslogtreecommitdiffstats
path: root/common/StringMatcher.h
blob: 01906cd78460b9c8bd96c55fd496c283d7e99ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * File:	GlobSectionSelector.h
 *
 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
 * See included license file for license details.
 */
#if !defined(_StringMatcher_h_)
#define _StringMatcher_h_

#include <string>

namespace elftosb
{

/*!
 * \brief Abstract interface class used to select strings by name.
 */
class StringMatcher
{
public:
	//! \brief Performs a single string match test against testValue.
	//!
	//! \retval true The \a testValue argument matches.
	//! \retval false No match was made against the argument.
	virtual bool match(const std::string & testValue)=0;
};

/*!
 * \brief String matcher subclass that matches all test strings.
 */
class WildcardMatcher : public StringMatcher
{
public:
	//! \brief Always returns true, indicating a positive match.
	virtual bool match(const std::string & /*testValue*/) { return true; }
};

/*!
 * \brief Simple string matcher that compares against a fixed value.
 */
class FixedMatcher : public StringMatcher
{
public:
	//! \brief Constructor. Sets the string to compare against to be \a fixedValue.
	FixedMatcher(const std::string & fixedValue) : m_value(fixedValue) {}
	
	//! \brief Returns whether \a testValue is the same as the value passed to the constructor.
	//!
	//! \retval true The \a testValue argument matches the fixed compare value.
	//! \retval false The argument is not the same as the compare value.
	virtual bool match(const std::string & testValue)
	{
		return testValue == m_value;
	}

protected:
	const std::string & m_value;	//!< The section name to look for.
};

}; // namespace elftosb

#endif // _StringMatcher_h_