本文整理汇总了C++中DiskFile::read方法的典型用法代码示例。如果您正苦于以下问题:C++ DiskFile::read方法的具体用法?C++ DiskFile::read怎么用?C++ DiskFile::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiskFile
的用法示例。
在下文中一共展示了DiskFile::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
//-----------------------------------------------------------------------------
void* TextResource::load(Allocator& allocator, Bundle& bundle, ResourceId id)
{
DiskFile* stream = bundle.open(id);
CE_ASSERT(stream != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
TextResource* resource = (TextResource*)allocator.allocate(sizeof(TextResource));
stream->read(&resource->length, sizeof(uint32_t));
resource->data = (char*)allocator.allocate(sizeof(char) * (resource->length + 1));
stream->read(resource->data, (size_t)resource->length);
resource->data[resource->length] = '\0';
bundle.close(stream);
return resource;
}
示例2: open
//-----------------------------------------------------------------------------
DiskFile* FileBundle::open(ResourceId name)
{
// Convert name/type into strings
char resource_name[512];
snprintf(resource_name, 512, "%.8X%.8X", name.name, name.type);
// Search the resource in the filesystem
bool exists = m_filesystem.exists(resource_name);
CE_ASSERT(exists == true, "Resource does not exist: %s", resource_name);
// Open the resource and check magic number/version
DiskFile* file = (DiskFile*)m_filesystem.open(resource_name, FOM_READ);
ResourceHeader header;
file->read(&header, sizeof(ResourceHeader));
CE_ASSERT(header.magic == RESOURCE_MAGIC_NUMBER, "Resource is not valid: %s", resource_name);
CE_ASSERT(header.version == RESOURCE_VERSION, "Resource version mismatch: %s", resource_name);
return file;
}