OSDN Git Service

2009-02-03 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libsupc++ / exception_ptr.h
1 // Exception Handling support header (exception_ptr class) for -*- C++ -*-
2
3 // Copyright (C) 2008, 2009 Free Software Foundation
4 //
5 // This file is part of GCC.
6 //
7 // GCC is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11 // 
12 // GCC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 // 
17 // You should have received a copy of the GNU General Public License
18 // along with GCC; see the file COPYING.  If not, write to
19 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 /** @file exception_ptr.h
32  *  This is an internal header file, included by other headers and the
33  *  implementation. You should not attempt to use it directly.
34  */
35
36 #ifndef _EXCEPTION_PTR_H
37 #define _EXCEPTION_PTR_H
38
39 #pragma GCC visibility push(default)
40
41 #include <bits/c++config.h>
42 #include <exception_defines.h>
43
44 #if !defined(_GLIBCXX_ATOMIC_BUILTINS_4)
45 #  error This platform does not support exception propagation.
46 #endif
47
48 extern "C++" {
49
50 namespace std 
51 {
52   // Hide the free operators from other types
53   namespace __exception_ptr
54   {
55     /**
56      * @brief An opaque pointer to an arbitrary exception.
57      */
58     class exception_ptr;
59   }
60
61   using __exception_ptr::exception_ptr;
62
63   /** Obtain an %exception_ptr to the currently handled exception. If there
64    *  is none, or the currently handled exception is foreign, return the null
65    *  value.
66    */
67   exception_ptr current_exception() throw();
68
69   /// Throw the object pointed to by the %exception_ptr.
70   void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__));
71
72   /// Obtain an %exception_ptr pointing to a copy of the supplied object.
73   template <class _Ex>
74   exception_ptr copy_exception(_Ex __ex) throw();
75
76
77   namespace __exception_ptr
78   {
79     bool operator==(const exception_ptr&,
80                     const exception_ptr&) throw();
81     bool operator!=(const exception_ptr&,
82                     const exception_ptr&) throw();
83
84     class exception_ptr
85     {
86       void* _M_exception_object;
87
88       explicit exception_ptr(void* __e) throw();
89
90       void _M_addref() throw();
91       void _M_release() throw();
92
93       void *_M_get() const throw();
94
95       void _M_safe_bool_dummy();
96
97       friend exception_ptr std::current_exception() throw();
98       friend void std::rethrow_exception(exception_ptr);
99
100     public:
101       exception_ptr() throw();
102
103       typedef void (exception_ptr::*__safe_bool)();
104
105       // For construction from nullptr or 0.
106       exception_ptr(__safe_bool) throw();
107
108       exception_ptr(const exception_ptr&) throw();
109
110 #ifdef __GXX_EXPERIMENTAL_CXX0X__
111       exception_ptr(exception_ptr&& __o) throw()
112         : _M_exception_object(__o._M_exception_object)
113       {
114         __o._M_exception_object = 0;
115       }
116 #endif
117
118       exception_ptr& operator=(const exception_ptr&) throw();
119
120 #ifdef __GXX_EXPERIMENTAL_CXX0X__
121       exception_ptr& operator=(exception_ptr&& __o) throw()
122       {
123         exception_ptr(__o).swap(*this);
124         return *this;
125       }
126 #endif
127
128       ~exception_ptr() throw();
129
130       void swap(exception_ptr&) throw();
131
132 #ifdef __GXX_EXPERIMENTAL_CXX0X__
133       void swap(exception_ptr &&__o) throw()
134       {
135         void *__tmp = _M_exception_object;
136         _M_exception_object = __o._M_exception_object;
137         __o._M_exception_object = __tmp;
138       }
139 #endif
140
141       bool operator!() const throw();
142       operator __safe_bool() const throw();
143
144       friend bool operator==(const exception_ptr&,
145                              const exception_ptr&) throw();
146
147       const type_info *__cxa_exception_type() const throw();
148     };
149
150   } // namespace __exception_ptr
151
152
153   template <class _Ex>
154   exception_ptr copy_exception(_Ex __ex) throw()
155   {
156     __try
157       {
158         throw __ex;
159       }
160     __catch(...)
161       {
162         return current_exception ();
163       }
164   }
165
166 } // namespace std
167
168 } // extern "C++"
169
170 #pragma GCC visibility pop
171
172 #endif