PageRenderTime 90ms CodeModel.GetById 23ms app.highlight 62ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/classic/phoenix/actor.hpp

http://pythonocc.googlecode.com/
C++ Header | 604 lines | 400 code | 67 blank | 137 comment | 0 complexity | 5c67880485e1b62b260e615d46a181e7 MD5 | raw file
  1/*=============================================================================
  2    Phoenix v1.2
  3    Copyright (c) 2001-2002 Joel de Guzman
  4
  5  Distributed under the Boost Software License, Version 1.0. (See accompanying
  6  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7==============================================================================*/
  8#ifndef PHOENIX_ACTOR_HPP
  9#define PHOENIX_ACTOR_HPP
 10
 11///////////////////////////////////////////////////////////////////////////////
 12#include <boost/spirit/home/classic/phoenix/tuples.hpp>
 13
 14///////////////////////////////////////////////////////////////////////////////
 15namespace phoenix {
 16
 17//  These are forward declared here because we cannot include impl.hpp
 18//  or operators.hpp yet but the actor's assignment operator and index
 19//  operator are required to be members.
 20
 21//////////////////////////////////
 22struct assign_op;
 23struct index_op;
 24
 25//////////////////////////////////
 26namespace impl {
 27
 28    template <typename OperationT, typename BaseT, typename B>
 29    struct make_binary1;
 30}
 31
 32///////////////////////////////////////////////////////////////////////////////
 33//
 34//  unpack_tuple class
 35//
 36//      This class is used to unpack a supplied tuple such, that the members of 
 37//      this tuple will be handled as if they would be supplied separately.
 38//
 39///////////////////////////////////////////////////////////////////////////////
 40template <typename TupleT>
 41struct unpack_tuple : public TupleT {
 42
 43    typedef TupleT tuple_t;
 44    
 45    unpack_tuple() {}
 46    unpack_tuple(tuple_t const &tuple_) : TupleT(tuple_) {}
 47};
 48
 49///////////////////////////////////////////////////////////////////////////////
 50//
 51//  actor class
 52//
 53//      This class is a protocol class for all actors. This class is
 54//      essentially an interface contract. The actor class does not
 55//      really know how how to act on anything but instead relies on the
 56//      template parameter BaseT (from which the actor will derive from)
 57//      to do the actual action.
 58//
 59//      An actor is a functor that is capable of accepting arguments up
 60//      to a predefined maximum. It is up to the base class to do the
 61//      actual processing or possibly to limit the arity (no. of
 62//      arguments) passed in. Upon invocation of the functor through a
 63//      supplied operator(), the actor funnels the arguments passed in
 64//      by the client into a tuple and calls the base eval member
 65//      function.
 66//
 67//      Schematically:
 68//
 69//          arg0 ---------|
 70//          arg1 ---------|
 71//          arg2 ---------|---> tupled_args ---> base.eval
 72//          ...           |
 73//          argN ---------|
 74//
 75//          actor::operator()(arg0, arg1... argN)
 76//              ---> BaseT::eval(tupled_args);
 77//
 78//      Actor base classes from which this class inherits from are
 79//      expected to have a corresponding member function eval compatible
 80//      with the conceptual Interface:
 81//
 82//          template <typename TupleT>
 83//          actor_return_type
 84//          eval(TupleT const& args) const;
 85//
 86//      where args are the actual arguments passed in by the client
 87//      funneled into a tuple (see tuple.hpp for details).
 88//
 89//      The actor_return_type can be anything. Base classes are free to
 90//      return any type, even argument dependent types (types that are
 91//      deduced from the types of the arguments). After evaluating the
 92//      parameters and doing some computations or actions, the eval
 93//      member function concludes by returning something back to the
 94//      client. To do this, the forwarding function (the actor's
 95//      operator()) needs to know the return type of the eval member
 96//      function that it is calling. For this purpose, actor base
 97//      classes are required to provide a nested template class:
 98//
 99//          template <typename TupleT>
100//          struct result;
101//
102//      This auxiliary class provides the result type information
103//      returned by the eval member function of a base actor class. The
104//      nested template class result should have a typedef 'type' that
105//      reflects the return type of its member function eval. It is
106//      basically a type computer that answers the question "given
107//      arguments packed into a TupleT type, what will be the result
108//      type of the eval member function of ActorT?". The template class
109//      actor_result queries this to extract the return type of an
110//      actor. Example:
111//
112//          typedef typename actor_result<ActorT, TupleT>::type
113//              actor_return_type;
114//
115//      where actor_return_type is the actual type returned by ActorT's
116//      eval member function given some arguments in a TupleT.
117//
118///////////////////////////////////////////////////////////////////////////////
119template <typename ActorT, typename TupleT>
120struct actor_result {
121
122    typedef typename ActorT::template result<TupleT>::type type;
123    typedef typename remove_reference<type>::type plain_type;
124};
125
126//////////////////////////////////
127#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
128#pragma warning(push)
129#pragma warning(disable:4512) //assignment operator could not be generated
130#endif
131
132template <typename BaseT>
133struct actor : public BaseT {
134
135    actor();
136    actor(BaseT const& base);
137
138    typename actor_result<BaseT, tuple<> >::type
139    operator()() const;
140
141    template <typename A>
142    typename actor_result<BaseT, tuple<A&> >::type
143    operator()(A& a) const;
144
145    template <typename A, typename B>
146    typename actor_result<BaseT, tuple<A&, B&> >::type
147    operator()(A& a, B& b) const;
148
149    template <typename A, typename B, typename C>
150    typename actor_result<BaseT, tuple<A&, B&, C&> >::type
151    operator()(A& a, B& b, C& c) const;
152
153#if PHOENIX_LIMIT > 3
154    template <typename A, typename B, typename C, typename D>
155    typename actor_result<BaseT, tuple<A&, B&, C&, D&> >::type
156    operator()(A& a, B& b, C& c, D& d) const;
157
158    template <typename A, typename B, typename C, typename D, typename E>
159    typename actor_result<BaseT, tuple<A&, B&, C&, D&, E&> >::type
160    operator()(A& a, B& b, C& c, D& d, E& e) const;
161
162    template <
163        typename A, typename B, typename C, typename D, typename E,
164        typename F>
165    typename actor_result<BaseT, tuple<A&, B&, C&, D&, E&, F&> >::type
166    operator()(A& a, B& b, C& c, D& d, E& e, F& f) const;
167
168#if PHOENIX_LIMIT > 6
169
170    template <
171        typename A, typename B, typename C, typename D, typename E,
172        typename F, typename G>
173    typename actor_result<BaseT, tuple<A&, B&, C&, D&, E&, F&, G&> >::type
174    operator()(A& a, B& b, C& c, D& d, E& e, F& f, G& g) const;
175
176    template <
177        typename A, typename B, typename C, typename D, typename E,
178        typename F, typename G, typename H>
179    typename actor_result<BaseT,
180        tuple<A&, B&, C&, D&, E&, F&, G&, H&>
181    >::type
182    operator()(A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h) const;
183
184    template <
185        typename A, typename B, typename C, typename D, typename E,
186        typename F, typename G, typename H, typename I>
187    typename actor_result<BaseT,
188        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&>
189    >::type
190    operator()(A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h, I& i) const;
191
192#if PHOENIX_LIMIT > 9
193
194    template <
195        typename A, typename B, typename C, typename D, typename E,
196        typename F, typename G, typename H, typename I, typename J>
197    typename actor_result<BaseT,
198        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&>
199    >::type
200    operator()(
201        A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h, I& i, J& j) const;
202
203    template <
204        typename A, typename B, typename C, typename D, typename E,
205        typename F, typename G, typename H, typename I, typename J,
206        typename K>
207    typename actor_result<BaseT,
208        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&>
209    >::type
210    operator()(
211        A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h, I& i, J& j,
212        K& k) const;
213
214    template <
215        typename A, typename B, typename C, typename D, typename E,
216        typename F, typename G, typename H, typename I, typename J,
217        typename K, typename L>
218    typename actor_result<BaseT,
219        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&>
220    >::type
221    operator()(
222        A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h, I& i, J& j,
223        K& k, L& l) const;
224
225#if PHOENIX_LIMIT > 12
226
227    template <
228        typename A, typename B, typename C, typename D, typename E,
229        typename F, typename G, typename H, typename I, typename J,
230        typename K, typename L, typename M>
231    typename actor_result<BaseT,
232        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&>
233    >::type
234    operator()(
235        A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h, I& i, J& j,
236        K& k, L& l, M& m) const;
237
238    template <
239        typename A, typename B, typename C, typename D, typename E,
240        typename F, typename G, typename H, typename I, typename J,
241        typename K, typename L, typename M, typename N>
242    typename actor_result<BaseT,
243        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&, N&>
244    >::type
245    operator()(
246        A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h, I& i, J& j,
247        K& k, L& l, M& m, N& n) const;
248
249    template <
250        typename A, typename B, typename C, typename D, typename E,
251        typename F, typename G, typename H, typename I, typename J,
252        typename K, typename L, typename M, typename N, typename O>
253    typename actor_result<BaseT,
254        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&, N&, O&>
255    >::type
256    operator()(
257        A& a, B& b, C& c, D& d, E& e, F& f, G& g, H& h, I& i, J& j,
258        K& k, L& l, M& m, N& n, O& o) const;
259
260#endif
261#endif
262#endif
263#endif
264
265    template <typename TupleT>
266    typename actor_result<BaseT, unpack_tuple<TupleT> >::type
267    operator()(unpack_tuple<TupleT> const &t) const;
268    
269    template <typename B>
270    typename impl::make_binary1<assign_op, BaseT, B>::type
271    operator=(B const& b) const;
272
273    template <typename B>
274    typename impl::make_binary1<index_op, BaseT, B>::type
275    operator[](B const& b) const;
276};
277
278#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
279#pragma warning(pop)
280#endif
281
282///////////////////////////////////////////////////////////////////////////
283//
284//  as_actor
285//
286//      as_actor is a meta-program that converts an arbitrary type into
287//      an actor. All participants in the framework must be first-class
288//      actors. This meta-program is used all throughout the framework
289//      whenever an unknown type needs to be converted to an actor.
290//      as_actor specializations are expected to have a typedef 'type'.
291//      This is the destination actor type. A static member function
292//      'convert' converts an object to this target type.
293//
294//      The meta-program does no conversion if the object to be
295//      converted is already an actor.
296//
297///////////////////////////////////////////////////////////////////////////
298template <typename T>
299struct as_actor;
300
301//////////////////////////////////
302template <typename BaseT>
303struct as_actor<actor<BaseT> > {
304
305    typedef actor<BaseT> type;
306    static type convert(actor<BaseT> const& x) { return x; }
307};
308
309//////////////////////////////////
310template <>
311struct as_actor<nil_t> {
312
313    typedef nil_t type;
314    static nil_t convert(nil_t /*x*/)
315    { return nil_t(); }
316};
317
318//////////////////////////////////
319template <>
320struct as_actor<void> {
321
322    typedef void type;
323    //  ERROR!!!
324};
325
326///////////////////////////////////////////////////////////////////////////////
327//
328//  actor class implementation
329//
330///////////////////////////////////////////////////////////////////////////////
331template <typename BaseT>
332actor<BaseT>::actor()
333:   BaseT() {}
334
335//////////////////////////////////
336template <typename BaseT>
337actor<BaseT>::actor(BaseT const& base)
338:   BaseT(base) {}
339
340//////////////////////////////////
341template <typename BaseT>
342inline typename actor_result<BaseT, tuple<> >::type
343actor<BaseT>::operator()() const
344{
345    return BaseT::eval(tuple<>());
346}
347
348//////////////////////////////////
349template <typename BaseT>
350template <typename A>
351inline typename actor_result<BaseT, tuple<A&> >::type
352actor<BaseT>::operator()(A& a_) const
353{
354    return BaseT::eval(tuple<A&>(a_));
355}
356
357//////////////////////////////////
358template <typename BaseT>
359template <typename A, typename B>
360inline typename actor_result<BaseT, tuple<A&, B&> >::type
361actor<BaseT>::operator()(A& a_, B& b_) const
362{
363    return BaseT::eval(tuple<A&, B&>(a_, b_));
364}
365
366//////////////////////////////////
367template <typename BaseT>
368template <typename A, typename B, typename C>
369inline typename actor_result<BaseT, tuple<A&, B&, C&> >::type
370actor<BaseT>::operator()(A& a_, B& b_, C& c_) const
371{
372    return BaseT::eval(tuple<A&, B&, C&>(a_, b_, c_));
373}
374
375#if PHOENIX_LIMIT > 3
376//////////////////////////////////
377template <typename BaseT>
378template <typename A, typename B, typename C, typename D>
379inline typename actor_result<BaseT, tuple<A&, B&, C&, D&> >::type
380actor<BaseT>::operator()(A& a_, B& b_, C& c_, D& d_) const
381{
382    return BaseT::eval(tuple<A&, B&, C&, D&>(a_, b_, c_, d_));
383}
384
385//////////////////////////////////
386template <typename BaseT>
387template <typename A, typename B, typename C, typename D, typename E>
388inline typename actor_result<BaseT, tuple<A&, B&, C&, D&, E&> >::type
389actor<BaseT>::operator()(A& a_, B& b_, C& c_, D& d_, E& e_) const
390{
391    return BaseT::eval(tuple<A&, B&, C&, D&, E&>(a_, b_, c_, d_, e_));
392}
393
394//////////////////////////////////
395template <typename BaseT>
396template <
397    typename A, typename B, typename C, typename D, typename E,
398    typename F>
399inline typename actor_result<BaseT,
400    tuple<A&, B&, C&, D&, E&, F&>
401>::type
402actor<BaseT>::operator()(
403    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_
404) const
405{
406    return BaseT::eval(
407        tuple<A&, B&, C&, D&, E&, F&>
408        (a_, b_, c_, d_, e_, f_)
409    );
410}
411
412#if PHOENIX_LIMIT > 6
413//////////////////////////////////
414template <typename BaseT>
415template <
416    typename A, typename B, typename C, typename D, typename E,
417    typename F, typename G>
418inline typename actor_result<BaseT,
419    tuple<A&, B&, C&, D&, E&, F&, G&>
420>::type
421actor<BaseT>::operator()(
422    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_
423) const
424{
425    return BaseT::eval(
426        tuple<A&, B&, C&, D&, E&, F&, G&>
427        (a_, b_, c_, d_, e_, f_, g_)
428    );
429}
430
431//////////////////////////////////
432template <typename BaseT>
433template <
434    typename A, typename B, typename C, typename D, typename E,
435    typename F, typename G, typename H>
436inline typename actor_result<BaseT,
437    tuple<A&, B&, C&, D&, E&, F&, G&, H&>
438>::type
439actor<BaseT>::operator()(
440    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_
441) const
442{
443    return BaseT::eval(
444        tuple<A&, B&, C&, D&, E&, F&, G&, H&>
445        (a_, b_, c_, d_, e_, f_, g_, h_)
446    );
447}
448
449//////////////////////////////////
450template <typename BaseT>
451template <
452    typename A, typename B, typename C, typename D, typename E,
453    typename F, typename G, typename H, typename I>
454inline typename actor_result<BaseT,
455    tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&>
456>::type
457actor<BaseT>::operator()(
458    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_, I& i_
459) const
460{
461    return BaseT::eval(
462        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&>
463        (a_, b_, c_, d_, e_, f_, g_, h_, i_)
464    );
465}
466
467#if PHOENIX_LIMIT > 9
468//////////////////////////////////
469template <typename BaseT>
470template <
471    typename A, typename B, typename C, typename D, typename E,
472    typename F, typename G, typename H, typename I, typename J>
473inline typename actor_result<BaseT,
474    tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&>
475>::type
476actor<BaseT>::operator()(
477    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_, I& i_, J& j_
478) const
479{
480    return BaseT::eval(
481        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&>
482        (a_, b_, c_, d_, e_, f_, g_, h_, i_, j_)
483    );
484}
485
486//////////////////////////////////
487template <typename BaseT>
488template <
489    typename A, typename B, typename C, typename D, typename E,
490    typename F, typename G, typename H, typename I, typename J,
491    typename K>
492inline typename actor_result<BaseT,
493    tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&>
494>::type
495actor<BaseT>::operator()(
496    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_, I& i_, J& j_,
497    K& k_
498) const
499{
500    return BaseT::eval(
501        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&>
502        (a_, b_, c_, d_, e_, f_, g_, h_, i_, j_, k_)
503    );
504}
505
506//////////////////////////////////
507template <typename BaseT>
508template <
509    typename A, typename B, typename C, typename D, typename E,
510    typename F, typename G, typename H, typename I, typename J,
511    typename K, typename L>
512inline typename actor_result<BaseT,
513    tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&>
514>::type
515actor<BaseT>::operator()(
516    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_, I& i_, J& j_,
517    K& k_, L& l_
518) const
519{
520    return BaseT::eval(
521        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&>
522        (a_, b_, c_, d_, e_, f_, g_, h_, i_, j_, k_, l_)
523    );
524}
525
526#if PHOENIX_LIMIT > 12
527//////////////////////////////////
528template <typename BaseT>
529template <
530    typename A, typename B, typename C, typename D, typename E,
531    typename F, typename G, typename H, typename I, typename J,
532    typename K, typename L, typename M>
533inline typename actor_result<BaseT,
534    tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&>
535>::type
536actor<BaseT>::operator()(
537    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_, I& i_, J& j_,
538    K& k_, L& l_, M& m_
539) const
540{
541    return BaseT::eval(
542        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&>
543        (a_, b_, c_, d_, e_, f_, g_, h_, i_, j_, k_, l_, m_)
544    );
545}
546
547//////////////////////////////////
548template <typename BaseT>
549template <
550    typename A, typename B, typename C, typename D, typename E,
551    typename F, typename G, typename H, typename I, typename J,
552    typename K, typename L, typename M, typename N>
553inline typename actor_result<BaseT,
554    tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&, N&>
555>::type
556actor<BaseT>::operator()(
557    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_, I& i_, J& j_,
558    K& k_, L& l_, M& m_, N& n_
559) const
560{
561    return BaseT::eval(
562        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&, N&>
563        (a_, b_, c_, d_, e_, f_, g_, h_, i_, j_, k_, l_, m_, n_)
564    );
565}
566
567//////////////////////////////////
568template <typename BaseT>
569template <
570    typename A, typename B, typename C, typename D, typename E,
571    typename F, typename G, typename H, typename I, typename J,
572    typename K, typename L, typename M, typename N, typename O>
573inline typename actor_result<BaseT,
574    tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&, N&, O&>
575>::type
576actor<BaseT>::operator()(
577    A& a_, B& b_, C& c_, D& d_, E& e_, F& f_, G& g_, H& h_, I& i_, J& j_,
578    K& k_, L& l_, M& m_, N& n_, O& o_
579) const
580{
581    return BaseT::eval(
582        tuple<A&, B&, C&, D&, E&, F&, G&, H&, I&, J&, K&, L&, M&, N&, O&>
583        (a_, b_, c_, d_, e_, f_, g_, h_, i_, j_, k_, l_, m_, n_, o_)
584    );
585}
586
587#endif
588#endif
589#endif
590#endif
591
592//////////////////////////////////
593template <typename BaseT>
594template <typename TupleT>
595typename actor_result<BaseT, unpack_tuple<TupleT> >::type
596actor<BaseT>::operator()(unpack_tuple<TupleT> const &t) const
597{
598    return BaseT::eval(t);
599}
600
601///////////////////////////////////////////////////////////////////////////////
602}   //  namespace phoenix
603
604#endif