本文整理汇总了C++中TypedValue::getDataSize方法的典型用法代码示例。如果您正苦于以下问题:C++ TypedValue::getDataSize方法的具体用法?C++ TypedValue::getDataSize怎么用?C++ TypedValue::getDataSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypedValue
的用法示例。
在下文中一共展示了TypedValue::getDataSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: coerceValue
TypedValue CharType::coerceValue(const TypedValue &original_value,
const Type &original_type) const {
DCHECK(isCoercibleFrom(original_type))
<< "Can't coerce value of Type " << original_type.getName()
<< " to Type " << getName();
if (original_value.isNull()) {
return makeNullValue();
}
const void *original_data = original_value.getOutOfLineData();
const std::size_t original_data_size = original_value.getDataSize();
// VARCHAR always has a null-terminator. CHAR(X) has a null-terminator when
// string's length is less than X.
const bool null_terminated
= (original_type.getTypeID() == kVarChar)
|| (original_data_size < original_type.maximumByteLength())
|| (std::memchr(original_data, '\0', original_data_size) != nullptr);
if (original_data_size <= length_) {
if (null_terminated || (original_data_size == length_)) {
TypedValue value_copy(original_value);
value_copy.markType(kChar);
return value_copy;
} else {
// Need to make a new NULL-terminated copy of the string.
char *null_terminated_str = static_cast<char*>(std::malloc(original_data_size + 1));
std::memcpy(null_terminated_str, original_data, original_data_size);
null_terminated_str[original_data_size] = '\0';
return TypedValue::CreateWithOwnedData(kChar,
null_terminated_str,
original_data_size + 1);
}
} else {
// Need to truncate.
if (original_value.ownsOutOfLineData()) {
char *truncated_str = static_cast<char*>(std::malloc(length_));
std::memcpy(truncated_str, original_data, length_);
return TypedValue::CreateWithOwnedData(kChar, truncated_str, length_);
} else {
// Original is a reference, so we will just make a shorter reference.
return TypedValue(kChar, original_data, length_);
}
}
}