From 93f0bb8307ea26cc9ef96cf368110e8f6f0caead Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 3 Jan 2013 10:01:34 +0100 Subject: ExcludeList: convert to a class --- src/ExcludeList.hxx | 61 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'src/ExcludeList.hxx') diff --git a/src/ExcludeList.hxx b/src/ExcludeList.hxx index 52ba377b..4d678b08 100644 --- a/src/ExcludeList.hxx +++ b/src/ExcludeList.hxx @@ -25,25 +25,54 @@ #ifndef MPD_EXCLUDE_H #define MPD_EXCLUDE_H +#include "gcc.h" + +#include + #include -/** - * Loads and parses a .mpdignore file. - */ -GSList * -exclude_list_load(const char *path_fs); +class ExcludeList { + class Pattern { + GPatternSpec *pattern; -/** - * Frees a list returned by exclude_list_load(). - */ -void -exclude_list_free(GSList *list); + public: + Pattern(const char *_pattern) + :pattern(g_pattern_spec_new(_pattern)) {} + + Pattern(Pattern &&other) + :pattern(other.pattern) { + other.pattern = nullptr; + } + + ~Pattern() { + g_pattern_spec_free(pattern); + } + + gcc_pure + bool Check(const char *name_fs) const { + return g_pattern_match_string(pattern, name_fs); + } + }; + + std::forward_list patterns; + +public: + gcc_pure + bool IsEmpty() const { + return patterns.empty(); + } + + /** + * Loads and parses a .mpdignore file. + */ + bool LoadFile(const char *path_fs); + + /** + * Checks whether one of the patterns in the .mpdignore file matches + * the specified file name. + */ + bool Check(const char *name_fs) const; +}; -/** - * Checks whether one of the patterns in the .mpdignore file matches - * the specified file name. - */ -bool -exclude_list_check(GSList *list, const char *name_fs); #endif -- cgit v1.2.3