//=-- Filter.h - Filter for filtering URLs, and other strings ----------------=
//
//  This class implements a class that is used to filter a string against a 
//    standard unix style filter.  It also has code to load a filter from the
//    configuration file.  Example of a filter: "\~sabre\*MagicStats*"
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-1998 Chris Lattner
//=---------------------------------------------------------------------------=

#ifndef FILTER_H
#define FILTER_H

#include "LinkedList.h"
#include "AccessFormatPlugin.h"
class TextMatcher;

typedef Table<String,TextMatcher*> MatcherCache;

class MSAPI Filter {
  friend class FilterManager;
protected :
  // Protected constructor - The only way to get a filter object is to ask 
  //   your friendly FilterManager for one...
  Filter(const String &i, const String &e);

private :
  ~Filter();
  Filter(Filter &F);

public :
  int Match(const AccessFormatPlugin &);
  String ToParamStr();
  
  String IncludeFilter, ExcludeFilter;

  void AddRef();
  void DeleteRef();

private :
  typedef DataPair<int, TextMatcher*> Matcher;
  LinkedList<Matcher> I, E;

  static int FilterCount;

  // Wildcard Matchers...
  static MatcherCache &GetCachedWMatchers(int Delete = 0);

  // Regex Matchers...
  static MatcherCache &GetCachedRMatchers(int Delete = 0);

  int RefCount;

private :
  void DecodeFilter(LinkedList<Matcher> &L, const String &F);
};

#endif
