本文整理汇总了C++中FileStreamPtr::write方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStreamPtr::write方法的具体用法?C++ FileStreamPtr::write怎么用?C++ FileStreamPtr::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStreamPtr
的用法示例。
在下文中一共展示了FileStreamPtr::write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveSpr
void SpriteManager::saveSpr(std::string fileName)
{
if(!m_loaded)
stdext::throw_exception("failed to save, spr is not loaded");
try {
FileStreamPtr fin = g_resources.createFile(fileName);
if(!fin)
stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));
fin->cache();
fin->addU32(m_signature);
if(g_game.getFeature(Otc::GameSpritesU32))
fin->addU32(m_spritesCount);
else
fin->addU16(m_spritesCount);
uint32 offset = fin->tell();
uint32 spriteAddress = offset + 4 * m_spritesCount;
for(int i = 1; i <= m_spritesCount; i++)
fin->addU32(0);
for(int i = 1; i <= m_spritesCount; i++) {
m_spritesFile->seek((i - 1) * 4 + m_spritesOffset);
uint32 fromAdress = m_spritesFile->getU32();
if(fromAdress != 0) {
fin->seek(offset + (i - 1) * 4);
fin->addU32(spriteAddress);
fin->seek(spriteAddress);
m_spritesFile->seek(fromAdress);
fin->addU8(m_spritesFile->getU8());
fin->addU8(m_spritesFile->getU8());
fin->addU8(m_spritesFile->getU8());
uint16 dataSize = m_spritesFile->getU16();
fin->addU16(dataSize);
char spriteData[SPRITE_DATA_SIZE];
m_spritesFile->read(spriteData, dataSize);
fin->write(spriteData, dataSize);
spriteAddress = fin->tell();
}
//TODO: Check for overwritten sprites.
}
fin->flush();
fin->close();
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
}
示例2: savePNG
void Image::savePNG(const std::string& fileName)
{
FileStreamPtr fin = g_resources.createFile(fileName);
if(!fin)
stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));
fin->cache();
std::stringstream data;
save_png(data, m_size.width(), m_size.height(), 4, (unsigned char*)getPixelData());
fin->write(data.str().c_str(), data.str().length());
fin->flush();
fin->close();
}
示例3: save
bool CSceneData::save(const std::string& file, f32 version)
{
if (m_objectList.empty())
{
LOG_ERROR("CSceneData::save: Object list empty, nothing save");
return false;
}
LOG_DEBUG("CSceneData::save: Serialize model to memory stream");
MemoryStreamPtr stream = CStreamManager::createMemoryStream();
stream->seekBeg(0);
stream->write(version);
stream->write(m_id);
stream->write(m_name);
if (!CSceneData::saveMaterial(stream))
{
LOG_ERROR("CSceneData::save: Material serialize failed");
return false;
}
if (!CSceneData::saveGeometry(stream))
{
LOG_ERROR("CSceneData::save: Geometry serialize failed");
return false;
}
LOG_DEBUG("CSceneData::save: Save memory stream to file stream [%s]. Size [%d]", file.c_str(), stream->size());
FileStreamPtr fileStream = CStreamManager::createFileStream(file, FileStream::e_create);
fileStream->write(stream->getData(), sizeof(u8), stream->size());
fileStream->close();
return true;
}