• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // archive_exception.cpp:
3 
4 // (C) Copyright 2009 Robert Ramey - http://www.rrsd.com .
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 //  See http://www.boost.org for updates, documentation, and revision history.
10 
11 #if (defined _MSC_VER) && (_MSC_VER == 1200)
12 #  pragma warning (disable : 4786) // too long name, harmless warning
13 #endif
14 
15 #include <exception>
16 #include <string>
17 #include <cstring>
18 
19 #define BOOST_ARCHIVE_SOURCE
20 #include <boost/serialization/config.hpp>
21 #include <boost/archive/archive_exception.hpp>
22 
23 namespace boost {
24 namespace archive {
25 
26 BOOST_ARCHIVE_DECL
27 unsigned int
append(unsigned int l,const char * a)28 archive_exception::append(unsigned int l, const char * a){
29     while(l < (sizeof(m_buffer) - 1)){
30         char c = *a++;
31         if('\0' == c)
32             break;
33         m_buffer[l++] = c;
34     }
35     m_buffer[l] = '\0';
36     return l;
37 }
38 
39 BOOST_ARCHIVE_DECL
archive_exception(exception_code c,const char * e1,const char * e2)40 archive_exception::archive_exception(
41     exception_code c,
42     const char * e1,
43     const char * e2
44 ) BOOST_NOEXCEPT :
45     code(c)
46 {
47     unsigned int length = 0;
48     switch(code){
49     case no_exception:
50         length = append(length, "uninitialized exception");
51         break;
52     case unregistered_class:
53         length = append(length, "unregistered class");
54         if(NULL != e1){
55             length = append(length, " - ");
56             length = append(length, e1);
57         }
58         break;
59     case invalid_signature:
60         length = append(length, "invalid signature");
61         break;
62     case unsupported_version:
63         length = append(length, "unsupported version");
64         break;
65     case pointer_conflict:
66         length = append(length, "pointer conflict");
67         break;
68     case incompatible_native_format:
69         length = append(length, "incompatible native format");
70         if(NULL != e1){
71             length = append(length, " - ");
72             length = append(length, e1);
73         }
74         break;
75     case array_size_too_short:
76         length = append(length, "array size too short");
77         break;
78     case input_stream_error:
79         length = append(length, "input stream error");
80         if(NULL != e1){
81             length = append(length, "-");
82             length = append(length, e1);
83         }
84         if(NULL != e2){
85             length = append(length, "-");
86             length = append(length, e2);
87         }
88         break;
89     case invalid_class_name:
90         length = append(length, "class name too long");
91         break;
92     case unregistered_cast:
93         length = append(length, "unregistered void cast ");
94         length = append(length, (NULL != e1) ? e1 : "?");
95         length = append(length, "<-");
96         length = append(length, (NULL != e2) ? e2 : "?");
97         break;
98     case unsupported_class_version:
99         length = append(length, "class version ");
100         length = append(length, (NULL != e1) ? e1 : "<unknown class>");
101         break;
102     case other_exception:
103         // if get here - it indicates a derived exception
104         // was sliced by passing by value in catch
105         length = append(length, "unknown derived exception");
106         break;
107     case multiple_code_instantiation:
108         length = append(length, "code instantiated in more than one module");
109         if(NULL != e1){
110             length = append(length, " - ");
111             length = append(length, e1);
112         }
113         break;
114     case output_stream_error:
115         length = append(length, "output stream error");
116         if(NULL != e1){
117             length = append(length, "-");
118             length = append(length, e1);
119         }
120         if(NULL != e2){
121             length = append(length, "-");
122             length = append(length, e2);
123         }
124         break;
125     default:
126         BOOST_ASSERT(false);
127         length = append(length, "programming error");
128         break;
129     }
130 }
131 
132 BOOST_ARCHIVE_DECL
archive_exception(archive_exception const & oth)133 archive_exception::archive_exception(archive_exception const & oth) BOOST_NOEXCEPT :
134 	std::exception(oth),
135 	code(oth.code)
136 {
137 	std::memcpy(m_buffer,oth.m_buffer,sizeof m_buffer);
138 }
139 
140 BOOST_ARCHIVE_DECL
~archive_exception()141 archive_exception::~archive_exception() BOOST_NOEXCEPT_OR_NOTHROW {}
142 
143 BOOST_ARCHIVE_DECL const char *
what() const144 archive_exception::what() const BOOST_NOEXCEPT_OR_NOTHROW {
145     return m_buffer;
146 }
147 
148 BOOST_ARCHIVE_DECL
archive_exception()149 archive_exception::archive_exception() BOOST_NOEXCEPT :
150     code(no_exception)
151 {}
152 
153 } // archive
154 } // boost
155