]> git.lyx.org Git - lyx.git/blobdiff - boost/boost/crc.hpp
Don't allow newline characters in document settings.
[lyx.git] / boost / boost / crc.hpp
index 272482964ffb896b2d95942272d765a056f8759e..6be5aa1d8b1bef83fd99fe63b0553d1c96189d81 100644 (file)
@@ -1,11 +1,10 @@
 //  Boost CRC library crc.hpp header file  -----------------------------------//
 
-//  (C) Copyright Daryle Walker 2001.  Permission to copy, use, modify, sell and
-//  distribute this software is granted provided this copyright notice appears 
-//  in all copies.  This software is provided "as is" without express or
-//  implied warranty, and with no claim as to its suitability for any purpose. 
+//  Copyright 2001, 2004 Daryle Walker.  Use, modification, and distribution are
+//  subject to the Boost Software License, Version 1.0.  (See accompanying file
+//  LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
 
-//  See http://www.boost.org for updates, documentation, and revision history. 
+//  See <http://www.boost.org/libs/crc/> for the library's home page.
 
 #ifndef BOOST_CRC_HPP
 #define BOOST_CRC_HPP
@@ -38,7 +37,7 @@
 // arguments explicitly specified.  At least one compiler that needs this
 // workaround also needs the default value for the dummy argument to be
 // specified in the definition.
-#ifndef BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
+#if defined(__GNUC__) || !defined(BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
 #define BOOST_CRC_DUMMY_PARM_TYPE
 #define BOOST_CRC_DUMMY_INIT
 #define BOOST_ACRC_DUMMY_PARM_TYPE
@@ -280,10 +279,15 @@ namespace detail
         typedef typename base_type::least  least;
         typedef typename base_type::fast   fast;
 
+#if defined(__EDG_VERSION__) && __EDG_VERSION__ <= 243
+        static const least high_bit = 1ul << ( Bits - 1u );
+        static const fast high_bit_fast = 1ul << ( Bits - 1u );
+#else
         BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << ( Bits
          - 1u )) );
         BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << ( Bits
          - 1u )) );
+#endif
 
     };  // boost::detail::high_uint_t
 
@@ -340,9 +344,17 @@ namespace detail
         BOOST_STATIC_CONSTANT( fast, high_bit_fast = base_type::high_bit_fast );
         #endif
 
+#if defined(__EDG_VERSION__) && __EDG_VERSION__ <= 243
+        static const least sig_bits = (~( ~( 0ul ) << Bits )) ;
+#else
         BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
+#endif
+#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 2
+        // Work around a weird bug that ICEs the compiler in build_c_cast
+        BOOST_STATIC_CONSTANT( fast, sig_bits_fast = static_cast<fast>(sig_bits) );
+#else
         BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
-
+#endif
     };  // boost::detail::mask_uint_t
 
     template <  >
@@ -450,8 +462,12 @@ namespace detail
         typedef typename masking_type::fast  value_type;
 #if defined(__BORLANDC__) && defined(_M_IX86) && (__BORLANDC__ == 0x560)
         // for some reason Borland's command line compiler (version 0x560)
-        // chokes over this unless we do the calculation for it: 
+        // chokes over this unless we do the calculation for it:
         typedef value_type                   table_type[ 0x100 ];
+#elif defined(__GNUC__)
+        // old versions of GCC (before 4.0.2) choke on using byte_combos
+        // as a constant expression when compiling with -pedantic.
+        typedef value_type                   table_type[1ul << CHAR_BIT];
 #else
         typedef value_type                   table_type[ byte_combos ];
 #endif
@@ -519,6 +535,30 @@ namespace detail
         did_init = true;
     }
 
+    #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+    // Align the msb of the remainder to a byte
+    template < std::size_t Bits, bool RightShift >
+    class remainder
+    {
+    public:
+        typedef typename uint_t<Bits>::fast  value_type;
+
+        static unsigned char align_msb( value_type rem )
+            { return rem >> (Bits - CHAR_BIT); }
+    };
+
+    // Specialization for the case that the remainder has less
+    // bits than a byte: align the remainder msb to the byte msb
+    template < std::size_t Bits >
+    class remainder< Bits, false >
+    {
+    public:
+        typedef typename uint_t<Bits>::fast  value_type;
+
+        static unsigned char align_msb( value_type rem )
+            { return rem << (CHAR_BIT - Bits); }
+    };
+    #endif
 
     // CRC helper routines
     template < std::size_t Bits, bool DoReflect >
@@ -547,7 +587,9 @@ namespace detail
 
         // Compare a byte to the remainder's highest byte
         static  unsigned char  index( value_type rem, unsigned char x )
-            { return x ^ ( rem >> (DoReflect ? 0u : Bits - CHAR_BIT) ); }
+            { return x ^ ( DoReflect ? rem :
+                                ((Bits>CHAR_BIT)?( rem >> (Bits - CHAR_BIT) ) :
+                                    ( rem << (CHAR_BIT - Bits) ))); }
 
         // Shift out the remainder's highest byte
         static  value_type  shift( value_type rem )
@@ -570,7 +612,7 @@ namespace detail
 
         // Compare a byte to the remainder's highest byte
         static  unsigned char  index( value_type rem, unsigned char x )
-            { return x ^ ( rem >> (Bits - CHAR_BIT) ); }
+            { return x ^ remainder<Bits,(Bits>CHAR_BIT)>::align_msb( rem ); }
 
         // Shift out the remainder's highest byte
         static  value_type  shift( value_type rem )
@@ -698,7 +740,7 @@ crc_basic<Bits>::process_bit
     // a full polynominal division step is done when the highest bit is one
     bool const  do_poly_div = static_cast<bool>( rem_ & high_bit_mask );
 
-    // shift out the highest bit 
+    // shift out the highest bit
     rem_ <<= 1;
 
     // carry out the division, if needed