本文整理汇总了C++中AString::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::resize方法的具体用法?C++ AString::resize怎么用?C++ AString::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::resize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UncompressString
int UncompressString(const char * a_Data, size_t a_Length, AString & a_Uncompressed, size_t a_UncompressedSize)
{
// HACK: We're assuming that AString returns its internal buffer in its data() call and we're overwriting that buffer!
// It saves us one allocation and one memcpy of the entire compressed data
// It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010)
a_Uncompressed.resize(a_UncompressedSize);
uLongf UncompressedSize = static_cast<uLongf>(a_UncompressedSize); // On some architectures the uLongf is different in size to int, that may be the cause of the -5 error
int errorcode = uncompress(reinterpret_cast<Bytef *>(const_cast<char *>(a_Uncompressed.data())), &UncompressedSize, reinterpret_cast<const Bytef *>(a_Data), static_cast<uLong>(a_Length));
if (errorcode != Z_OK)
{
return errorcode;
}
a_Uncompressed.resize(UncompressedSize);
return Z_OK;
}
示例2: Read
AString cFile::Read(size_t a_NumBytes)
{
ASSERT(IsOpen());
if (!IsOpen())
{
return AString();
}
// HACK: This depends on the knowledge that AString::data() returns the internal buffer, rather than a copy of it.
AString res;
res.resize(a_NumBytes);
auto newSize = fread(const_cast<char *>(res.data()), 1, a_NumBytes, m_File);
res.resize(newSize);
return res;
}
示例3: CompressString
int CompressString(const char * a_Data, size_t a_Length, AString & a_Compressed, int a_Factor)
{
uLongf CompressedSize = compressBound(static_cast<uLong>(a_Length));
// HACK: We're assuming that AString returns its internal buffer in its data() call and we're overwriting that buffer!
// It saves us one allocation and one memcpy of the entire compressed data
// It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010)
a_Compressed.resize(CompressedSize);
int errorcode = compress2(reinterpret_cast<Bytef *>(const_cast<char *>(a_Compressed.data())), &CompressedSize, reinterpret_cast<const Bytef *>(a_Data), static_cast<uLong>(a_Length), a_Factor);
if (errorcode != Z_OK)
{
return errorcode;
}
a_Compressed.resize(CompressedSize);
return Z_OK;
}
示例4: ParseItemMetadata
int cProtocol132::ParseItem(cItem & a_Item)
{
HANDLE_PACKET_READ(ReadBEShort, short, ItemType);
if (ItemType <= -1)
{
a_Item.Empty();
return PARSE_OK;
}
a_Item.m_ItemType = ItemType;
HANDLE_PACKET_READ(ReadChar, char, ItemCount);
HANDLE_PACKET_READ(ReadBEShort, short, ItemDamage);
a_Item.m_ItemCount = ItemCount;
a_Item.m_ItemDamage = ItemDamage;
if (ItemCount <= 0)
{
a_Item.Empty();
}
HANDLE_PACKET_READ(ReadBEShort, short, MetadataLength);
if (MetadataLength <= 0)
{
return PARSE_OK;
}
// Read the metadata
AString Metadata;
Metadata.resize((size_t)MetadataLength);
if (!m_ReceivedData.ReadBuf((void *)Metadata.data(), (size_t)MetadataLength))
{
return PARSE_INCOMPLETE;
}
return ParseItemMetadata(a_Item, Metadata);
}