]> git.lyx.org Git - lyx.git/blob - 3rdparty/boost/boost/exception/exception.hpp
de.po
[lyx.git] / 3rdparty / boost / boost / exception / exception.hpp
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
2
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
7 #define UUID_274DA366004E11DCB1DDFE2E56D89593
8 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
9 #pragma GCC system_header
10 #endif
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
12 #pragma warning(push,1)
13 #endif
14
15 namespace
16 boost
17     {
18     namespace
19     exception_detail
20         {
21         template <class T>
22         class
23         refcount_ptr
24             {
25             public:
26
27             refcount_ptr():
28                 px_(0)
29                 {
30                 }
31
32             ~refcount_ptr()
33                 {
34                 release();
35                 }
36
37             refcount_ptr( refcount_ptr const & x ):
38                 px_(x.px_)
39                 {
40                 add_ref();
41                 }
42
43             refcount_ptr &
44             operator=( refcount_ptr const & x )
45                 {
46                 adopt(x.px_);
47                 return *this;
48                 }
49
50             void
51             adopt( T * px )
52                 {
53                 release();
54                 px_=px;
55                 add_ref();
56                 }
57
58             T *
59             get() const
60                 {
61                 return px_;
62                 }
63
64             private:
65
66             T * px_;
67
68             void
69             add_ref()
70                 {
71                 if( px_ )
72                     px_->add_ref();
73                 }
74
75             void
76             release()
77                 {
78                 if( px_ && px_->release() )
79                     px_=0;
80                 }
81             };
82         }
83
84     ////////////////////////////////////////////////////////////////////////
85
86     template <class Tag,class T>
87     class error_info;
88
89     typedef error_info<struct throw_function_,char const *> throw_function;
90     typedef error_info<struct throw_file_,char const *> throw_file;
91     typedef error_info<struct throw_line_,int> throw_line;
92
93     template <>
94     class
95     error_info<throw_function_,char const *>
96         {
97         public:
98         typedef char const * value_type;
99         value_type v_;
100         explicit
101         error_info( value_type v ):
102             v_(v)
103             {
104             }
105         };
106
107     template <>
108     class
109     error_info<throw_file_,char const *>
110         {
111         public:
112         typedef char const * value_type;
113         value_type v_;
114         explicit
115         error_info( value_type v ):
116             v_(v)
117             {
118             }
119         };
120
121     template <>
122     class
123     error_info<throw_line_,int>
124         {
125         public:
126         typedef int value_type;
127         value_type v_;
128         explicit
129         error_info( value_type v ):
130             v_(v)
131             {
132             }
133         };
134
135 #if defined(__GNUC__)
136 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
137 #  pragma GCC visibility push (default)
138 # endif
139 #endif
140     class exception;
141 #if defined(__GNUC__)
142 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
143 #  pragma GCC visibility pop
144 # endif
145 #endif
146
147     template <class T>
148     class shared_ptr;
149
150     namespace
151     exception_detail
152         {
153         class error_info_base;
154         struct type_info_;
155
156         struct
157         error_info_container
158             {
159             virtual char const * diagnostic_information( char const * ) const = 0;
160             virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
161             virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
162             virtual void add_ref() const = 0;
163             virtual bool release() const = 0;
164             virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
165
166             protected:
167
168             ~error_info_container() throw()
169                 {
170                 }
171             };
172
173         template <class>
174         struct get_info;
175
176         template <>
177         struct get_info<throw_function>;
178
179         template <>
180         struct get_info<throw_file>;
181
182         template <>
183         struct get_info<throw_line>;
184
185         template <class>
186         struct set_info_rv;
187
188         template <>
189         struct set_info_rv<throw_function>;
190
191         template <>
192         struct set_info_rv<throw_file>;
193
194         template <>
195         struct set_info_rv<throw_line>;
196
197         char const * get_diagnostic_information( exception const &, char const * );
198
199         void copy_boost_exception( exception *, exception const * );
200
201         template <class E,class Tag,class T>
202         E const & set_info( E const &, error_info<Tag,T> const & );
203
204         template <class E>
205         E const & set_info( E const &, throw_function const & );
206
207         template <class E>
208         E const & set_info( E const &, throw_file const & );
209
210         template <class E>
211         E const & set_info( E const &, throw_line const & );
212         }
213
214 #if defined(__GNUC__)
215 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
216 #  pragma GCC visibility push (default)
217 # endif
218 #endif
219     class
220     exception
221         {
222         //<N3757>
223         public:
224         template <class Tag> void set( typename Tag::type const & );
225         template <class Tag> typename Tag::type const * get() const;
226         //</N3757>
227
228         protected:
229
230         exception():
231             throw_function_(0),
232             throw_file_(0),
233             throw_line_(-1)
234             {
235             }
236
237 #ifdef __HP_aCC
238         //On HP aCC, this protected copy constructor prevents throwing boost::exception.
239         //On all other platforms, the same effect is achieved by the pure virtual destructor.
240         exception( exception const & x ) throw():
241             data_(x.data_),
242             throw_function_(x.throw_function_),
243             throw_file_(x.throw_file_),
244             throw_line_(x.throw_line_)
245             {
246             }
247 #endif
248
249         virtual ~exception() throw()
250 #ifndef __HP_aCC
251             = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
252 #endif
253             ;
254
255 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
256         public:
257 #else
258         private:
259
260         template <class E>
261         friend E const & exception_detail::set_info( E const &, throw_function const & );
262
263         template <class E>
264         friend E const & exception_detail::set_info( E const &, throw_file const & );
265
266         template <class E>
267         friend E const & exception_detail::set_info( E const &, throw_line const & );
268
269         template <class E,class Tag,class T>
270         friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
271
272         friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
273
274         template <class>
275         friend struct exception_detail::get_info;
276         friend struct exception_detail::get_info<throw_function>;
277         friend struct exception_detail::get_info<throw_file>;
278         friend struct exception_detail::get_info<throw_line>;
279         template <class>
280         friend struct exception_detail::set_info_rv;
281         friend struct exception_detail::set_info_rv<throw_function>;
282         friend struct exception_detail::set_info_rv<throw_file>;
283         friend struct exception_detail::set_info_rv<throw_line>;
284         friend void exception_detail::copy_boost_exception( exception *, exception const * );
285 #endif
286         mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
287         mutable char const * throw_function_;
288         mutable char const * throw_file_;
289         mutable int throw_line_;
290         };
291 #if defined(__GNUC__)
292 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
293 #  pragma GCC visibility pop
294 # endif
295 #endif
296
297     inline
298     exception::
299     ~exception() throw()
300         {
301         }
302
303     namespace
304     exception_detail
305         {
306         template <class E>
307         E const &
308         set_info( E const & x, throw_function const & y )
309             {
310             x.throw_function_=y.v_;
311             return x;
312             }
313
314         template <class E>
315         E const &
316         set_info( E const & x, throw_file const & y )
317             {
318             x.throw_file_=y.v_;
319             return x;
320             }
321
322         template <class E>
323         E const &
324         set_info( E const & x, throw_line const & y )
325             {
326             x.throw_line_=y.v_;
327             return x;
328             }
329         }
330
331     ////////////////////////////////////////////////////////////////////////
332
333     namespace
334     exception_detail
335         {
336 #if defined(__GNUC__)
337 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
338 #  pragma GCC visibility push (default)
339 # endif
340 #endif
341         template <class T>
342         struct
343         error_info_injector:
344             public T,
345             public exception
346             {
347             explicit
348             error_info_injector( T const & x ):
349                 T(x)
350                 {
351                 }
352
353             ~error_info_injector() throw()
354                 {
355                 }
356             };
357 #if defined(__GNUC__)
358 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
359 #  pragma GCC visibility pop
360 # endif
361 #endif
362
363         struct large_size { char c[256]; };
364         large_size dispatch_boost_exception( exception const * );
365
366         struct small_size { };
367         small_size dispatch_boost_exception( void const * );
368
369         template <class,int>
370         struct enable_error_info_helper;
371
372         template <class T>
373         struct
374         enable_error_info_helper<T,sizeof(large_size)>
375             {
376             typedef T type;
377             };
378
379         template <class T>
380         struct
381         enable_error_info_helper<T,sizeof(small_size)>
382             {
383             typedef error_info_injector<T> type;
384             };
385
386         template <class T>
387         struct
388         enable_error_info_return_type
389             {
390             typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
391             };
392         }
393
394     template <class T>
395     inline
396     typename
397     exception_detail::enable_error_info_return_type<T>::type
398     enable_error_info( T const & x )
399         {
400         typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
401         return rt(x);
402         }
403
404     ////////////////////////////////////////////////////////////////////////
405
406     namespace
407     exception_detail
408         {
409 #if defined(__GNUC__)
410 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
411 #  pragma GCC visibility push (default)
412 # endif
413 #endif
414         class
415         clone_base
416             {
417             public:
418
419             virtual clone_base const * clone() const = 0;
420             virtual void rethrow() const = 0;
421
422             virtual
423             ~clone_base() throw()
424                 {
425                 }
426             };
427 #if defined(__GNUC__)
428 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
429 #  pragma GCC visibility pop
430 # endif
431 #endif
432
433         inline
434         void
435         copy_boost_exception( exception * a, exception const * b )
436             {
437             refcount_ptr<error_info_container> data;
438             if( error_info_container * d=b->data_.get() )
439                 data = d->clone();
440             a->throw_file_ = b->throw_file_;
441             a->throw_line_ = b->throw_line_;
442             a->throw_function_ = b->throw_function_;
443             a->data_ = data;
444             }
445
446         inline
447         void
448         copy_boost_exception( void *, void const * )
449             {
450             }
451
452 #if defined(__GNUC__)
453 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
454 #  pragma GCC visibility push (default)
455 # endif
456 #endif
457         template <class T>
458         class
459         clone_impl:
460             public T,
461             public virtual clone_base
462             {
463             struct clone_tag { };
464             clone_impl( clone_impl const & x, clone_tag ):
465                 T(x)
466                 {
467                 copy_boost_exception(this,&x);
468                 }
469
470             public:
471
472             explicit
473             clone_impl( T const & x ):
474                 T(x)
475                 {
476                 copy_boost_exception(this,&x);
477                 }
478
479             ~clone_impl() throw()
480                 {
481                 }
482
483             private:
484
485             clone_base const *
486             clone() const
487                 {
488                 return new clone_impl(*this,clone_tag());
489                 }
490
491             void
492             rethrow() const
493                 {
494                 throw*this;
495                 }
496             };
497         }
498 #if defined(__GNUC__)
499 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
500 #  pragma GCC visibility pop
501 # endif
502 #endif
503
504     template <class T>
505     inline
506     exception_detail::clone_impl<T>
507     enable_current_exception( T const & x )
508         {
509         return exception_detail::clone_impl<T>(x);
510         }
511     }
512
513 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
514 #pragma warning(pop)
515 #endif
516 #endif