本文整理汇总了C++中DataChunk::Resize方法的典型用法代码示例。如果您正苦于以下问题:C++ DataChunk::Resize方法的具体用法?C++ DataChunk::Resize怎么用?C++ DataChunk::Resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataChunk
的用法示例。
在下文中一共展示了DataChunk::Resize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Base_ReadDataFrom
/*! \param Offset Offset from the start of the KLV value from which to start reading
* \param Size Number of bytes to read, if -1 all available bytes will be read (which could be billions!)
* \return The number of bytes read
*
* DRAGONS: This base function may be called from derived class objects to get base behaviour.
* It is therefore vital that the function does not call any "virtual" KLVObject
* functions, directly or indirectly.
*/
size_t KLVObject::Base_ReadDataFrom(DataChunk &Buffer, Position Offset, size_t Size /*=-1*/)
{
// Delagate to ReadHandler if defined
if(ReadHandler) return ReadHandler->ReadData(Buffer, this, Offset, Size);
if(Source.Offset < 0)
{
error("Call to KLVObject::Base_ReadDataFrom() with no read handler defined and DataBase undefined\n");
return 0;
}
if(!Source.File)
{
error("Call to KLVObject::Base_ReadDataFrom() with no read handler defined and source file not set\n");
return 0;
}
// Initially plan to read all the bytes available
Length BytesToRead = Source.OuterLength - Offset;
// Limit to specified size if > 0 and if < available
if( (Size > 0) && (Size < BytesToRead)) BytesToRead = Size;
// Don't do anything if nothing to read
if(BytesToRead <= 0)
{
Buffer.Resize(0);
return 0;
}
// Sanity check the size of this read
if((sizeof(size_t) < 8) && (BytesToRead > 0xffffffff))
{
error("Tried to read > 4GBytes, but this platform can only handle <= 4GByte chunks\n");
return 0;
}
// Seek to the start of the requested data
Source.File->Seek(Source.Offset + Source.KLSize + Offset);
// Resize the chunk
// Discarding old data first (by setting Size to 0) prevents old data being
// copied needlessly if the buffer is reallocated to increase its size
Buffer.Size = 0;
Buffer.Resize(static_cast<size_t>(BytesToRead));
// Read into the buffer (only as big as the buffer is!)
size_t Bytes = Source.File->Read(Buffer.Data, Buffer.Size);
// Resize the buffer if something odd happened (such as an early end-of-file)
if(Bytes != static_cast<size_t>(BytesToRead)) Buffer.Resize(Bytes);
return Bytes;
}