source: NonGTP/Boost/boost/variant/recursive_wrapper.hpp @ 857

Revision 857, 2.7 KB checked in by igarcia, 19 years ago (diff)
Line 
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
19namespace boost {
20
21//////////////////////////////////////////////////////////////////////////
22// class template recursive_wrapper
23//
24// See docs and recursive_wrapper_fwd.hpp for more information.
25//
26
27template <typename T>
28class recursive_wrapper
29{
30public: // typedefs
31
32    typedef T type;
33
34private: // representation
35
36    T* p_;
37
38public: // structors
39
40    ~recursive_wrapper();
41    recursive_wrapper();
42
43    recursive_wrapper(const recursive_wrapper& operand);
44    recursive_wrapper(const T& operand);
45
46private: // helpers, for modifiers (below)
47
48    void assign(const T& rhs);
49
50public: // 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
71public: // 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
81template <typename T>
82recursive_wrapper<T>::~recursive_wrapper()
83{
84    boost::checked_delete(p_);
85}
86
87template <typename T>
88recursive_wrapper<T>::recursive_wrapper()
89    : p_(new T)
90{
91}
92
93template <typename T>
94recursive_wrapper<T>::recursive_wrapper(const recursive_wrapper& operand)
95    : p_(new T( operand.get() ))
96{
97}
98
99template <typename T>
100recursive_wrapper<T>::recursive_wrapper(const T& operand)
101    : p_(new T(operand))
102{
103}
104
105template <typename T>
106void 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//
115template <typename T>
116inline 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
Note: See TracBrowser for help on using the repository browser.