File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux/CPP/Boost/Mini.x/i/boost/exception/exception.hpp
Criterion Covered Total %
statement 80 91 87.9
branch 15 76 19.7
condition n/a
subroutine n/a
pod n/a
total 95 167 56.8


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