00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef PREFIX_H
00017 #define PREFIX_H
00018
00019 #ifndef USE_PCH
00020 #include "debug.h"
00021 #endif
00022
00023 #include "Nick.h"
00024
00025 class ClientMessageIn;
00026 class ServerMessageIn;
00027
00028
00029 class Prefix {
00030 private:
00031 boost::shared_ptr<Nick> M_nick;
00032 std::string M_server_name;
00033 public:
00034
00035 Prefix(void) { Dout(dc::objects, "Constructing empty Prefix."); }
00036
00037 Prefix(ClientMessageIn const& msg);
00038
00039 Prefix(ServerMessageIn const& msg);
00040
00041 Prefix(ServerSession& server_session, std::string const& prefix) { init(server_session, prefix); }
00042
00043 Prefix(ClientSession& client_session, std::string const& prefix) { init(client_session, prefix); }
00044
00045 explicit Prefix(boost::shared_ptr<Nick> const& nick) : M_nick(nick) { ASSERT(nick.get()); Dout(dc::objects, "Constructing Prefix from " << nick); }
00046
00047 Prefix(std::string const& fixed_prefix_str) : M_server_name(fixed_prefix_str) { Dout(dc::objects, "Constructing Prefix from fixed string \"" << fixed_prefix_str << "\"."); }
00048
00049 Prefix(Prefix const& prefix) : M_nick(prefix.M_nick), M_server_name(prefix.M_server_name) { Dout(dc::objects, "Copy-constructing Prefix from " << prefix); }
00050
00051 ~Prefix() { Dout(dc::objects, "Destructing Prefix " << *this); }
00052 std::string out_prefix(ClientSession const& client_session, bool allow_uninitialized = false) const;
00053 std::string out_prefix(ServerSession const& server_session, bool allow_uninitialized = false) const;
00054
00055 #ifdef CWDEBUG
00056
00057 Nick* nick(void) const { return M_nick.get(); }
00058 std::string const& server_name(void) const { return M_server_name; }
00059 #endif
00060
00061
00062 bool empty(void) const { return M_nick.get() == NULL && M_server_name.empty(); }
00063
00064
00065 boost::shared_ptr<Nick> get_nick(void) { return M_nick; }
00066
00067
00068 boost::shared_ptr<Nick const> get_nick(void) const { return M_nick; }
00069
00070 private:
00071 template<class SESSION>
00072 void init(SESSION& session, std::string const& prefix);
00073 };
00074
00075 #endif // PREFIX_H