Пример #1
0
    static inline
    asio::ip::tcp::endpoint
    cast(const From& endpoint) {
        switch (endpoint.protocol().family()) {
        case AF_INET: {
            const sockaddr_in* addr = reinterpret_cast<const sockaddr_in*>(endpoint.data());
            asio::ip::address_v4::bytes_type array;
            std::copy((char*)&addr->sin_addr, (char*)&addr->sin_addr + array.size(), array.begin());
            asio::ip::address_v4 address(array);
            return asio::ip::tcp::endpoint(
                       address,
                       asio::detail::socket_ops::network_to_host_short(addr->sin_port)
                   );
        }
        case AF_INET6: {
            const sockaddr_in6* addrv6 = reinterpret_cast<const sockaddr_in6*>(endpoint.data());
            asio::ip::address_v6::bytes_type array;
            std::copy((char*)&addrv6->sin6_addr, (char*)&addrv6->sin6_addr + array.size(), array.begin());
            asio::ip::address_v6 address(array, addrv6->sin6_scope_id);
            return asio::ip::tcp::endpoint(
                       address,
                       asio::detail::socket_ops::network_to_host_short(addrv6->sin6_port)
                   );
        }
        default:
            BOOST_ASSERT(false);
        };

        return asio::ip::tcp::endpoint();
    }
Пример #2
0
bool move(To& to, From& from) {
    if (CFGetTypeID(from.c_obj()) == To::type_id()) {
        to.reset(reinterpret_cast<typename To::type>(from.release()));
        return true;
    }
    return false;
}
Пример #3
0
 To operator ()(From &arr) const
 {
     typename remove_const<To>::type res(arr.size());
     for(std::size_t i = 0, size = arr.size(); i != size; ++i)
     {
         res[i] = numeric::promote<typename To::value_type>(arr[i]);
     }
     return res;
 }
Пример #4
0
 std::vector< char > get_block(
     std::vector<char>::const_iterator prefix_begin, std::vector<char>::const_iterator prefix_end,
     const From &from_string, typename From::size_type head_pos ) {
     typename From::size_type block_size = std::min( from_string.size() * sizeof( typename From::value_type ) - head_pos, block_size );
     std::vector< char > block( prefix_begin, prefix_end );
     block.resize( block.size() + block_size );
     std::vector< char >::iterator output_head = block.begin();
     std::advance( output_head, std::distance( prefix_begin, prefix_end ) );
     std::copy( reinterpret_cast<const char*>( from_string.c_str() ) + head_pos, reinterpret_cast<const char*>( from_string.c_str() ) + head_pos + block_size, output_head );
     return block;
 }
void test_convert_imp(boost::mpl::int_<number_kind_integer> const&, boost::mpl::int_<number_kind_integer> const&)
{
   int bits_wanted = (std::min)((std::min)(std::numeric_limits<From>::digits, std::numeric_limits<To>::digits), 2000);

   for(unsigned i = 0; i < 100; ++i)
   {
      From from = generate_random<From>(bits_wanted);
      To t1(from);
      To t2 = from.template convert_to<To>();
      BOOST_CHECK_EQUAL(from.str(), t1.str());
      BOOST_CHECK_EQUAL(from.str(), t2.str());
      test_convert_neg_int<From, To>(from, boost::mpl::bool_<std::numeric_limits<From>::is_signed && std::numeric_limits<To>::is_signed>());
   }
}
void test_convert_neg_rat(From from, const boost::mpl::true_&)
{
   from = -from;
   To t3(from);
   To t4 = from.template convert_to<To>();
   BOOST_CHECK_EQUAL(from.str(), numerator(t3).str());
   BOOST_CHECK_EQUAL(from.str(), numerator(t4).str());
}
void test_convert_neg_int(From from, const boost::mpl::true_&)
{
   from = -from;
   To t3(from);
   To t4 = from.template convert_to<To>();
   BOOST_CHECK_EQUAL(from.str(), t3.str());
   BOOST_CHECK_EQUAL(from.str(), t4.str());
}
Пример #8
0
    static inline
    std::string
    cast(const From& endpoint) {
        // TODO: Это пиздец.
        switch (endpoint.protocol().family()) {
        case AF_INET:
        case AF_INET6:
            return boost::lexical_cast<std::string>(endpoint_traits<asio::ip::tcp::endpoint>::cast(endpoint));
        case AF_UNIX: {
            const sockaddr_un* addr = (const sockaddr_un*)(endpoint.data());
            return std::string(addr->sun_path);
        }
        default:
            break;
        };

        return "<unknown protocol type>";
    }
