ircproxy  The Ultimate Cyborg

Matcher Class Reference

#include <Matcher.h>

Inheritance diagram for Matcher:

Matcher_exactmatch Matcher_matchcomp Matcher_noarg Matcher_regexp

List of all members.


Detailed Description

Matcher base class.

Definition at line 63 of file Matcher.h.


Public Member Functions

 Matcher (int param, bool single_param)
 Construct a Matcher that matches against parameter param, including all following parameters if single_param is true.
virtual ~Matcher ()
 Virtual destructor.
bool match (ServerMessageIn const &msg)
 Returns true if message msg matches this Matcher.
virtual void print_on (std::ostream &os) const
 For debugging purposes. Write the contents of this object to os.
virtual int sort_value (void)=0
 Returns an indication of the match algorithm speed (smaller is faster).

Static Public Member Functions

static boost::shared_ptr< Matchercreate (int param, match0_type mt, bool single_param=true)
 Create and return a shared pointer to a Matcher.
static boost::shared_ptr< Matchercreate (int param, match1_type mt, std::string const &arg, bool single_param=true)
 Create and return a shared pointer to a Matcher.

Protected Member Functions

virtual bool match_impl (ServerSession const &server_session, char const *start, size_t len)=0
 Match implementation interface filled in by derived classes.

Private Attributes

int M_param
 Parameter, or prefix when M_param is -1.
bool M_single_param
 True if we only match against parameter M_param. False if we match against parameters M_param and higher.

Constructor & Destructor Documentation

Matcher::Matcher ( int  param,
bool  single_param 
) [inline]

Construct a Matcher that matches against parameter param, including all following parameters if single_param is true.

Definition at line 70 of file Matcher.h.

00070 : M_param(param), M_single_param(single_param) { }

virtual Matcher::~Matcher (  )  [inline, virtual]

Virtual destructor.

Definition at line 72 of file Matcher.h.

00072 { }


Member Function Documentation

boost::shared_ptr< Matcher > Matcher::create ( int  param,
match0_type  mt,
bool  single_param = true 
) [inline, static]

Create and return a shared pointer to a Matcher.

Create and return a matcher of match0_type mt.

Definition at line 228 of file Matcher.h.

Referenced by MatchRequest::anychannel(), MatchRequest::anyglobalchannel(), MatchRequest::anylocalchannel(), MatchRequest::anynick(), MatchRequest::anyserver(), MatchRequest::anystring(), MatchRequest::exactmatch(), MatchRequest::localserver(), MatchRequest::mynick(), MatchRequest::nonemptystring(), MatchRequest::regexp(), and MatchRequest::wildcard().

00229 {
00230   return boost::shared_ptr<Matcher>(NEW(Matcher_noarg(param, mt, single_param)));
00231 }

boost::shared_ptr< Matcher > Matcher::create ( int  param,
match1_type  mt,
std::string const &  arg,
bool  single_param = true 
) [static]

Create and return a shared pointer to a Matcher.

Definition at line 71 of file Matcher.cc.

References debug::channels::dc::matcher.

00072 {
00073   boost::shared_ptr<Matcher> matcher;
00074   switch(mt)
00075   {
00076     case wildcard_mt:
00077       matcher.reset(NEW(Matcher_matchcomp(param, arg, single_param)));
00078       break;
00079     case regexp_mt:
00080       matcher.reset(NEW(Matcher_regexp(param, arg, single_param)));
00081       break;
00082     case exactmatch_mt:
00083       matcher.reset(NEW(Matcher_exactmatch(param, arg, single_param)));
00084       break;
00085   }
00086   return matcher;
00087 }

bool Matcher::match ( ServerMessageIn const &  msg  ) 

Returns true if message msg matches this Matcher.

Definition at line 98 of file Matcher.cc.

References MessageIn::end(), M_param, M_single_param, match_impl(), debug::channels::dc::matcher, MessageIn::params(), MessageIn::prefix_part(), and ServerMessageIn::server_session().

00099 {
00100   MessageIn::Part const& part((M_param == prefix) ? msg.prefix_part() : msg.params()[M_param]);
00101   char const* start = part.start();
00102   size_t len = M_single_param ? part.len() : (msg.end() - start);
00103   Dout(dc::matcher|continued_cf, "Matching \"" << buf2str(start, len) << "\" against {" << cwprint(*this) << "} : ");
00104   bool result = match_impl(msg.server_session(), start, len);
00105   Dout(dc::finish, (result ? "(matched)" : "(did not match)"));
00106   return result;
00107 }

virtual void Matcher::print_on ( std::ostream &  os  )  const [inline, virtual]

For debugging purposes. Write the contents of this object to os.

Reimplemented in Matcher_noarg, Matcher_matchcomp, Matcher_regexp, and Matcher_exactmatch.

Definition at line 87 of file Matcher.h.

References M_param, and M_single_param.

Referenced by operator<<().

00088     {
00089       os << "param:";
00090       if (M_param == prefix)
00091         os << "prefix";
00092       else
00093         os << M_param;
00094       os << ", single_param:" << (M_single_param ? "true" : "false");
00095     }

virtual bool Matcher::match_impl ( ServerSession const &  server_session,
char const *  start,
size_t  len 
) [protected, pure virtual]

Match implementation interface filled in by derived classes.

Implemented in Matcher_noarg, Matcher_matchcomp, Matcher_regexp, and Matcher_exactmatch.

Referenced by match().

virtual int Matcher::sort_value ( void   )  [pure virtual]

Returns an indication of the match algorithm speed (smaller is faster).

Implemented in Matcher_noarg, Matcher_matchcomp, Matcher_regexp, and Matcher_exactmatch.


Member Data Documentation

int Matcher::M_param [private]

Parameter, or prefix when M_param is -1.

Definition at line 65 of file Matcher.h.

Referenced by match(), and print_on().

bool Matcher::M_single_param [private]

True if we only match against parameter M_param. False if we match against parameters M_param and higher.

Definition at line 66 of file Matcher.h.

Referenced by match(), and print_on().


The documentation for this class was generated from the following files:

Copyright © 2005-2007 Carlo Wood.  All rights reserved.