本文整理汇总了C++中DataChunk::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ DataChunk::reserve方法的具体用法?C++ DataChunk::reserve怎么用?C++ DataChunk::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataChunk
的用法示例。
在下文中一共展示了DataChunk::reserve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ABC_ERROR
Status
chunkDecode(DataChunk &result, const std::string &in)
{
// The string must be a multiple of the chunk size:
if (in.size() % Chars)
return ABC_ERROR(ABC_CC_ParseError, "Bad encoding");
DataChunk out;
out.reserve(Bytes * (in.size() / Chars));
constexpr unsigned shift = 8 * Bytes / Chars; // Bits per character
uint16_t buffer = 0; // Bits waiting to be written out, MSB first
int bits = 0; // Number of bits currently in the buffer
auto i = in.begin();
while (i != in.end())
{
// Read one character from the string:
int value = Decode(*i);
if (value < 0)
break;
++i;
// Append the bits to the buffer:
buffer |= value << (16 - bits - shift);
bits += shift;
// Write out some bits if the buffer has a byte's worth:
if (8 <= bits)
{
out.push_back(buffer >> 8);
buffer <<= 8;
bits -= 8;
}
}
示例2:
DataChunk
buildData(std::initializer_list<DataSlice> slices)
{
size_t size = 0;
for (auto slice: slices)
size += slice.size();
DataChunk out;
out.reserve(size);
for (auto slice: slices)
out.insert(out.end(), slice.begin(), slice.end());
return out;
}