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