00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef JUSTINTIME_H
00017 #define JUSTINTIME_H
00018
00019 #ifndef USE_PCH
00020 #include <string>
00021 #include "debug.h"
00022 #endif
00023
00024 #include "command_to_str.h"
00025
00026
00027 class JustInTimeToken {
00028 public:
00029
00030 virtual ~JustInTimeToken() { }
00031 virtual std::string value(ClientSession const&) const = 0;
00032 virtual std::string value(ServerSession const&) const = 0;
00033 virtual void write_to(std::ostream& os, ClientSession const&) const = 0;
00034 virtual void write_to(std::ostream& os, ServerSession const&) const = 0;
00035 virtual bool is_prefix(void) { return false; }
00036 };
00037
00038
00039 class JustInTimeString : public JustInTimeToken {
00040 private:
00041 std::string M_token;
00042 public:
00043
00044 JustInTimeString(std::string const& token) : M_token(token) { }
00045
00046 virtual std::string value(ClientSession const&) const { return M_token; }
00047 virtual std::string value(ServerSession const&) const { return M_token; }
00048
00049 virtual void write_to(std::ostream& os, ClientSession const&) const { os << ' ' << M_token; }
00050 virtual void write_to(std::ostream& os, ServerSession const&) const { os << ' ' << M_token; }
00051 };
00052
00053
00054 class JustInTimeChar : public JustInTimeToken {
00055 private:
00056 char M_token;
00057 public:
00058
00059 JustInTimeChar(char token) : M_token(token) { }
00060
00061 virtual std::string value(ClientSession const&) const { std::string result; result = M_token; return result; }
00062 virtual std::string value(ServerSession const&) const { std::string result; result = M_token; return result; }
00063
00064 virtual void write_to(std::ostream& os, ClientSession const&) const { os << ' ' << M_token; }
00065 virtual void write_to(std::ostream& os, ServerSession const&) const { os << ' ' << M_token; }
00066 };
00067
00068
00069 class JustInTimeLong : public JustInTimeToken {
00070 private:
00071 long M_token;
00072 public:
00073
00074 JustInTimeLong(long token) : M_token(token) { }
00075
00076 virtual std::string value(ClientSession const&) const { std::ostringstream result; result << M_token; return result.str(); }
00077 virtual std::string value(ServerSession const&) const { std::ostringstream result; result << M_token; return result.str(); }
00078
00079 virtual void write_to(std::ostream& os, ClientSession const&) const { os << ' ' << M_token; }
00080 virtual void write_to(std::ostream& os, ServerSession const&) const { os << ' ' << M_token; }
00081 };
00082
00083
00084 class JustInTimeTarget : public JustInTimeToken {
00085 private:
00086 boost::shared_ptr<Target> M_target;
00087 private:
00088
00089 std::string value_impl(ClientSession const& session) const { return M_target->out_name(session); }
00090 std::string value_impl(ServerSession const& session) const { return M_target->out_name(session); }
00091 public:
00092
00093 JustInTimeTarget(boost::shared_ptr<Target> const& target) : M_target(target) { }
00094
00095 virtual std::string value(ClientSession const& session) const { return value_impl(session); }
00096 virtual std::string value(ServerSession const& session) const { return value_impl(session); }
00097
00098 virtual void write_to(std::ostream& os, ClientSession const& session) const { os << ' ' << value_impl(session); }
00099 virtual void write_to(std::ostream& os, ServerSession const& session) const { os << ' ' << value_impl(session); }
00100 };
00101
00102
00103 class JustInTimeCommand : public JustInTimeToken {
00104 private:
00105 int M_token;
00106 public:
00107
00108 JustInTimeCommand(int token) : M_token(token) { }
00109
00110 virtual std::string value(ClientSession const&) const { return command_to_str(M_token); }
00111 virtual std::string value(ServerSession const&) const { return command_to_str(M_token); }
00112
00113 virtual void write_to(std::ostream& os, ClientSession const&) const { os << command_to_str(M_token); }
00114 virtual void write_to(std::ostream& os, ServerSession const&) const { os << command_to_str(M_token); }
00115
00116 virtual int command(void) const { return M_token; }
00117 };
00118
00119
00120 class JustInTimePrefix : public JustInTimeToken {
00121 private:
00122 Prefix M_token;
00123 private:
00124
00125 virtual std::string value_impl(ClientSession const& session) const { return M_token.out_prefix(session, true); }
00126 virtual std::string value_impl(ServerSession const& session) const { return M_token.out_prefix(session, true); }
00127 public:
00128
00129 JustInTimePrefix(Prefix const& token) : M_token(token) { }
00130
00131 virtual std::string value(ClientSession const& session) const { return value_impl(session); }
00132 virtual std::string value(ServerSession const& session) const { return value_impl(session); }
00133
00134 virtual void write_to(std::ostream& os, ClientSession const& session) const { os << ':' << value_impl(session) << ' '; }
00135 virtual void write_to(std::ostream& os, ServerSession const& session) const { os << ':' << value_impl(session) << ' '; }
00136
00137 virtual bool is_prefix(void) { return true; }
00138 };
00139
00140
00141 class JustInTimeMsgPart : public JustInTimeToken {
00142 private:
00143 MsgPart M_token;
00144 public:
00145
00146 JustInTimeMsgPart(MsgPart const& token) : M_token(token) { }
00147
00148 virtual std::string value(ClientSession const&) const { return std::string(M_token.start(), M_token.len()); }
00149 virtual std::string value(ServerSession const&) const { return std::string(M_token.start(), M_token.len()); }
00150
00151 virtual void write_to(std::ostream& os, ClientSession const&) const { os << ' '; os.write(M_token.start(), M_token.len()); }
00152 virtual void write_to(std::ostream& os, ServerSession const&) const { os << ' '; os.write(M_token.start(), M_token.len()); }
00153 };
00154
00155
00156
00157
00158
00159 class JustInTimeCatenate : public JustInTimeToken {
00160 private:
00161 boost::shared_ptr<JustInTimeToken> M_token;
00162 public:
00163
00164 JustInTimeCatenate(char token) : M_token(NEW(JustInTimeChar(token))) { }
00165
00166 JustInTimeCatenate(std::string const& token) : M_token(NEW(JustInTimeString(token))) { }
00167
00168 JustInTimeCatenate(boost::shared_ptr<Target> const& token) : M_token(NEW(JustInTimeTarget(token))) { }
00169
00170 JustInTimeCatenate(MsgPart const& token) : M_token(NEW(JustInTimeMsgPart(token))) { }
00171
00172
00173 virtual std::string value(ClientSession const& session) const { return M_token->value(session); }
00174 virtual std::string value(ServerSession const& session) const { return M_token->value(session); }
00175
00176 virtual void write_to(std::ostream& os, ClientSession const& session) const { os << M_token->value(session); }
00177 virtual void write_to(std::ostream& os, ServerSession const& session) const { os << M_token->value(session); }
00178 };
00179
00180
00181
00182
00183
00184 class JustInTimeLast : public JustInTimeToken {
00185 private:
00186 boost::shared_ptr<JustInTimeToken> M_token;
00187 public:
00188
00189 JustInTimeLast(std::string const& token) : M_token(NEW(JustInTimeString(token))) { }
00190
00191 JustInTimeLast(MsgPart const& token) : M_token(NEW(JustInTimeMsgPart(token))) { }
00192
00193
00194 virtual std::string value(ClientSession const& session) const { return M_token->value(session); }
00195 virtual std::string value(ServerSession const& session) const { return M_token->value(session); }
00196
00197 virtual void write_to(std::ostream& os, ClientSession const& session) const { os << " :" << M_token->value(session); }
00198 virtual void write_to(std::ostream& os, ServerSession const& session) const { os << " :" << M_token->value(session); }
00199 };
00200
00201 #endif // JUSTINTIME
00202