LCOV - code coverage report
Current view: top level - co - dataStreamArchiveException.h (source / functions) Hit Total Coverage
Test: Collage Lines: 0 15 0.0 %
Date: 2016-12-14 01:26:48 Functions: 0 6 0.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@googlemail.com>
       3             :  *
       4             :  * This file is part of Collage <https://github.com/Eyescale/Collage>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #ifndef CO_DATASTREAMARCHIVEEXCEPTION_H
      21             : #define CO_DATASTREAMARCHIVEEXCEPTION_H
      22             : 
      23             : #include <boost/lexical_cast.hpp>
      24             : #include <boost/archive/archive_exception.hpp>
      25             : 
      26             : 
      27             : namespace co
      28             : {
      29             : namespace serialization
      30             : {
      31             : // @internal flag for fp serialization
      32             : const unsigned no_infnan = 64;
      33             : }
      34             : 
      35             : /**
      36             :  * \brief Exception thrown when serialization cannot proceed.
      37             :  *
      38             :  * There are several situations in which the DataStream archives may fail and
      39             :  * throw an exception:
      40             :  * -# deserialization of an integer value that exceeds the range of the type
      41             :  * -# (de)serialization of inf/nan through an archive with no_infnan flag set
      42             :  * -# deserialization of a denormalized value without the floating point type
      43             :  *    supporting denormalized numbers
      44             :  *
      45             :  * Note that this exception will also be thrown if you mixed up your stream
      46             :  * position and accidentially interpret some value for size data (in this case
      47             :  * the reported size will be totally amiss most of the time).
      48             :  */
      49             : class DataStreamArchiveException : public boost::archive::archive_exception
      50             : {
      51             :     std::string msg;
      52             : 
      53             : public:
      54             :     //! type size is not large enough for deserialized number
      55           0 :     explicit DataStreamArchiveException( const signed char invalid_size )
      56           0 :         : boost::archive::archive_exception(other_exception)
      57           0 :         , msg("requested integer size exceeds type size: ")
      58             :     {
      59           0 :         msg += boost::lexical_cast<std::string, int>(invalid_size);
      60           0 :     }
      61             : 
      62             :     //! negative number in unsigned type
      63           0 :     DataStreamArchiveException()
      64           0 :         : boost::archive::archive_exception(other_exception)
      65           0 :         , msg("cannot read a negative number into an unsigned type")
      66             :     {
      67           0 :     }
      68             : 
      69             :     //! serialization of inf, nan and denormals
      70             :     template <typename T>
      71           0 :     explicit DataStreamArchiveException( const T& abnormal )
      72             :         : boost::archive::archive_exception(other_exception)
      73           0 :         , msg("serialization of illegal floating point value: ")
      74             :     {
      75           0 :         msg += boost::lexical_cast<std::string>(abnormal);
      76           0 :     }
      77             : 
      78             :     //! override the base class function with our message
      79           0 :     const char* what() const throw() { return msg.c_str(); }
      80           0 :     ~DataStreamArchiveException() throw() {}
      81             : };
      82             : 
      83             : }
      84             : 
      85             : #endif //CO_DATAOSTREAMARCHIVE_H

Generated by: LCOV version 1.11