//=-- FilterHandle.h -  ----------------=
//
//  
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-1998 Chris Lattner
//=---------------------------------------------------------------------------=

#ifndef FILTERHANDLE_H
#define FILTERHANDLE_H

#include "MSString.h"
#include "Filter.h"

class MSAPI FilterHandle : public Object {
public :
  FilterHandle() { 
    F = 0; 
  }

  FilterHandle(Filter *filter) { 
    F = filter;
    if (F) F->AddRef();
  }

  // Provide this so that we can search a linked list of plugins for the string
  //  specified as the parameter.
  FilterHandle(String &S) { 
    F = 0; 
    Paramstr = S; 
  }

  FilterHandle(const FilterHandle &FH) : Object(FH) {
    F = FH.F;
    if (F) F->AddRef();
    Paramstr = FH.Paramstr;
  }

  FilterHandle &operator=(const FilterHandle &FH) {
    if (F)
      F->DeleteRef();
    F = FH.F;
    Paramstr = FH.Paramstr;
    F->AddRef();

    return *this;
  }

  ~FilterHandle() {
    if (F) F->DeleteRef();
  }

  int Compare(const Object &FH) const {
    return ToParamStr().Compare(((FilterHandle&)FH).ToParamStr());
  }

  ostream &print(ostream &o) const { 
    return o << "Filter: " << F->ToParamStr() << endl; 
  }

  String ToParamStr() const { 
    if (F)
      return F->ToParamStr();
    else
      return Paramstr;
  }

  inline int Match(const AccessFormatPlugin &A) { return F ? F->Match(A) : 1; }

private :
  Filter *F;
  String Paramstr;
};

#endif
