本文整理汇总了C++中object::ptr::type_id方法的典型用法代码示例。如果您正苦于以下问题:C++ ptr::type_id方法的具体用法?C++ ptr::type_id怎么用?C++ ptr::type_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object::ptr
的用法示例。
在下文中一共展示了ptr::type_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: int_object_to_signed_long
signed long long vanilla::int_object_to_signed_longlong(object::ptr const& obj)
{
#if LLONG_MAX == LONG_MAX
return int_object_to_signed_long(obj);
#endif
if(obj->type_id() != OBJECT_ID_INT)
{
BOOST_THROW_EXCEPTION(error::bad_cast_error()
<< error::first_operand(obj)
<< error::cast_target_name("int"));
}
mpz_t& mpz = static_cast<int_object const*>(obj.get())->value().mpz();
if(mpz_sizeinbase(mpz, 2) + 1 > sizeof(long long) * CHAR_BIT)
{
BOOST_THROW_EXCEPTION(error::integer_conversion_overflow_error()
<< error::first_operand(obj)
<< error::integer_conversion_target_type("signed long long"));
}
size_t count = 0;
long long result = 0;
mpz_export(&result, &count, -1, sizeof(result), 0, 0, mpz);
assert(count == 1);
return result;
}
示例2: lhs
vanilla::object::ptr vanilla::int_object::neq(object::ptr const& other)
{
switch(other->type_id())
{
case OBJECT_ID_INT:
{
int_object const* rhs = static_cast<int_object const*>(other.get());
int result = mpz_cmp(_v.mpz(), rhs->value().mpz());
return allocate_object<bool_object>(result != 0);
}
case OBJECT_ID_FLOAT:
{
float_object const* rhs = static_cast<float_object const*>(other.get());
if(!mpf_integer_p(rhs->value().mpf()))
return allocate_object<bool_object>(true);
float_object::float_type lhs( (_v.mpz()) );
return allocate_object<bool_object>(mpf_cmp(lhs.mpf(), rhs->value().mpf()) != 0);
}
default:
{
return object::ge(other);
}
}
}
示例3: float_object_to_double
double vanilla::float_object_to_double(object::ptr const& obj)
{
if(obj->type_id() != OBJECT_ID_FLOAT)
{
BOOST_THROW_EXCEPTION(error::bad_cast_error()
<< error::first_operand(obj)
<< error::cast_target_name("float"));
}
mpf_t& mpf = static_cast<float_object const*>(obj.get())->value().mpf();
double result = mpf_get_d(mpf);
if(std::numeric_limits<double>::has_infinity &&
result == std::numeric_limits<double>::infinity())
{
BOOST_THROW_EXCEPTION(error::float_conversion_overflow_error()
<< error::first_operand(obj)
<< error::float_conversion_target_type("double"));
}
return result;
}