Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:32

0001 /*****************************************************************************/
0002 /**

0003  * \file portable_archive_exception.hpp

0004  * \brief Provides error handling and constants.

0005  * \author christian.pfligersdorffer@gmx.at

0006  *

0007  * Portable archive exceptions derive from the boost archive exceptions

0008  * and add failure causes specific to the portable binary usecase.

0009  *

0010  * Additionally this header serves as common include for important

0011  * constants or typedefs.

0012  */
0013 /****************************************************************************/
0014 
0015 #pragma once
0016 
0017 #include <boost/archive/basic_archive.hpp>
0018 #include <boost/archive/archive_exception.hpp>
0019 
0020 namespace eos {
0021 
0022   // this value is written to the top of the stream

0023   const signed char magic_byte = 'e' | 'o' | 's';
0024 
0025   // flag for fp serialization

0026   const unsigned no_infnan = 64;
0027 
0028 // integral type for the archive version

0029 #if BOOST_VERSION < 104400
0030   typedef boost::archive::version_type archive_version_type;
0031 #else
0032   typedef boost::archive::library_version_type archive_version_type;
0033 #endif
0034 
0035   // version of the linked boost archive library

0036   const archive_version_type archive_version(
0037 #if BOOST_VERSION < 103700
0038       boost::archive::ARCHIVE_VERSION()
0039 #else
0040       boost::archive::BOOST_ARCHIVE_VERSION()
0041 #endif
0042   );
0043 
0044   /**

0045      * \brief Exception being thrown when serialization cannot proceed.

0046      *

0047      * There are several situations in which the portable archives may fail and

0048      * hence throw an exception: 

0049      * -# deserialization of an integer value that exceeds the range of the type 

0050      * -# (de)serialization of inf/nan through an archive with no_infnan flag set

0051      * -# deserialization of a denormalized value without the floating point type

0052      *    supporting denormalized numbers

0053      *

0054      * Note that this exception will also be thrown if you mixed up your stream

0055      * position and accidentially interpret some value for size data (in this case

0056      * the reported size will be totally amiss most of the time).

0057      */
0058   class portable_archive_exception : public boost::archive::archive_exception {
0059     std::string msg;
0060 
0061   public:
0062     //! type size is not large enough for deserialized number

0063     portable_archive_exception(signed char invalid_size)
0064         : boost::archive::archive_exception(other_exception), msg("requested integer size exceeds type size: ") {
0065       msg += std::to_string(invalid_size);
0066     }
0067 
0068     //! negative number in unsigned type

0069     portable_archive_exception()
0070         : boost::archive::archive_exception(other_exception),
0071           msg("cannot read a negative number into an unsigned type") {}
0072 
0073     //! serialization of inf, nan and denormals

0074     template <typename T>
0075     portable_archive_exception(const T& abnormal)
0076         : boost::archive::archive_exception(other_exception), msg("serialization of illegal floating point value: ") {
0077       msg += std::to_string(abnormal);
0078     }
0079 
0080     //! override the base class function with our message

0081     const char* what() const throw() override { return msg.c_str(); }
0082     ~portable_archive_exception() throw() override {}
0083   };
0084 
0085 }  // namespace eos