File indexing completed on 2024-11-15 09:31:29
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_SPIRIT_CLASSIC_PHOENIX_STATEMENTS_HPP
0009 #define BOOST_SPIRIT_CLASSIC_PHOENIX_STATEMENTS_HPP
0010
0011
0012 #include <boost/spirit/home/classic/phoenix/composite.hpp>
0013
0014
0015 namespace phoenix {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 template <typename A0, typename A1>
0034 struct sequential_composite {
0035
0036 typedef sequential_composite<A0, A1> self_t;
0037
0038 template <typename TupleT>
0039 struct result { typedef void type; };
0040
0041 sequential_composite(A0 const& _0, A1 const& _1)
0042 : a0(_0), a1(_1) {}
0043
0044 template <typename TupleT>
0045 void
0046 eval(TupleT const& args) const
0047 {
0048 a0.eval(args);
0049 a1.eval(args);
0050 }
0051
0052 A0 a0; A1 a1;
0053 };
0054
0055
0056 template <typename BaseT0, typename BaseT1>
0057 inline actor<sequential_composite<actor<BaseT0>, actor<BaseT1> > >
0058 operator,(actor<BaseT0> const& _0, actor<BaseT1> const& _1)
0059 {
0060 return sequential_composite<actor<BaseT0>, actor<BaseT1> >(_0, _1);
0061 }
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 template <typename CondT, typename ThenT, typename ElseT>
0094 struct if_then_else_composite {
0095
0096 typedef if_then_else_composite<CondT, ThenT, ElseT> self_t;
0097
0098 template <typename TupleT>
0099 struct result {
0100
0101 typedef void type;
0102 };
0103
0104 if_then_else_composite(
0105 CondT const& cond_,
0106 ThenT const& then_,
0107 ElseT const& else__)
0108 : cond(cond_), then(then_), else_(else__) {}
0109
0110 template <typename TupleT>
0111 void eval(TupleT const& args) const
0112 {
0113 if (cond.eval(args))
0114 then.eval(args);
0115 else
0116 else_.eval(args);
0117 }
0118
0119 CondT cond; ThenT then; ElseT else_;
0120 };
0121
0122
0123 template <typename CondT, typename ThenT>
0124 struct else_gen {
0125
0126 else_gen(CondT const& cond_, ThenT const& then_)
0127 : cond(cond_), then(then_) {}
0128
0129 template <typename ElseT>
0130 actor<if_then_else_composite<CondT, ThenT,
0131 typename as_actor<ElseT>::type> >
0132 operator[](ElseT const& else_)
0133 {
0134 typedef if_then_else_composite<CondT, ThenT,
0135 typename as_actor<ElseT>::type>
0136 result;
0137
0138 return result(cond, then, as_actor<ElseT>::convert(else_));
0139 }
0140
0141 CondT cond; ThenT then;
0142 };
0143
0144
0145 template <typename CondT, typename ThenT>
0146 struct if_then_composite {
0147
0148 typedef if_then_composite<CondT, ThenT> self_t;
0149
0150 template <typename TupleT>
0151 struct result { typedef void type; };
0152
0153 if_then_composite(CondT const& cond_, ThenT const& then_)
0154 : cond(cond_), then(then_), else_(cond, then) {}
0155
0156 template <typename TupleT>
0157 void eval(TupleT const& args) const
0158 {
0159 if (cond.eval(args))
0160 then.eval(args);
0161 }
0162
0163 CondT cond; ThenT then;
0164 else_gen<CondT, ThenT> else_;
0165 };
0166
0167
0168 template <typename CondT>
0169 struct if_gen {
0170
0171 if_gen(CondT const& cond_)
0172 : cond(cond_) {}
0173
0174 template <typename ThenT>
0175 actor<if_then_composite<
0176 typename as_actor<CondT>::type,
0177 typename as_actor<ThenT>::type> >
0178 operator[](ThenT const& then) const
0179 {
0180 typedef if_then_composite<
0181 typename as_actor<CondT>::type,
0182 typename as_actor<ThenT>::type>
0183 result;
0184
0185 return result(
0186 as_actor<CondT>::convert(cond),
0187 as_actor<ThenT>::convert(then));
0188 }
0189
0190 CondT cond;
0191 };
0192
0193
0194 template <typename CondT>
0195 inline if_gen<CondT>
0196 if_(CondT const& cond)
0197 {
0198 return if_gen<CondT>(cond);
0199 }
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217 template <typename CondT, typename DoT>
0218 struct while_composite {
0219
0220 typedef while_composite<CondT, DoT> self_t;
0221
0222 template <typename TupleT>
0223 struct result { typedef void type; };
0224
0225 while_composite(CondT const& cond_, DoT const& do__)
0226 : cond(cond_), do_(do__) {}
0227
0228 template <typename TupleT>
0229 void eval(TupleT const& args) const
0230 {
0231 while (cond.eval(args))
0232 do_.eval(args);
0233 }
0234
0235 CondT cond;
0236 DoT do_;
0237 };
0238
0239
0240 template <typename CondT>
0241 struct while_gen {
0242
0243 while_gen(CondT const& cond_)
0244 : cond(cond_) {}
0245
0246 template <typename DoT>
0247 actor<while_composite<
0248 typename as_actor<CondT>::type,
0249 typename as_actor<DoT>::type> >
0250 operator[](DoT const& do_) const
0251 {
0252 typedef while_composite<
0253 typename as_actor<CondT>::type,
0254 typename as_actor<DoT>::type>
0255 result;
0256
0257 return result(
0258 as_actor<CondT>::convert(cond),
0259 as_actor<DoT>::convert(do_));
0260 }
0261
0262 CondT cond;
0263 };
0264
0265
0266 template <typename CondT>
0267 inline while_gen<CondT>
0268 while_(CondT const& cond)
0269 {
0270 return while_gen<CondT>(cond);
0271 }
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292 template <typename DoT, typename CondT>
0293 struct do_composite {
0294
0295 typedef do_composite<DoT, CondT> self_t;
0296
0297 template <typename TupleT>
0298 struct result { typedef void type; };
0299
0300 do_composite(DoT const& do__, CondT const& cond_)
0301 : do_(do__), cond(cond_) {}
0302
0303 template <typename TupleT>
0304 void eval(TupleT const& args) const
0305 {
0306 do
0307 do_.eval(args);
0308 while (cond.eval(args));
0309 }
0310
0311 DoT do_;
0312 CondT cond;
0313 };
0314
0315
0316 template <typename DoT>
0317 struct do_gen2 {
0318
0319 do_gen2(DoT const& do__)
0320 : do_(do__) {}
0321
0322 template <typename CondT>
0323 actor<do_composite<
0324 typename as_actor<DoT>::type,
0325 typename as_actor<CondT>::type> >
0326 while_(CondT const& cond) const
0327 {
0328 typedef do_composite<
0329 typename as_actor<DoT>::type,
0330 typename as_actor<CondT>::type>
0331 result;
0332
0333 return result(
0334 as_actor<DoT>::convert(do_),
0335 as_actor<CondT>::convert(cond));
0336 }
0337
0338 DoT do_;
0339 };
0340
0341
0342 struct do_gen {
0343
0344 template <typename DoT>
0345 do_gen2<DoT>
0346 operator[](DoT const& do_) const
0347 {
0348 return do_gen2<DoT>(do_);
0349 }
0350 };
0351
0352 do_gen const do_ = do_gen();
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372 template <typename InitT, typename CondT, typename StepT, typename DoT>
0373 struct for_composite {
0374
0375 typedef composite<InitT, CondT, StepT, DoT> self_t;
0376
0377 template <typename TupleT>
0378 struct result { typedef void type; };
0379
0380 for_composite(
0381 InitT const& init_,
0382 CondT const& cond_,
0383 StepT const& step_,
0384 DoT const& do__)
0385 : init(init_), cond(cond_), step(step_), do_(do__) {}
0386
0387 template <typename TupleT>
0388 void
0389 eval(TupleT const& args) const
0390 {
0391 for (init.eval(args); cond.eval(args); step.eval(args))
0392 do_.eval(args);
0393 }
0394
0395 InitT init; CondT cond; StepT step; DoT do_;
0396 };
0397
0398
0399 template <typename InitT, typename CondT, typename StepT>
0400 struct for_gen {
0401
0402 for_gen(
0403 InitT const& init_,
0404 CondT const& cond_,
0405 StepT const& step_)
0406 : init(init_), cond(cond_), step(step_) {}
0407
0408 template <typename DoT>
0409 actor<for_composite<
0410 typename as_actor<InitT>::type,
0411 typename as_actor<CondT>::type,
0412 typename as_actor<StepT>::type,
0413 typename as_actor<DoT>::type> >
0414 operator[](DoT const& do_) const
0415 {
0416 typedef for_composite<
0417 typename as_actor<InitT>::type,
0418 typename as_actor<CondT>::type,
0419 typename as_actor<StepT>::type,
0420 typename as_actor<DoT>::type>
0421 result;
0422
0423 return result(
0424 as_actor<InitT>::convert(init),
0425 as_actor<CondT>::convert(cond),
0426 as_actor<StepT>::convert(step),
0427 as_actor<DoT>::convert(do_));
0428 }
0429
0430 InitT init; CondT cond; StepT step;
0431 };
0432
0433
0434 template <typename InitT, typename CondT, typename StepT>
0435 inline for_gen<InitT, CondT, StepT>
0436 for_(InitT const& init, CondT const& cond, StepT const& step)
0437 {
0438 return for_gen<InitT, CondT, StepT>(init, cond, step);
0439 }
0440
0441 }
0442
0443 #endif