PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/src/contrib/boost/statechart/detail/constructor.hpp

http://pythonocc.googlecode.com/
C++ Header | 139 lines | 103 code | 26 blank | 10 comment | 0 complexity | 685e2a4a01141292b379f3423c5c6a8d MD5 | raw file
  1#ifndef BOOST_STATECHART_DETAIL_CONSTRUCTOR_HPP_INCLUDED
  2#define BOOST_STATECHART_DETAIL_CONSTRUCTOR_HPP_INCLUDED
  3//////////////////////////////////////////////////////////////////////////////
  4// Copyright 2002-2006 Andreas Huber Doenni
  5// Distributed under the Boost Software License, Version 1.0. (See accompany-
  6// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7//////////////////////////////////////////////////////////////////////////////
  8
  9
 10
 11#include <boost/mpl/eval_if.hpp>
 12#include <boost/mpl/identity.hpp>
 13#include <boost/mpl/equal_to.hpp>
 14#include <boost/mpl/size.hpp>
 15#include <boost/mpl/front.hpp>
 16#include <boost/mpl/advance.hpp>
 17#include <boost/mpl/find.hpp>
 18#include <boost/mpl/push_front.hpp>
 19#include <boost/mpl/pop_front.hpp>
 20#include <boost/mpl/erase.hpp>
 21#include <boost/mpl/reverse.hpp>
 22#include <boost/mpl/long.hpp>
 23
 24
 25
 26namespace boost
 27{
 28namespace statechart
 29{
 30namespace detail
 31{
 32
 33
 34
 35template< class ContextList, class OutermostContextBase >
 36struct constructor;
 37
 38//////////////////////////////////////////////////////////////////////////////
 39template< class ContextList, class OutermostContextBase >
 40struct outer_constructor
 41{
 42  typedef typename mpl::front< ContextList >::type to_construct;
 43  typedef typename to_construct::context_ptr_type context_ptr_type;
 44  typedef typename to_construct::inner_context_ptr_type
 45    inner_context_ptr_type;
 46
 47  typedef typename to_construct::inner_initial_list inner_initial_list;
 48  typedef typename mpl::pop_front< ContextList >::type inner_context_list;
 49  typedef typename mpl::front< inner_context_list >::type::orthogonal_position
 50    inner_orthogonal_position;
 51  typedef typename mpl::advance<
 52    typename mpl::begin< inner_initial_list >::type,
 53    inner_orthogonal_position >::type to_construct_iter;
 54
 55  typedef typename mpl::erase<
 56    inner_initial_list,
 57    to_construct_iter,
 58    typename mpl::end< inner_initial_list >::type
 59  >::type first_inner_initial_list;
 60
 61  typedef typename mpl::erase<
 62    inner_initial_list,
 63    typename mpl::begin< inner_initial_list >::type,
 64    typename mpl::next< to_construct_iter >::type
 65  >::type last_inner_initial_list;
 66
 67  static void construct(
 68    const context_ptr_type & pContext,
 69    OutermostContextBase & outermostContextBase )
 70  {
 71    const inner_context_ptr_type pInnerContext =
 72      to_construct::shallow_construct( pContext, outermostContextBase );
 73    to_construct::template deep_construct_inner<
 74      first_inner_initial_list >( pInnerContext, outermostContextBase );
 75    constructor< inner_context_list, OutermostContextBase >::construct(
 76      pInnerContext, outermostContextBase );
 77    to_construct::template deep_construct_inner<
 78      last_inner_initial_list >( pInnerContext, outermostContextBase );
 79  }
 80};
 81
 82//////////////////////////////////////////////////////////////////////////////
 83template< class ContextList, class OutermostContextBase >
 84struct inner_constructor
 85{
 86  typedef typename mpl::front< ContextList >::type to_construct;
 87  typedef typename to_construct::context_ptr_type context_ptr_type;
 88
 89  static void construct(
 90    const context_ptr_type & pContext,
 91    OutermostContextBase & outermostContextBase )
 92  {
 93    to_construct::deep_construct( pContext, outermostContextBase );
 94  }
 95};
 96
 97//////////////////////////////////////////////////////////////////////////////
 98template< class ContextList, class OutermostContextBase >
 99struct constructor_impl : public mpl::eval_if<
100  mpl::equal_to< mpl::size< ContextList >, mpl::long_< 1 > >,
101  mpl::identity< inner_constructor< ContextList, OutermostContextBase > >,
102  mpl::identity< outer_constructor< ContextList, OutermostContextBase > > >
103{
104};
105
106
107//////////////////////////////////////////////////////////////////////////////
108template< class ContextList, class OutermostContextBase >
109struct constructor :
110  constructor_impl< ContextList, OutermostContextBase >::type {};
111
112//////////////////////////////////////////////////////////////////////////////
113template< class CommonContext, class DestinationState >
114struct make_context_list
115{
116  typedef typename mpl::reverse< typename mpl::push_front<
117    typename mpl::erase<
118      typename DestinationState::context_type_list,
119      typename mpl::find<
120        typename DestinationState::context_type_list,
121        CommonContext
122      >::type,
123      typename mpl::end<
124        typename DestinationState::context_type_list
125      >::type
126    >::type,
127    DestinationState
128  >::type >::type type;
129};
130
131
132
133} // namespace detail
134} // namespace statechart
135} // namespace boost
136
137
138
139#endif