X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=boost_ext%2Fboost%2Ftypeof%2Fint_encoding.hpp;fp=boost_ext%2Fboost%2Ftypeof%2Fint_encoding.hpp;h=552c250471ace49cf3b3ec06677de5b8cafa8d5c;hb=4123b4fe58a7fd4659fa01476581690b47c83600;hp=0000000000000000000000000000000000000000;hpb=79564b90f6c9f7cd0bc5b11a6146bb7067b11a75;p=senf.git diff --git a/boost_ext/boost/typeof/int_encoding.hpp b/boost_ext/boost/typeof/int_encoding.hpp new file mode 100644 index 0000000..552c250 --- /dev/null +++ b/boost_ext/boost/typeof/int_encoding.hpp @@ -0,0 +1,116 @@ +// Copyright (C) 2004 Arkadiy Vertleyb +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED +#define BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED + +#include +#include + +namespace boost { namespace type_of { + + template struct get_unsigned + { + typedef T type; + }; + template<> struct get_unsigned + { + typedef unsigned char type; + }; + template<> struct get_unsigned + { + typedef unsigned char type; + }; + template<> struct get_unsigned + { + typedef unsigned short type; + }; + template<> struct get_unsigned + { + typedef unsigned int type; + }; + template<> struct get_unsigned + { + typedef unsigned long type; + }; + + ////////////////////////// + + template + struct pack + { + enum {value = (n + 1) * 2 + (Overflow ? 1 : 0)}; + }; + + template + struct unpack + { + enum {value = (m / 2) - 1}; + enum {overflow = (m % 2 == 1)}; + }; + + //////////////////////////////// + + template= 0x3fffffff)> + struct encode_size_t : push_back< + V, + boost::mpl::size_t::value> + > + {}; + + template + struct encode_size_t : push_back::value> >::type, + boost::mpl::size_t + > + {}; + + template + struct encode_integral : encode_size_t< V, (typename get_unsigned::type)n,(((typename get_unsigned::type)n)>=0x3fffffff) > + {}; + + template + struct encode_integral : encode_size_t< V, b?1:0, false> + {}; + /////////////////////////// + + template + struct decode_size_t; + + template + struct decode_size_t + { + enum {value = n}; + typedef Iter iter; + }; + + template + struct decode_size_t + { + enum {m = Iter::type::value}; + + enum {value = (std::size_t)m * 0x3ffffffe + n}; + typedef typename Iter::next iter; + }; + + template + struct decode_integral + { + enum {m = Iter::type::value}; + + enum {n = unpack::value}; + + enum {overflow = unpack::overflow}; + + typedef typename Iter::next nextpos; + + static const T value = (T)(std::size_t)decode_size_t::value; + + typedef typename decode_size_t::iter iter; + }; + +}}//namespace + +#endif//BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED