00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef lestes__msg___message_stencil_hh___included
00029 #define lestes__msg___message_stencil_hh___included
00030
00031
00032
00033
00034
00035
00036
00037 #include <lestes/common.hh>
00038 #include <lestes/std/vector.hh>
00039 #include <lestes/msg/message.hh>
00040 #include <lestes/msg/formatter.hh>
00041
00042 package(lestes);
00043 package(msg);
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 class message_stencil : public ::lestes::std::object {
00067 public:
00068
00069 ulint nparams_get(void) const;
00070
00071 ulint kind_get(void) const;
00072
00073 bool equals(const ptr<message_stencil> &other) const;
00074 protected:
00075
00076 typedef message::flags_type flags_type;
00077
00078 typedef ::lestes::std::vector<lstring> args_type;
00079
00080 message_stencil(ulint a_nparams, const lstring &a_format, flags_type a_flags);
00081
00082 ptr<message> generate(const ptr<args_type> &args) const;
00083
00084 void gc_mark(void);
00085 private:
00086
00087 typedef ::lestes::std::vector<lstring> texts_type;
00088
00089 typedef ::lestes::std::vector<ulint> params_type;
00090
00091 void parse(const lstring &a_format);
00092
00093 ulint nparams;
00094
00095 ulint kind;
00096
00097 flags_type flags;
00098
00099 srp<texts_type> texts;
00100
00101 srp<params_type> params;
00102
00103 message_stencil(const message_stencil &);
00104
00105 message_stencil &operator=(const message_stencil &);
00106
00107 static ulint kind_counter;
00108 };
00109
00110
00111
00112
00113
00114
00115
00116 template <typename T>
00117 class message_stencil0 : public message_stencil {
00118 public:
00119
00120 ptr<message> format(void) const;
00121
00122 static ptr< message_stencil0<T> > create(const lstring &a_format, flags_type a_flags);
00123 protected:
00124
00125 message_stencil0(const lstring &a_format, flags_type a_flags);
00126
00127 void gc_mark(void);
00128 private:
00129
00130
00131
00132 void fake_method(T &);
00133
00134 message_stencil0(const message_stencil0<T> &);
00135
00136 message_stencil0<T> &operator=(const message_stencil0<T> &);
00137 };
00138
00139
00140
00141
00142
00143
00144 template <typename T>
00145 inline message_stencil0<T>::message_stencil0(const lstring &a_text, flags_type a_flags):
00146 message_stencil(0,a_text,a_flags)
00147 {
00148 }
00149
00150
00151
00152
00153
00154 template <typename T>
00155 ptr<message> message_stencil0<T>::format(void) const
00156 {
00157 ptr<args_type> args = args_type::create();
00158 return generate(args);
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168 template <typename T>
00169 ptr< message_stencil0<T> > message_stencil0<T>::create(const lstring &a_format, flags_type a_flags)
00170 {
00171 return new message_stencil0<T>(a_format,a_flags);
00172 }
00173
00174
00175
00176
00177 template <typename T>
00178 void message_stencil0<T>::gc_mark(void)
00179 {
00180 message_stencil::gc_mark();
00181 }
00182
00183
00184
00185
00186
00187
00188
00189 template <typename P0>
00190 class message_stencil1 : public message_stencil {
00191 public:
00192
00193 typedef formatter<P0> f0_type;
00194
00195 ptr<message> format(const P0 &p0) const;
00196
00197 static ptr< message_stencil1<P0> > create(const lstring &a_format, flags_type a_flags,
00198 const ptr<f0_type> &a_f0);
00199 protected:
00200
00201 message_stencil1(const lstring &a_format, flags_type a_flags,
00202 const ptr<f0_type> &a_f0);
00203
00204 void gc_mark(void);
00205 private:
00206
00207 srp<f0_type> f0;
00208
00209 message_stencil1(const message_stencil1<P0> &);
00210
00211 message_stencil1<P0> &operator=(const message_stencil1<P0> &);
00212 };
00213
00214
00215
00216
00217 template <typename P0>
00218 void message_stencil1<P0>::gc_mark(void)
00219 {
00220 f0.gc_mark();
00221 message_stencil::gc_mark();
00222 }
00223
00224
00225
00226
00227
00228
00229
00230 template <typename P0>
00231 message_stencil1<P0>::message_stencil1(const lstring &a_text, flags_type a_flags,
00232 const ptr<f0_type> &a_f0):
00233 message_stencil(1,a_text,a_flags),
00234 f0(checked(a_f0))
00235 {
00236 }
00237
00238
00239
00240
00241
00242
00243 template <typename P0>
00244 ptr<message> message_stencil1<P0>::format(const P0 &p0) const
00245 {
00246 ptr<args_type> args = args_type::create();
00247 args->push_back(f0->format(p0));
00248 return generate(args);
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 template <typename P0>
00261 ptr< message_stencil1<P0> > message_stencil1<P0>::create(const lstring &a_format, flags_type a_flags,
00262 const ptr<f0_type> &a_f0)
00263 {
00264 return new message_stencil1(a_format,a_flags,a_f0);
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274 template < typename P0, typename P1>
00275 class message_stencil2 : public message_stencil {
00276 public:
00277
00278 typedef formatter<P0> f0_type;
00279
00280 typedef formatter<P1> f1_type;
00281
00282 ptr<message> format(const P0 &p0, const P1 &p1) const;
00283
00284 static ptr< message_stencil2<P0,P1> > create(const lstring &a_format, flags_type a_flags,
00285 const ptr<f0_type> &a_f0, const ptr<f1_type> &a_f1);
00286 protected:
00287
00288 message_stencil2(const lstring &a_format, flags_type a_flags,
00289 const ptr<f0_type> &a_f0, const ptr<f1_type> &a_f1);
00290
00291 void gc_mark(void);
00292 private:
00293
00294 srp<f0_type> f0;
00295
00296 srp<f1_type> f1;
00297
00298 message_stencil2(const message_stencil2<P0,P1> &);
00299
00300 message_stencil2<P0,P1> &operator=(const message_stencil2<P0,P1> &);
00301 };
00302
00303
00304
00305
00306 template <typename P0, typename P1>
00307 void message_stencil2<P0,P1>::gc_mark(void)
00308 {
00309 f0.gc_mark();
00310 f1.gc_mark();
00311 message_stencil::gc_mark();
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321 template <typename P0, typename P1>
00322 message_stencil2<P0,P1>::message_stencil2(const lstring &a_text, flags_type a_flags,
00323 const ptr<f0_type> &a_f0, const ptr<f1_type> &a_f1):
00324 message_stencil(2,a_text,a_flags),
00325 f0(checked(a_f0)),
00326 f1(checked(a_f1))
00327 {
00328 }
00329
00330
00331
00332
00333
00334
00335
00336 template <typename P0, typename P1>
00337 ptr<message> message_stencil2<P0,P1>::format(const P0 &p0, const P1 &p1) const
00338 {
00339 ptr<args_type> args = args_type::create();
00340 args->push_back(f0->format(p0));
00341 args->push_back(f1->format(p1));
00342 return generate(args);
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 template <typename P0, typename P1>
00357 ptr< message_stencil2<P0,P1> > message_stencil2<P0,P1>::create(const lstring &a_format, flags_type a_flags,
00358 const ptr<f0_type> &a_f0, const ptr<f1_type> &a_f1)
00359 {
00360 return new message_stencil2(a_format,a_flags,a_f0,a_f1);
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 template < typename P0, typename P1, typename P2>
00372 class message_stencil3 : public message_stencil {
00373 public:
00374
00375 typedef formatter<P0> f0_type;
00376
00377 typedef formatter<P1> f1_type;
00378
00379 typedef formatter<P2> f2_type;
00380
00381 ptr<message> format(const P0 &p0, const P1 &p1, const P2 &p2) const;
00382
00383 static ptr< message_stencil3<P0,P1,P2> > create(const lstring &a_format,
00384 flags_type a_flags, const ptr<f0_type> &a_f0,
00385 const ptr<f1_type> &a_f1, const ptr<f2_type> &a_f2);
00386 protected:
00387
00388 message_stencil3(const lstring &a_format, flags_type a_flags, const ptr<f0_type> &a_f0,
00389 const ptr<f1_type> &a_f1, const ptr<f2_type> &a_f2);
00390
00391 void gc_mark(void);
00392 private:
00393
00394 srp<f0_type> f0;
00395
00396 srp<f1_type> f1;
00397
00398 srp<f2_type> f2;
00399
00400 message_stencil3(const message_stencil3<P0,P1,P2> &);
00401
00402 message_stencil3<P0,P1,P2> &operator=(const message_stencil3<P0,P1,P2> &);
00403 };
00404
00405
00406
00407
00408 template <typename P0, typename P1, typename P2>
00409 void message_stencil3<P0,P1,P2>::gc_mark(void)
00410 {
00411 f0.gc_mark();
00412 f1.gc_mark();
00413 f2.gc_mark();
00414 message_stencil::gc_mark();
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 template <typename P0, typename P1, typename P2>
00426 message_stencil3<P0,P1,P2>::message_stencil3(const lstring &a_text, flags_type a_flags,
00427 const ptr<f0_type> &a_f0, const ptr<f1_type> &a_f1, const ptr<f2_type> &a_f2):
00428 message_stencil(3,a_text,a_flags),
00429 f0(checked(a_f0)),
00430 f1(checked(a_f1)),
00431 f2(checked(a_f2))
00432 {
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442 template <typename P0, typename P1, typename P2>
00443 ptr<message> message_stencil3<P0,P1,P2>::format(const P0 &p0, const P1 &p1, const P2 &p2) const
00444 {
00445 ptr<args_type> args = args_type::create();
00446 args->push_back(f0->format(p0));
00447 args->push_back(f1->format(p1));
00448 args->push_back(f2->format(p2));
00449 return generate(args);
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465 template <typename P0, typename P1, typename P2>
00466 ptr< message_stencil3<P0,P1,P2> > message_stencil3<P0,P1,P2>::create(const lstring &a_format, flags_type a_flags,
00467 const ptr<f0_type> &a_f0, const ptr<f1_type> &a_f1, const ptr<f2_type> &a_f2)
00468 {
00469 return new message_stencil3(a_format,a_flags,a_f0,a_f1,a_f2);
00470 }
00471
00472 end_package(msg);
00473 end_package(lestes);
00474 #endif
00475