epoc32/include/stdapis/boost/variant/detail/backup_holder.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 //-----------------------------------------------------------------------------
     2 // boost variant/detail/backup_holder.hpp header file
     3 // See http://www.boost.org for updates, documentation, and revision history.
     4 //-----------------------------------------------------------------------------
     5 //
     6 // Copyright (c) 2003
     7 // Eric Friedman
     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_DETAIL_BACKUP_HOLDER_HPP
    14 #define BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP
    15 
    16 #include "boost/assert.hpp"
    17 
    18 namespace boost {
    19 namespace detail { namespace variant {
    20 
    21 template <typename T>
    22 class backup_holder
    23 {
    24 private: // representation
    25 
    26     T* backup_;
    27 
    28 public: // structors
    29 
    30     ~backup_holder()
    31     {
    32         delete backup_;
    33     }
    34 
    35     explicit backup_holder(T* backup)
    36         : backup_(backup)
    37     {
    38     }
    39 
    40     backup_holder(const backup_holder&);
    41 
    42 public: // modifiers
    43 
    44     backup_holder& operator=(const backup_holder& rhs)
    45     {
    46         *backup_ = rhs.get();
    47         return *this;
    48     }
    49 
    50     backup_holder& operator=(const T& rhs)
    51     {
    52         *backup_ = rhs;
    53         return *this;
    54     }
    55 
    56     void swap(backup_holder& rhs)
    57     {
    58         T* tmp = rhs.backup_;
    59         rhs.backup_ = this->backup_;
    60         this->backup_ = tmp;
    61     }
    62 
    63 public: // queries
    64 
    65     T& get()
    66     {
    67         return *backup_;
    68     }
    69 
    70     const T& get() const
    71     {
    72         return *backup_;
    73     }
    74 
    75 };
    76 
    77 template <typename T>
    78 backup_holder<T>::backup_holder(const backup_holder&)
    79     : backup_(0)
    80 {
    81     // not intended for copy, but do not want to prohibit syntactically
    82     BOOST_ASSERT(false);
    83 }
    84 
    85 template <typename T>
    86 void swap(backup_holder<T>& lhs, backup_holder<T>& rhs)
    87 {
    88     lhs.swap(rhs);
    89 }
    90 
    91 }} // namespace detail::variant
    92 } // namespace boost
    93 
    94 #endif // BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP