[857] | 1 | //-----------------------------------------------------------------------------
|
---|
| 2 | // boost variant/recursive_wrapper.hpp header file
|
---|
| 3 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
| 4 | //-----------------------------------------------------------------------------
|
---|
| 5 | //
|
---|
| 6 | // Copyright (c) 2002-2003
|
---|
| 7 | // Eric Friedman, Itay Maman
|
---|
| 8 | //
|
---|
| 9 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
| 10 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
| 11 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 12 |
|
---|
| 13 | #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
|
---|
| 14 | #define BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
|
---|
| 15 |
|
---|
| 16 | #include "boost/variant/recursive_wrapper_fwd.hpp"
|
---|
| 17 | #include "boost/checked_delete.hpp"
|
---|
| 18 |
|
---|
| 19 | namespace boost {
|
---|
| 20 |
|
---|
| 21 | //////////////////////////////////////////////////////////////////////////
|
---|
| 22 | // class template recursive_wrapper
|
---|
| 23 | //
|
---|
| 24 | // See docs and recursive_wrapper_fwd.hpp for more information.
|
---|
| 25 | //
|
---|
| 26 |
|
---|
| 27 | template <typename T>
|
---|
| 28 | class recursive_wrapper
|
---|
| 29 | {
|
---|
| 30 | public: // typedefs
|
---|
| 31 |
|
---|
| 32 | typedef T type;
|
---|
| 33 |
|
---|
| 34 | private: // representation
|
---|
| 35 |
|
---|
| 36 | T* p_;
|
---|
| 37 |
|
---|
| 38 | public: // structors
|
---|
| 39 |
|
---|
| 40 | ~recursive_wrapper();
|
---|
| 41 | recursive_wrapper();
|
---|
| 42 |
|
---|
| 43 | recursive_wrapper(const recursive_wrapper& operand);
|
---|
| 44 | recursive_wrapper(const T& operand);
|
---|
| 45 |
|
---|
| 46 | private: // helpers, for modifiers (below)
|
---|
| 47 |
|
---|
| 48 | void assign(const T& rhs);
|
---|
| 49 |
|
---|
| 50 | public: // modifiers
|
---|
| 51 |
|
---|
| 52 | recursive_wrapper& operator=(const recursive_wrapper& rhs)
|
---|
| 53 | {
|
---|
| 54 | assign( rhs.get() );
|
---|
| 55 | return *this;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | recursive_wrapper& operator=(const T& rhs)
|
---|
| 59 | {
|
---|
| 60 | assign( rhs );
|
---|
| 61 | return *this;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void swap(recursive_wrapper& operand)
|
---|
| 65 | {
|
---|
| 66 | T* temp = operand.p_;
|
---|
| 67 | operand.p_ = p_;
|
---|
| 68 | p_ = temp;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public: // queries
|
---|
| 72 |
|
---|
| 73 | T& get() { return *get_pointer(); }
|
---|
| 74 | const T& get() const { return *get_pointer(); }
|
---|
| 75 |
|
---|
| 76 | T* get_pointer() { return p_; }
|
---|
| 77 | const T* get_pointer() const { return p_; }
|
---|
| 78 |
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 | template <typename T>
|
---|
| 82 | recursive_wrapper<T>::~recursive_wrapper()
|
---|
| 83 | {
|
---|
| 84 | boost::checked_delete(p_);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | template <typename T>
|
---|
| 88 | recursive_wrapper<T>::recursive_wrapper()
|
---|
| 89 | : p_(new T)
|
---|
| 90 | {
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | template <typename T>
|
---|
| 94 | recursive_wrapper<T>::recursive_wrapper(const recursive_wrapper& operand)
|
---|
| 95 | : p_(new T( operand.get() ))
|
---|
| 96 | {
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | template <typename T>
|
---|
| 100 | recursive_wrapper<T>::recursive_wrapper(const T& operand)
|
---|
| 101 | : p_(new T(operand))
|
---|
| 102 | {
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | template <typename T>
|
---|
| 106 | void recursive_wrapper<T>::assign(const T& rhs)
|
---|
| 107 | {
|
---|
| 108 | this->get() = rhs;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | // function template swap
|
---|
| 112 | //
|
---|
| 113 | // Swaps two recursive_wrapper<T> objects of the same type T.
|
---|
| 114 | //
|
---|
| 115 | template <typename T>
|
---|
| 116 | inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs)
|
---|
| 117 | {
|
---|
| 118 | lhs.swap(rhs);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | } // namespace boost
|
---|
| 122 |
|
---|
| 123 | #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
|
---|