author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
#ifndef BOOST_STATECHART_EVENT_BASE_HPP_INCLUDED |
sl@0 | 2 |
#define BOOST_STATECHART_EVENT_BASE_HPP_INCLUDED |
sl@0 | 3 |
////////////////////////////////////////////////////////////////////////////// |
sl@0 | 4 |
// Copyright 2002-2006 Andreas Huber Doenni |
sl@0 | 5 |
// Distributed under the Boost Software License, Version 1.0. (See accompany- |
sl@0 | 6 |
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
sl@0 | 7 |
////////////////////////////////////////////////////////////////////////////// |
sl@0 | 8 |
|
sl@0 | 9 |
|
sl@0 | 10 |
|
sl@0 | 11 |
#include <boost/statechart/detail/rtti_policy.hpp> |
sl@0 | 12 |
#include <boost/statechart/detail/counted_base.hpp> |
sl@0 | 13 |
|
sl@0 | 14 |
#include <boost/assert.hpp> |
sl@0 | 15 |
#include <boost/intrusive_ptr.hpp> |
sl@0 | 16 |
#include <boost/config.hpp> |
sl@0 | 17 |
|
sl@0 | 18 |
|
sl@0 | 19 |
|
sl@0 | 20 |
namespace boost |
sl@0 | 21 |
{ |
sl@0 | 22 |
namespace statechart |
sl@0 | 23 |
{ |
sl@0 | 24 |
namespace detail |
sl@0 | 25 |
{ |
sl@0 | 26 |
|
sl@0 | 27 |
|
sl@0 | 28 |
|
sl@0 | 29 |
// This helper is necessary because there doesn't seem to be consensus among |
sl@0 | 30 |
// compilers on how a friend declaration for a function in another namespace |
sl@0 | 31 |
// has to look like. |
sl@0 | 32 |
class delete_helper |
sl@0 | 33 |
{ |
sl@0 | 34 |
public: |
sl@0 | 35 |
template< class T > |
sl@0 | 36 |
static void delete_object( const T * pObject ) |
sl@0 | 37 |
{ |
sl@0 | 38 |
delete pObject; |
sl@0 | 39 |
} |
sl@0 | 40 |
}; |
sl@0 | 41 |
|
sl@0 | 42 |
|
sl@0 | 43 |
|
sl@0 | 44 |
} // namespace detail |
sl@0 | 45 |
|
sl@0 | 46 |
|
sl@0 | 47 |
|
sl@0 | 48 |
////////////////////////////////////////////////////////////////////////////// |
sl@0 | 49 |
class event_base : public detail::rtti_policy::rtti_base_type< |
sl@0 | 50 |
detail::counted_base<> > |
sl@0 | 51 |
{ |
sl@0 | 52 |
typedef detail::rtti_policy::rtti_base_type< |
sl@0 | 53 |
detail::counted_base<> > base_type; |
sl@0 | 54 |
public: |
sl@0 | 55 |
////////////////////////////////////////////////////////////////////////// |
sl@0 | 56 |
intrusive_ptr< const event_base > intrusive_from_this() const; |
sl@0 | 57 |
|
sl@0 | 58 |
protected: |
sl@0 | 59 |
////////////////////////////////////////////////////////////////////////// |
sl@0 | 60 |
event_base( detail::rtti_policy::id_provider_type idProvider ) : |
sl@0 | 61 |
base_type( idProvider ) |
sl@0 | 62 |
{ |
sl@0 | 63 |
} |
sl@0 | 64 |
|
sl@0 | 65 |
virtual ~event_base() {} |
sl@0 | 66 |
|
sl@0 | 67 |
private: |
sl@0 | 68 |
////////////////////////////////////////////////////////////////////////// |
sl@0 | 69 |
virtual intrusive_ptr< const event_base > clone() const = 0; |
sl@0 | 70 |
|
sl@0 | 71 |
friend class detail::delete_helper; |
sl@0 | 72 |
}; |
sl@0 | 73 |
|
sl@0 | 74 |
|
sl@0 | 75 |
|
sl@0 | 76 |
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP |
sl@0 | 77 |
} // namespace statechart |
sl@0 | 78 |
#endif |
sl@0 | 79 |
|
sl@0 | 80 |
|
sl@0 | 81 |
|
sl@0 | 82 |
inline void intrusive_ptr_add_ref( const ::boost::statechart::event_base * pBase ) |
sl@0 | 83 |
{ |
sl@0 | 84 |
pBase->add_ref(); |
sl@0 | 85 |
} |
sl@0 | 86 |
|
sl@0 | 87 |
inline void intrusive_ptr_release( const ::boost::statechart::event_base * pBase ) |
sl@0 | 88 |
{ |
sl@0 | 89 |
if ( pBase->release() ) |
sl@0 | 90 |
{ |
sl@0 | 91 |
::boost::statechart::detail::delete_helper::delete_object( pBase ); |
sl@0 | 92 |
} |
sl@0 | 93 |
} |
sl@0 | 94 |
|
sl@0 | 95 |
|
sl@0 | 96 |
|
sl@0 | 97 |
#ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP |
sl@0 | 98 |
} // namespace statechart |
sl@0 | 99 |
#endif |
sl@0 | 100 |
namespace statechart |
sl@0 | 101 |
{ |
sl@0 | 102 |
|
sl@0 | 103 |
|
sl@0 | 104 |
|
sl@0 | 105 |
// We're implementing this here so that GCC3.4.2 can find |
sl@0 | 106 |
// intrusive_ptr_add_ref, which is indirectly called from the intrusive_ptr |
sl@0 | 107 |
// ctor. |
sl@0 | 108 |
inline intrusive_ptr< const event_base > event_base::intrusive_from_this() const |
sl@0 | 109 |
{ |
sl@0 | 110 |
if ( base_type::ref_counted() ) |
sl@0 | 111 |
{ |
sl@0 | 112 |
return intrusive_ptr< const event_base >( this ); |
sl@0 | 113 |
} |
sl@0 | 114 |
else |
sl@0 | 115 |
{ |
sl@0 | 116 |
return clone(); |
sl@0 | 117 |
} |
sl@0 | 118 |
} |
sl@0 | 119 |
|
sl@0 | 120 |
|
sl@0 | 121 |
|
sl@0 | 122 |
} // namespace statechart |
sl@0 | 123 |
} // namespace boost |
sl@0 | 124 |
|
sl@0 | 125 |
|
sl@0 | 126 |
|
sl@0 | 127 |
#endif |