sl@0: //----------------------------------------------------------------------------- sl@0: // boost variant/recursive_wrapper.hpp header file sl@0: // See http://www.boost.org for updates, documentation, and revision history. sl@0: //----------------------------------------------------------------------------- sl@0: // sl@0: // Copyright (c) 2002-2003 sl@0: // Eric Friedman, Itay Maman sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_HPP sl@0: #define BOOST_VARIANT_RECURSIVE_WRAPPER_HPP sl@0: sl@0: #include "boost/variant/recursive_wrapper_fwd.hpp" sl@0: #include "boost/checked_delete.hpp" sl@0: sl@0: namespace boost { sl@0: sl@0: ////////////////////////////////////////////////////////////////////////// sl@0: // class template recursive_wrapper sl@0: // sl@0: // See docs and recursive_wrapper_fwd.hpp for more information. sl@0: // sl@0: sl@0: template sl@0: class recursive_wrapper sl@0: { sl@0: public: // typedefs sl@0: sl@0: typedef T type; sl@0: sl@0: private: // representation sl@0: sl@0: T* p_; sl@0: sl@0: public: // structors sl@0: sl@0: ~recursive_wrapper(); sl@0: recursive_wrapper(); sl@0: sl@0: recursive_wrapper(const recursive_wrapper& operand); sl@0: recursive_wrapper(const T& operand); sl@0: sl@0: private: // helpers, for modifiers (below) sl@0: sl@0: void assign(const T& rhs); sl@0: sl@0: public: // modifiers sl@0: sl@0: recursive_wrapper& operator=(const recursive_wrapper& rhs) sl@0: { sl@0: assign( rhs.get() ); sl@0: return *this; sl@0: } sl@0: sl@0: recursive_wrapper& operator=(const T& rhs) sl@0: { sl@0: assign( rhs ); sl@0: return *this; sl@0: } sl@0: sl@0: void swap(recursive_wrapper& operand) sl@0: { sl@0: T* temp = operand.p_; sl@0: operand.p_ = p_; sl@0: p_ = temp; sl@0: } sl@0: sl@0: public: // queries sl@0: sl@0: T& get() { return *get_pointer(); } sl@0: const T& get() const { return *get_pointer(); } sl@0: sl@0: T* get_pointer() { return p_; } sl@0: const T* get_pointer() const { return p_; } sl@0: sl@0: }; sl@0: sl@0: template sl@0: recursive_wrapper::~recursive_wrapper() sl@0: { sl@0: boost::checked_delete(p_); sl@0: } sl@0: sl@0: template sl@0: recursive_wrapper::recursive_wrapper() sl@0: : p_(new T) sl@0: { sl@0: } sl@0: sl@0: template sl@0: recursive_wrapper::recursive_wrapper(const recursive_wrapper& operand) sl@0: : p_(new T( operand.get() )) sl@0: { sl@0: } sl@0: sl@0: template sl@0: recursive_wrapper::recursive_wrapper(const T& operand) sl@0: : p_(new T(operand)) sl@0: { sl@0: } sl@0: sl@0: template sl@0: void recursive_wrapper::assign(const T& rhs) sl@0: { sl@0: this->get() = rhs; sl@0: } sl@0: sl@0: // function template swap sl@0: // sl@0: // Swaps two recursive_wrapper objects of the same type T. sl@0: // sl@0: template sl@0: inline void swap(recursive_wrapper& lhs, recursive_wrapper& rhs) sl@0: { sl@0: lhs.swap(rhs); sl@0: } sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_HPP