ircproxy  The Ultimate Cyborg

Network Class Reference

#include <Network.h>

List of all members.


Detailed Description

An IRC network.

This class represents an IRC network. Servers that are part of a network can be added manually or might have been seen by the IRC proxy while connected to this network. The list of servers is therefore not necessarily up to date.

Definition at line 39 of file Network.h.


Public Types

typedef std::vector
< boost::shared_ptr< Server > > 
servers_type
 The type of Network::M_servers.
typedef uint32_t who_flags_type
 < The type of the WHO flags mask.
typedef std::vector< WhoMapwho_flag_vector_type
 A vector mapping WHO flag characters with their mask bit.

Public Member Functions

 Network (void)
 Construct an uninitialized object. It will be initialized by Network::serialize.
 Network (std::string const &name, bool priv=false)
 Construct a Network object with name name, without common domain.
 Network (std::string const &name, std::string const &domain, bool priv=false)
 Construct a Network object with name name and common domain domain.
std::string const & name (void) const
 Human readable name of this network.
bool has_domain (void) const
 True iff this Network object has a common domain name set.
std::string const & domain (void) const
 The common domain name of this network. May only be called when Network::has_domain returns true.
servers_type const & servers (void) const
 A const reference to the list of servers associated with this network.
servers_typeservers (void)
 A reference to the list of servers associated with this network.
target_lookup_map_type const & targets (void) const
 A const reference to an STL container with all known targets.
target_lookup_map_typetargets (void)
 A reference to an STL container with all known targets.
bool is_private (void) const
 Returns true if this is a private network, owned by an Identity.
void init_who_flag_table (std::string const &umodes, std::string prefix)
 Initialize M_who_flag_vector, called when numeric 005 is received.
char flag_to_char (who_flags_type maskbit) const
 Translate a mask bit to it's WHO flag character.
who_flags_type char_to_flag (char who_flag) const
 Translate a WHO flag character to it's mask bit.
void serialize (PersistXML &xml)
 Serialize object to XML.

Private Attributes

std::string M_name
 Human readable name of network.
std::string M_domain
 Common domain of servers, if any. Empty otherwise.
servers_type M_servers
 List of all known servers that belong to this network.
target_lookup_map_type M_targets
 Map with all known targets, related to at least one existing Identity. Only valid when M_private is false.
bool M_private
 True if this is a private network (owned by Identity).
who_flag_vector_type M_who_flag_vector
 Vector with mapping between WHO flags and corresponding mask bits.

Classes

struct  WhoMap
 A pair matching a WHO flag with it's mask bit. More...

Member Typedef Documentation

typedef std::vector<boost::shared_ptr<Server> > Network::servers_type

The type of Network::M_servers.

Definition at line 41 of file Network.h.

typedef uint32_t Network::who_flags_type

< The type of the WHO flags mask.

Definition at line 106 of file Network.h.

typedef std::vector<WhoMap> Network::who_flag_vector_type

A vector mapping WHO flag characters with their mask bit.

Definition at line 110 of file Network.h.


Constructor & Destructor Documentation

Network::Network ( void   )  [inline]

Construct an uninitialized object. It will be initialized by Network::serialize.

Definition at line 52 of file Network.h.

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

00052                 : M_private(false)              // Private networks are not serialized.
00053       { Dout(dc::objects, "Constructing Network()"); }

Network::Network ( std::string const &  name,
bool  priv = false 
) [inline]

Construct a Network object with name name, without common domain.

Definition at line 56 of file Network.h.

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

00056                                                     : M_name(name), M_private(priv)
00057       { Dout(dc::objects, "Constructing Network(\"" << name << "\", " << priv << ")"); }

Network::Network ( std::string const &  name,
std::string const &  domain,
bool  priv = false 
) [inline]

Construct a Network object with name name and common domain domain.

Definition at line 60 of file Network.h.

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

00060                                                                              :
00061       M_name(name), M_domain(domain), M_private(priv)
00062       { Dout(dc::objects, "Constructing Network(\"" << name << "\", \"" << domain << "\", " << priv << ")"); }


Member Function Documentation

std::string const& Network::name ( void   )  const [inline]

Human readable name of this network.

Definition at line 79 of file Network.h.

References M_name.

Referenced by operator<<(), and Target::~Target().

00079 { return M_name; }

bool Network::has_domain ( void   )  const [inline]

True iff this Network object has a common domain name set.

Definition at line 82 of file Network.h.

References M_domain.

Referenced by domain(), and operator<<().

00082 { return !M_domain.empty(); }

std::string const& Network::domain ( void   )  const [inline]

The common domain name of this network. May only be called when Network::has_domain returns true.

Definition at line 85 of file Network.h.

References has_domain(), and M_domain.

Referenced by operator<<().

00085 { assert(has_domain()); return M_domain; }

servers_type const& Network::servers ( void   )  const [inline]

A const reference to the list of servers associated with this network.

Definition at line 88 of file Network.h.

References M_servers.

Referenced by operator<<().

00088 { return M_servers; }

servers_type& Network::servers ( void   )  [inline]

A reference to the list of servers associated with this network.

Definition at line 91 of file Network.h.

