ircproxy  The Ultimate Cyborg

Prefix Class Reference

#include <Prefix.h>

List of all members.


Detailed Description

A class representing a message prefix.

Definition at line 29 of file Prefix.h.


Public Member Functions

 Prefix (void)
 The prefix, if it's a server (or any fixed string).
 Prefix (ClientMessageIn const &msg)
 Constructor.
 Prefix (ServerMessageIn const &msg)
 Constructor.
 Prefix (ServerSession &server_session, std::string const &prefix)
 Constructor.
 Prefix (ClientSession &client_session, std::string const &prefix)
 Constructor.
 Prefix (boost::shared_ptr< Nick > const &nick)
 Constructor.
 Prefix (std::string const &fixed_prefix_str)
 Constructor.
 Prefix (Prefix const &prefix)
 Constructor.
 ~Prefix ()
 Destructor.
std::string out_prefix (ClientSession const &client_session, bool allow_uninitialized=false) const
 Return the clientside prefix.
std::string out_prefix (ServerSession const &server_session, bool allow_uninitialized=false) const
 Return the serverside prefix.
bool empty (void) const
 Return true if there is no prefix.
boost::shared_ptr< Nickget_nick (void)
 Return shared pointer to underlying nick.
boost::shared_ptr< Nick const > get_nick (void) const
 Return shared pointer to underlying nick constant.

Private Attributes

std::string M_server_name
 The underlying Nick, if it's a user.

Constructor & Destructor Documentation

Prefix::Prefix ( void   )  [inline]

The prefix, if it's a server (or any fixed string).

Default constructor.

Definition at line 35 of file Prefix.h.

References debug::channels::dc::objects.

00035 { Dout(dc::objects, "Constructing empty Prefix."); }

Prefix::Prefix ( ClientMessageIn const &  msg  ) 

Constructor.

Definition at line 62 of file Prefix.cc.

References ClientMessageIn::client_session(), MessageIn::has_prefix(), and MessageIn::prefix_str().

00063 {
00064   if (msg.has_prefix())
00065     init(msg.client_session(), msg.prefix_str());
00066 }

Prefix::Prefix ( ServerMessageIn const &  msg  ) 

Constructor.

Definition at line 56 of file Prefix.cc.

References MessageIn::has_prefix(), MessageIn::prefix_str(), and ServerMessageIn::server_session().

00057 {
00058   if (msg.has_prefix())
00059     init(msg.server_session(), msg.prefix_str());
00060 }

Prefix::Prefix ( ServerSession server_session,
std::string const &  prefix 
) [inline]

Constructor.

Definition at line 41 of file Prefix.h.

00041 { init(server_session, prefix); }

Prefix::Prefix ( ClientSession client_session,
std::string const &  prefix 
) [inline]

Constructor.

Definition at line 43 of file Prefix.h.

00043 { init(client_session, prefix); }

Prefix::Prefix ( boost::shared_ptr< Nick > const &  nick  )  [inline, explicit]

Constructor.

Definition at line 45 of file Prefix.h.

References ASSERT, and debug::channels::dc::objects.

00045 : M_nick(nick) { ASSERT(nick.get()); Dout(dc::objects, "Constructing Prefix from " << nick); }

Prefix::Prefix ( std::string const &  fixed_prefix_str  )  [inline]

Constructor.

Definition at line 47 of file Prefix.h.

References debug::channels::dc::objects.

00047 : M_server_name(fixed_prefix_str) { Dout(dc::objects, "Constructing Prefix from fixed string \"" << fixed_prefix_str << "\"."); }

Prefix::Prefix ( Prefix const &  prefix  )  [inline]

Constructor.

Definition at line 49 of file Prefix.h.

References debug::channels::dc::objects.

00049 : M_nick(prefix.M_nick), M_server_name(prefix.M_server_name) { Dout(dc::objects, "Copy-constructing Prefix from " << prefix); }

Prefix::~Prefix (  )  [inline]

Destructor.

Definition at line 51 of file Prefix.h.

References debug::channels::dc::objects.

00051 { Dout(dc::objects, "Destructing Prefix " << *this); }


Member Function Documentation

std::string Prefix::out_prefix ( ClientSession const &  client_session,
bool  allow_uninitialized = false 
) const

Return the clientside prefix.

Definition at line 97 of file Prefix.cc.

References hostname_bit, M_server_name, and username_bit.

Referenced by Identity::new_server_message_received(), and JustInTimePrefix::value_impl().

00098 {
00099   if (!M_server_name.empty())
00100     return M_server_name;
00101   bool username_initialized = (M_nick->data().initialized() & username_bit);
00102   bool hostname_initialized = (M_nick->data().initialized() & hostname_bit);
00103   if (M_nick->is_me() && !(username_initialized && hostname_initialized))
00104     return M_nick->out_name(client_session);
00105   std::string result = M_nick->out_name(client_session);
00106   if (!username_initialized && allow_uninitialized)
00107     result += "!~unknown";
00108   else
00109   {
00110     result += '!';
00111     result += M_nick->data().username();
00112   }
00113   if (!hostname_initialized && allow_uninitialized)
00114     result += "@unknown.ircproxy.net";
00115   else
00116   {
00117     result += '@';
00118     result += M_nick->data().hostname();
00119   }
00120   return result;
00121 }

std::string Prefix::out_prefix ( ServerSession const &  server_session,
bool  allow_uninitialized = false 
) const

Return the serverside prefix.

Definition at line 69 of file Prefix.cc.

References ASSERT, hostname_bit, M_server_name, and username_bit.

00070 {
00071   if (!M_server_name.empty())
00072     return M_server_name;
00073   bool username_initialized = (M_nick->data().initialized() & username_bit);
00074   bool hostname_initialized = (M_nick->data().initialized() & hostname_bit);
00075   ASSERT(!M_nick->is_me() || !debug::secondary_connection);
00076   if (M_nick->is_me() && !(username_initialized && hostname_initialized))
00077     return M_nick->out_name(server_session);
00078   std::string result = M_nick->out_name(server_session);
00079   if (!username_initialized && allow_uninitialized)
00080     result += "!~unknown";
00081   else
00082   {
00083     result += '!';
00084     result += M_nick->data().username();
00085   }
00086   if (!hostname_initialized && allow_uninitialized)
00087     result += "@unknown.ircproxy.net";
00088   else
00089   {
00090     result += '@';
00091     result += M_nick->data().hostname();
00092   }
00093   return result;
00094 }

bool Prefix::empty ( void   )  const [inline]

Return true if there is no prefix.

Definition at line 62 of file Prefix.h.

References M_server_name.

Referenced by Channel::new_client_message_received(), and operator<<().

00062 { return M_nick.get() == NULL && M_server_name.empty(); }

boost::shared_ptr<Nick> Prefix::get_nick ( void   )  [inline]

Return shared pointer to underlying nick.

Definition at line 65 of file Prefix.h.

Referenced by Channel::new_client_message_received(), Identity::new_server_message_received(), and Channel::new_server_message_received().

00065 { return M_nick; }

boost::shared_ptr<Nick const> Prefix::get_nick ( void   )  const [inline]

Return shared pointer to underlying nick constant.

Definition at line 68 of file Prefix.h.

00068 { return M_nick; }


Member Data Documentation

std::string Prefix::M_server_name [private]

The underlying Nick, if it's a user.

Definition at line 32 of file Prefix.h.

Referenced by empty(), and out_prefix().


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

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