diff --git a/src/libraries/turtle/function.hpp b/src/libraries/turtle/function.hpp index de6431f..c2177e0 100644 --- a/src/libraries/turtle/function.hpp +++ b/src/libraries/turtle/function.hpp @@ -120,7 +120,7 @@ namespace mock public: function_impl() : name_( "?" ) - , parent_( &root ) + , parent_( &root() ) , valid_( true ) { parent_->add( *this ); diff --git a/src/libraries/turtle/node.hpp b/src/libraries/turtle/node.hpp index 593bfbe..cdc099b 100644 --- a/src/libraries/turtle/node.hpp +++ b/src/libraries/turtle/node.hpp @@ -20,6 +20,21 @@ namespace mock class node : protected verifiable { public: + virtual ~node() + { + std::for_each( v_.begin(), v_.end(), + std::mem_fun( &verifiable::untie ) ); + } + + void tag( const std::string& name ) + { + name_ = name; + } + const std::string& tag() const + { + return name_; + } + void add( verifiable& e ) { v_.push_back( &e ); @@ -42,24 +57,10 @@ namespace mock std::for_each( v_.begin(), v_.end(), std::mem_fun( &verifiable::reset ) ); } - virtual void untie() - {} - - void tag( const std::string& name ) - { - name_ = name; - } - const std::string& tag() const - { - return name_; - } protected: - virtual ~node() - { - std::for_each( v_.begin(), v_.end(), - std::mem_fun( &verifiable::untie ) ); - } + virtual void untie() + {} private: typedef std::vector< verifiable* > verifiables_type; diff --git a/src/libraries/turtle/object.hpp b/src/libraries/turtle/object.hpp index e566c5b..872890f 100644 --- a/src/libraries/turtle/object.hpp +++ b/src/libraries/turtle/object.hpp @@ -49,11 +49,11 @@ namespace mock public: object_impl() { - root.add( *this ); + root().add( *this ); } virtual ~object_impl() { - root.remove( *this ); + root().remove( *this ); } }; diff --git a/src/libraries/turtle/root.hpp b/src/libraries/turtle/root.hpp index 1b581f6..ba692d2 100644 --- a/src/libraries/turtle/root.hpp +++ b/src/libraries/turtle/root.hpp @@ -11,24 +11,22 @@ #include "config.hpp" #include "node.hpp" -#include namespace mock { - class root_t : public boost::unit_test::singleton< root_t >, public node + inline node& root() { - private: - BOOST_TEST_SINGLETON_CONS( root_t ); - }; - BOOST_TEST_SINGLETON_INST( root ) + static node r; + return r; + } inline bool verify() { - return root.verify(); + return root().verify(); } inline void reset() { - root.reset(); + root().reset(); } }