References M_servers.

00091 { return M_servers; }

target_lookup_map_type const& Network::targets ( void   )  const [inline]

A const reference to an STL container with all known targets.

Definition at line 94 of file Network.h.

References ASSERT, M_private, and M_targets.

Referenced by Target::add_channel(), Target::add_joined_nick(), ServerSession::get_nick(), Target::serverside_add_channel(), Nick::serverside_nick_changed_to(), and Target::~Target().

00094 { ASSERT(!M_private); return M_targets; }

target_lookup_map_type& Network::targets ( void   )  [inline]

A reference to an STL container with all known targets.

Definition at line 97 of file Network.h.

References ASSERT, M_private, and M_targets.

00097 { ASSERT(!M_private); return M_targets; }

bool Network::is_private ( void   )  const [inline]

void Network::init_who_flag_table ( std::string const &  umodes,
std::string  prefix 
)

Initialize M_who_flag_vector, called when numeric 005 is received.

Definition at line 24 of file Flags.cc.

References ASSERT, and M_who_flag_vector.

00025 {
00026   // Only initialize the table once.
00027   if (!M_who_flag_vector.empty())
00028     return;
00029   // FIXME: use prefix to map special characters to channel modes.
00030   int n = 1;    // The AWAY flag (H/G).
00031   n += umodes.size();
00032   M_who_flag_vector.resize(n);
00033   while(--n)
00034   {
00035     ASSERT(umodes[n] != '*');   // '*' has the special meaning of umode 'o', see Network::char_to_flag.
00036     M_who_flag_vector[n].who_flag = umodes[n];
00037     M_who_flag_vector[n].mask = (1 << n);
00038   }
00039   // By ignoring the 'H' flag, we get the same effect for 'G' as for any other flag.
00040   M_who_flag_vector[n].who_flag = 'G';
00041   M_who_flag_vector[n].mask = 1;
00042 }

char Network::flag_to_char ( who_flags_type  maskbit  )  const

Translate a mask bit to it's WHO flag character.

Definition at line 44 of file Flags.cc.

References ASSERT, and M_who_flag_vector.

00045 {
00046   // Make sure that Network::init_who_flag_table was already called.
00047   ASSERT(!M_who_flag_vector.empty());
00048   // Find the corresponding flag.
00049   int index = 0;
00050 #ifdef CWDEBUG
00051   who_flags_type orig_maskbit;
00052 #endif
00053   while ((maskbit >>= 1))
00054     ++index;
00055 #ifdef CWDEBUG
00056   if (M_who_flag_vector[index].mask != orig_maskbit)
00057     DoutFatal(dc::core, "Network::flag_to_char: Unknown maskbit " << std::hex << "0x" << orig_maskbit);
00058 #endif
00059   return M_who_flag_vector[index].who_flag;
00060 }

flags_type Network::char_to_flag ( char  who_flag  )  const

Translate a WHO flag character to it's mask bit.

Definition at line 62 of file Flags.cc.

References ASSERT, and M_who_flag_vector.

Referenced by Flags::assign().

00063 {
00064   // Make sure that Network::init_who_flag_table was already called.
00065   ASSERT(!M_who_flag_vector.empty());
00066   // Find the corresponding mask.
00067   if (who_flag == '*')
00068     who_flag = 'o';
00069   for (who_flag_vector_type::const_iterator iter = M_who_flag_vector.begin(); iter != M_who_flag_vector.end(); ++iter)
00070     if (iter->who_flag == who_flag)
00071       return iter->mask;
00072   // We deliberately do not process 'H' because it just means that flag 'G' is off.
00073   // We also don't handle '@' because we never use WHO to determine who is op and who isn't.
00074   if (who_flag != 'H' && who_flag != '@')
00075     Dout(dc::warning, "Network::char_to_flag: Unknown who_flag '" << who_flag << "'.");
00076   return 0;
00077 }

void Network::serialize ( PersistXML xml  ) 

Serialize object to XML.

Definition at line 27 of file Network.cc.

References M_domain, M_name, M_servers, and PersistXML::serialize().

00028 {
00029   xml.serialize("M_name", M_name);
00030   xml.serialize("M_domain", M_domain);
00031   xml.serialize("M_servers", M_servers);
00032 }


Member Data Documentation

std::string Network::M_name [private]

Human readable name of network.

Definition at line 44 of file Network.h.

Referenced by name(), and serialize().

std::string Network::M_domain [private]

Common domain of servers, if any. Empty otherwise.

Definition at line 45 of file Network.h.

Referenced by domain(), has_domain(), and serialize().

List of all known servers that belong to this network.

Definition at line 46 of file Network.h.

Referenced by serialize(), and servers().

Map with all known targets, related to at least one existing Identity. Only valid when M_private is false.

Definition at line 47 of file Network.h.

Referenced by targets().

bool Network::M_private [private]

True if this is a private network (owned by Identity).

Definition at line 48 of file Network.h.

Referenced by is_private(), and targets().

Vector with mapping between WHO flags and corresponding mask bits.

Definition at line 113 of file Network.h.

Referenced by char_to_flag(), flag_to_char(), and init_who_flag_table().


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

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