Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / serialization / src / archive_exception.cpp
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 <boost/assert.hpp>
17 #include <string>
18
19 #define BOOST_ARCHIVE_SOURCE
20 #include <boost/archive/archive_exception.hpp>
21
22 namespace boost {
23 namespace archive {
24
25 unsigned int
26 archive_exception::append(unsigned int l, const char * a){
27     while(l < (sizeof(m_buffer) - 1)){
28         char c = *a++;
29         if('\0' == c)
30             break;
31         m_buffer[l++] = c;
32     }
33     m_buffer[l] = '\0';
34     return l;
35 }
36
37 BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
38 archive_exception::archive_exception(
39     exception_code c, 
40     const char * e1,
41     const char * e2
42 ) : 
43     code(c)
44 {
45     unsigned int length = 0;
46     switch(code){
47     case no_exception:
48         length = append(length, "uninitialized exception");
49         break;
50     case unregistered_class:
51         length = append(length, "unregistered class");
52         if(NULL != e1){
53             length = append(length, " - ");
54             length = append(length, e1);
55         }    
56         break;
57     case invalid_signature:
58         length = append(length, "invalid signature");
59         break;
60     case unsupported_version:
61         length = append(length, "unsupported version");
62         break;
63     case pointer_conflict:
64         length = append(length, "pointer conflict");
65         break;
66     case incompatible_native_format:
67         length = append(length, "incompatible native format");
68         if(NULL != e1){
69             length = append(length, " - ");
70             length = append(length, e1);
71         }    
72         break;
73     case array_size_too_short:
74         length = append(length, "array size too short");
75         break;
76     case input_stream_error:
77         length = append(length, "input stream error");
78         break;
79     case invalid_class_name:
80         length = append(length, "class name too long");
81         break;
82     case unregistered_cast:
83         length = append(length, "unregistered void cast ");
84         length = append(length, (NULL != e1) ? e1 : "?");
85         length = append(length, "<-");
86         length = append(length, (NULL != e2) ? e2 : "?");
87         break;
88     case unsupported_class_version:
89         length = append(length, "class version ");
90         length = append(length, (NULL != e1) ? e1 : "<unknown class>");
91         break;
92     case other_exception:
93         // if get here - it indicates a derived exception 
94         // was sliced by passing by value in catch
95         length = append(length, "unknown derived exception");
96         break;
97     case multiple_code_instantiation:
98         length = append(length, "code instantiated in more than one module");
99         if(NULL != e1){
100             length = append(length, " - ");
101             length = append(length, e1);
102         }    
103         break;
104     case output_stream_error:
105         length = append(length, "output stream error");
106         break;
107     default:
108         BOOST_ASSERT(false);
109         length = append(length, "programming error");
110         break;
111     }
112 }
113 BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
114 archive_exception::~archive_exception() throw() {}
115
116 BOOST_ARCHIVE_DECL(const char *)
117 archive_exception::what( ) const throw()
118 {
119     return m_buffer;
120 }
121 BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
122 archive_exception::archive_exception() : 
123         code(no_exception)
124 {}
125
126 } // archive
127 } // boost