void test_convert_neg_float(From from, const boost::mpl::true_&)
{
   from = -from;
   To t3(from);
   To t4 = from.template convert_to<To>();
   To check(from.str() + ".0");
   BOOST_CHECK_EQUAL(t3, check);
   BOOST_CHECK_EQUAL(t4, check);
}
Пример #10
0
    To operator()( const From &from_string ) {
        To to_string;
        typename From::size_type head_pos = 0;
        std::vector< char > partial_sequence;
        while( 1 ) {
            const std::vector< char > input_block = get_block( partial_sequence.begin(), partial_sequence.end(), from_string, head_pos );
            head_pos += input_block.size() - partial_sequence.size();
            const std::pair< std::vector< char >, std::vector< char > > output_block = convert_block< block_size >( cd, input_block );
            const To temp = set_block( output_block.first );
            partial_sequence = output_block.second;
            to_string += temp;
            if( head_pos == from_string.size() * sizeof( typename From::value_type ) )
                break;

        }
        return to_string;
    }
Пример #11
0
void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_floating_point>& /*to_type*/, const mpl::int_<number_kind_floating_point>& /*from_type*/)
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
   //
   // The code here only works when the radix of "From" is 2, we could try shifting by other
   // radixes but it would complicate things.... use a string conversion when the radix is other
   // than 2:
   //
   if(std::numeric_limits<number<From> >::radix != 2)
   {
      to = from.str(0, std::ios_base::fmtflags()).c_str();
      return;
   }


   typedef typename canonical<unsigned char, To>::type ui_type;

   using default_ops::eval_fpclassify;
   using default_ops::eval_add;
   using default_ops::eval_subtract;
   using default_ops::eval_convert_to;

   //
   // First classify the input, then handle the special cases:
   //
   int c = eval_fpclassify(from);

   if(c == FP_ZERO)
   {
      to = ui_type(0);
      return;
   }
   else if(c == FP_NAN)
   {
      to = "nan";
      return;
   }
   else if(c == FP_INFINITE)
   {
      to = "inf";
      if(eval_get_sign(from) < 0)
         to.negate();
      return;
   }

   typename From::exponent_type e;
   From f, term;
   to = ui_type(0);

   eval_frexp(f, from, &e);

   static const int shift = std::numeric_limits<boost::intmax_t>::digits - 1;

   while(!eval_is_zero(f))
   {
      // extract int sized bits from f:
      eval_ldexp(f, f, shift);
      eval_floor(term, f);
      e -= shift;
      eval_ldexp(to, to, shift);
      typename boost::multiprecision::detail::canonical<boost::intmax_t, To>::type ll;
      eval_convert_to(&ll, term);
      eval_add(to, ll);
      eval_subtract(f, term);
   }
   typedef typename To::exponent_type to_exponent;
   if((e > (std::numeric_limits<to_exponent>::max)()) || (e < (std::numeric_limits<to_exponent>::min)()))
   {
      to = "inf";
      if(eval_get_sign(from) < 0)
         to.negate();
      return;
   }
   eval_ldexp(to, to, static_cast<to_exponent>(e));
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
Пример #12
0
To duration_cast(From const& dt) {
  return To(From::period::num * dt.count(), From::period::den);
}
Пример #13
0
To cast(From from) {
    if (CFGetTypeID(from.c_obj()) == To::type_id()) {
        return To(reinterpret_cast<typename To::type>(from.release()));
    }
    return nullptr;
}
Пример #14
0
void vchar2string(To& t,From& f)
{
	t.assign(f.begin(),f.end());
}
Пример #15
0
 To operator()(const From& x) const {
   return x.get();
 }
Пример #16
0
 To operator()(const From& x) const {
   return {x.get_locked(), false};
 }
Пример #17
0
 // Pass by reference for lvalue of 'move_ptr'.
 // Also note 'auto_ptr' isn't copy-initializable from one which has
 // a different 'element_type'. See http://tinyurl.com/yo8a7w (defect report #84).
 template< class To, class From > inline
 To move_to(From& from)
 {
     return To(from.release());
 }