base64_exception.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef BOOST_ARCHIVE_ITERATORS_BASE64_EXCEPTION_HPP
  2. #define BOOST_ARCHIVE_ITERATORS_BASE64_EXCEPTION_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // base64_exception.hpp:
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <boost/config.hpp>
  15. #ifndef BOOST_NO_EXCEPTIONS
  16. #include <exception>
  17. #include <boost/assert.hpp>
  18. namespace boost {
  19. namespace archive {
  20. namespace iterators {
  21. //////////////////////////////////////////////////////////////////////
  22. // exceptions thrown by base64s
  23. //
  24. class base64_exception : public std::exception
  25. {
  26. public:
  27. typedef enum {
  28. invalid_code, // attempt to encode a value > 6 bits
  29. invalid_character, // decode a value not in base64 char set
  30. other_exception
  31. } exception_code;
  32. exception_code code;
  33. base64_exception(exception_code c = other_exception) : code(c)
  34. {}
  35. virtual const char *what( ) const throw( )
  36. {
  37. const char *msg = "unknown exception code";
  38. switch(code){
  39. case invalid_code:
  40. msg = "attempt to encode a value > 6 bits";
  41. break;
  42. case invalid_character:
  43. msg = "attempt to decode a value not in base64 char set";
  44. break;
  45. default:
  46. BOOST_ASSERT(false);
  47. break;
  48. }
  49. return msg;
  50. }
  51. };
  52. } // namespace iterators
  53. } // namespace archive
  54. } // namespace boost
  55. #endif //BOOST_NO_EXCEPTIONS
  56. #endif //BOOST_ARCHIVE_ITERATORS_ARCHIVE_EXCEPTION_HPP