summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-01 08:48:42 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-01 09:24:28 (GMT)
commit2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch)
treed46294f35150c4f0f43deaf2d31fceaf945ae715 /3rdParty/CppUnit/src/ProtectorChain.cpp
downloadswift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip
swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2
Import.
Diffstat (limited to '3rdParty/CppUnit/src/ProtectorChain.cpp')
-rw-r--r--3rdParty/CppUnit/src/ProtectorChain.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/3rdParty/CppUnit/src/ProtectorChain.cpp b/3rdParty/CppUnit/src/ProtectorChain.cpp
new file mode 100644
index 0000000..f528341
--- /dev/null
+++ b/3rdParty/CppUnit/src/ProtectorChain.cpp
@@ -0,0 +1,86 @@
+#include "ProtectorChain.h"
+
+CPPUNIT_NS_BEGIN
+
+
+class ProtectorChain::ProtectFunctor : public Functor
+{
+public:
+ ProtectFunctor( Protector *protector,
+ const Functor &functor,
+ const ProtectorContext &context )
+ : m_protector( protector )
+ , m_functor( functor )
+ , m_context( context )
+ {
+ }
+
+ bool operator()() const
+ {
+ return m_protector->protect( m_functor, m_context );
+ }
+
+private:
+ Protector *m_protector;
+ const Functor &m_functor;
+ const ProtectorContext &m_context;
+};
+
+
+ProtectorChain::~ProtectorChain()
+{
+ while ( count() > 0 )
+ pop();
+}
+
+
+void
+ProtectorChain::push( Protector *protector )
+{
+ m_protectors.push_back( protector );
+}
+
+
+void
+ProtectorChain::pop()
+{
+ delete m_protectors.back();
+ m_protectors.pop_back();
+}
+
+int
+ProtectorChain::count() const
+{
+ return m_protectors.size();
+}
+
+
+bool
+ProtectorChain::protect( const Functor &functor,
+ const ProtectorContext &context )
+{
+ if ( m_protectors.empty() )
+ return functor();
+
+ Functors functors;
+ for ( int index = m_protectors.size()-1; index >= 0; --index )
+ {
+ const Functor &protectedFunctor =
+ functors.empty() ? functor : *functors.back();
+
+ functors.push_back( new ProtectFunctor( m_protectors[index],
+ protectedFunctor,
+ context ) );
+ }
+
+ const Functor &outermostFunctor = *functors.back();
+ bool succeed = outermostFunctor();
+
+ for ( unsigned int deletingIndex = 0; deletingIndex < m_protectors.size(); ++deletingIndex )
+ delete functors[deletingIndex];
+
+ return succeed;
+}
+
+
+CPPUNIT_NS_END