1 #include "ProtectorChain.h"
6 class ProtectorChain::ProtectFunctor : public Functor
9 ProtectFunctor( Protector *protector,
10 const Functor &functor,
11 const ProtectorContext &context )
12 : m_protector( protector )
13 , m_functor( functor )
14 , m_context( context )
18 bool operator()() const
20 return m_protector->protect( m_functor, m_context );
24 Protector *m_protector;
25 const Functor &m_functor;
26 const ProtectorContext &m_context;
30 ProtectorChain::~ProtectorChain()
38 ProtectorChain::push( Protector *protector )
40 m_protectors.push_back( protector );
47 delete m_protectors.back();
48 m_protectors.pop_back();
52 ProtectorChain::count() const
54 return m_protectors.size();
59 ProtectorChain::protect( const Functor &functor,
60 const ProtectorContext &context )
62 if ( m_protectors.empty() )
66 for ( int index = m_protectors.size()-1; index >= 0; --index )
68 const Functor &protectedFunctor =
69 functors.empty() ? functor : *functors.back();
71 functors.push_back( new ProtectFunctor( m_protectors[index],
76 const Functor &outermostFunctor = *functors.back();
77 bool succeed = outermostFunctor();
79 for ( unsigned int deletingIndex = 0; deletingIndex < m_protectors.size(); ++deletingIndex )
80 delete functors[deletingIndex];