50d326a71b665d71275d3b9ea004c0086eed0a61
[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 BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
26 archive_exception::archive_exception(
27     exception_code c, 
28     const char * e1,
29     const char * e2
30 ) : 
31     code(c)
32 {
33     m_msg = "programming error";
34     switch(code){
35     case no_exception:
36         m_msg = "uninitialized exception";
37         break;
38     case unregistered_class:
39         m_msg = "unregistered class";
40         if(NULL != e1){
41             m_msg += " - ";
42             m_msg += e1;
43         }    
44         break;
45     case invalid_signature:
46         m_msg = "invalid signature";
47         break;
48     case unsupported_version:
49         m_msg = "unsupported version";
50         break;
51     case pointer_conflict:
52         m_msg = "pointer conflict";
53         break;
54     case incompatible_native_format:
55         m_msg = "incompatible native format";
56         if(NULL != e1){
57             m_msg += " - ";
58             m_msg += e1;
59         }    
60         break;
61     case array_size_too_short:
62         m_msg = "array size too short";
63         break;
64     case input_stream_error:
65         m_msg = "input stream error";
66         break;
67     case invalid_class_name:
68         m_msg = "class name too long";
69         break;
70     case unregistered_cast:
71         m_msg = "unregistered void cast ";
72         m_msg += (NULL != e1) ? e1 : "?";
73         m_msg += "<-";
74         m_msg += (NULL != e2) ? e2 : "?";
75         break;
76     case unsupported_class_version:
77         m_msg = "class version ";
78         m_msg += (NULL != e1) ? e1 : "<unknown class>";
79         break;
80     case other_exception:
81         // if get here - it indicates a derived exception 
82         // was sliced by passing by value in catch
83         m_msg = "unknown derived exception";
84         break;
85     case multiple_code_instantiation:
86         m_msg = "code instantiated in more than one module";
87         if(NULL != e1){
88             m_msg += " - ";
89             m_msg += e1;
90         }    
91         break;
92     case output_stream_error:
93         m_msg = "output stream error";
94         break;
95     default:
96         BOOST_ASSERT(false);
97         break;
98     }
99 }
100 BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
101 archive_exception::~archive_exception() throw () {}
102
103 BOOST_ARCHIVE_DECL(const char *)
104 archive_exception::what( ) const throw()
105 {
106     return m_msg.c_str();
107 }
108 BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
109 archive_exception::archive_exception() : 
110         code(no_exception)
111 {}
112
113 } // archive
114 } // boost