本文整理汇总了C++中type::create_variant方法的典型用法代码示例。如果您正苦于以下问题:C++ type::create_variant方法的具体用法?C++ type::create_variant怎么用?C++ type::create_variant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类type
的用法示例。
在下文中一共展示了type::create_variant方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convert
//.........这里部分代码省略.........
target_var = value;
}
else if (target_type == type::get<int16_t>())
{
int16_t value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<int32_t>())
{
int32_t value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<int64_t>())
{
int64_t value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<uint8_t>())
{
uint8_t value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<uint16_t>())
{
uint16_t value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<uint32_t>())
{
uint32_t value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<uint64_t>())
{
uint64_t value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<float>())
{
float value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == type::get<double>())
{
double value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = value;
}
else if (target_type == string_type)
{
std::string value;
if ((ok = try_basic_type_conversion(value)) == true)
target_var = std::move(value);
}
}
else if ((source_is_arithmetic || source_type == string_type)
&& target_type.is_enumeration())
{
variant var = target_type;
auto wrapper = std::ref(var);
if ((ok = try_basic_type_conversion(wrapper)) == true)
target_var = std::move(var);
}
else
{
if (const auto& converter = source_type.get_type_converter(target_type))
{
void* ptr = get_ptr();
target_var = converter->to_variant(ptr, ok);
}
else if (target_type == type::get<std::nullptr_t>() && is_nullptr())
{
target_var = nullptr;
ok = true;
}
else if (source_type.is_pointer() &&
(source_type.get_pointer_dimension() == 1 && target_type.get_pointer_dimension() == 1))
{
void* raw_ptr = get_raw_ptr();
if (void* casted_ptr = type::apply_offset(raw_ptr, source_type, target_type))
{
// although we forward a void* to create a variant,
// it will create a variant for the specific class type
target_var = target_type.create_variant(casted_ptr);
if (target_var.is_valid())
ok = true;
}
}
}
return ok;
}