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