libstdc++
exception_ptr.h
Go to the documentation of this file.
00001 // Exception Handling support header (exception_ptr class) for -*- C++ -*-
00002 
00003 // Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation
00004 //
00005 // This file is part of GCC.
00006 //
00007 // GCC is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 3, or (at your option)
00010 // any later version.
00011 // 
00012 // GCC is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 // 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /** @file bits/exception_ptr.h
00027  *  This is an internal header file, included by other library headers.
00028  *  Do not attempt to use it directly. @headername{exception}
00029  */
00030 
00031 #ifndef _EXCEPTION_PTR_H
00032 #define _EXCEPTION_PTR_H
00033 
00034 #pragma GCC visibility push(default)
00035 
00036 #include <bits/c++config.h>
00037 #include <bits/exception_defines.h>
00038 
00039 #if !defined(_GLIBCXX_ATOMIC_BUILTINS_4)
00040 #  error This platform does not support exception propagation.
00041 #endif
00042 
00043 extern "C++" {
00044 
00045 namespace std 
00046 {
00047   /**
00048    * @addtogroup exceptions
00049    * @{
00050    */
00051   namespace __exception_ptr
00052   {
00053     class exception_ptr;
00054   }
00055 
00056   using __exception_ptr::exception_ptr;
00057 
00058   /** Obtain an exception_ptr to the currently handled exception. If there
00059    *  is none, or the currently handled exception is foreign, return the null
00060    *  value.
00061    */
00062   exception_ptr current_exception() throw();
00063 
00064   /// Throw the object pointed to by the exception_ptr.
00065   void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__));
00066 
00067   namespace __exception_ptr
00068   {
00069     /**
00070      *  @brief An opaque pointer to an arbitrary exception.
00071      *  @ingroup exceptions
00072      */
00073     class exception_ptr
00074     {
00075       void* _M_exception_object;
00076 
00077       explicit exception_ptr(void* __e) throw();
00078 
00079       void _M_addref() throw();
00080       void _M_release() throw();
00081 
00082       void *_M_get() const throw() __attribute__ ((__pure__));
00083 
00084       friend exception_ptr std::current_exception() throw();
00085       friend void std::rethrow_exception(exception_ptr);
00086 
00087     public:
00088       exception_ptr() throw();
00089 
00090       exception_ptr(const exception_ptr&) throw();
00091 
00092 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00093       exception_ptr(nullptr_t) throw()
00094       : _M_exception_object(0)
00095       { }
00096 
00097       exception_ptr(exception_ptr&& __o) throw()
00098       : _M_exception_object(__o._M_exception_object)
00099       { __o._M_exception_object = 0; }
00100 #else
00101       typedef void (exception_ptr::*__safe_bool)();
00102 
00103       // For construction from nullptr or 0.
00104       exception_ptr(__safe_bool) throw();
00105 #endif
00106 
00107       exception_ptr& 
00108       operator=(const exception_ptr&) throw();
00109 
00110 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00111       exception_ptr& 
00112       operator=(exception_ptr&& __o) throw()
00113       {
00114         exception_ptr(static_cast<exception_ptr&&>(__o)).swap(*this);
00115         return *this;
00116       }
00117 #endif
00118 
00119       ~exception_ptr() throw();
00120 
00121       void 
00122       swap(exception_ptr&) throw();
00123 
00124 #ifdef _GLIBCXX_EH_PTR_COMPAT
00125       // Retained for compatibility with CXXABI_1.3.
00126       void _M_safe_bool_dummy() throw() __attribute__ ((__const__));
00127       bool operator!() const throw() __attribute__ ((__pure__));
00128       operator __safe_bool() const throw();
00129 #endif
00130 
00131 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00132       explicit operator bool() const
00133       { return _M_exception_object; }
00134 #endif
00135 
00136       friend bool 
00137       operator==(const exception_ptr&, const exception_ptr&) throw() 
00138       __attribute__ ((__pure__));
00139 
00140       const class type_info*
00141       __cxa_exception_type() const throw() __attribute__ ((__pure__));
00142     };
00143 
00144     bool 
00145     operator==(const exception_ptr&, const exception_ptr&) throw() 
00146     __attribute__ ((__pure__));
00147 
00148     bool 
00149     operator!=(const exception_ptr&, const exception_ptr&) throw() 
00150     __attribute__ ((__pure__));
00151 
00152     inline void
00153     swap(exception_ptr& __lhs, exception_ptr& __rhs)
00154     { __lhs.swap(__rhs); }
00155 
00156   } // namespace __exception_ptr
00157 
00158 
00159   /// Obtain an exception_ptr pointing to a copy of the supplied object.
00160   template<typename _Ex>
00161     exception_ptr 
00162     copy_exception(_Ex __ex) throw()
00163     {
00164       __try
00165     {
00166 #ifdef __EXCEPTIONS
00167       throw __ex;
00168 #endif
00169     }
00170       __catch(...)
00171     {
00172       return current_exception();
00173     }
00174     }
00175 
00176   // _GLIBCXX_RESOLVE_LIB_DEFECTS
00177   // 1130. copy_exception name misleading
00178   /// Obtain an exception_ptr pointing to a copy of the supplied object.
00179   template<typename _Ex>
00180     exception_ptr 
00181     make_exception_ptr(_Ex __ex) throw()
00182     { return std::copy_exception<_Ex>(__ex); }
00183 
00184   // @} group exceptions
00185 } // namespace std
00186 
00187 } // extern "C++"
00188 
00189 #pragma GCC visibility pop
00190 
00191 #endif