下面是一段ogre中的文件操作相关的源码

    DataStreamPtr FileSystemArchive::open(const String& filename) const
    {
        String full_path 
= concatenate_path(mName, filename);

        
// Use filesystem to determine size 
        
// (quicker than streaming to the end and back)
        struct stat tagStat;
    
int ret = stat(full_path.c_str(), &tagStat);
        assert(ret 
== 0 && "Problem getting file size" );

        
// Always open in binary mode
        std::ifstream *origStream = OGRE_NEW_T(std::ifstream, MEMCATEGORY_GENERAL)();
        origStream
->open(full_path.c_str(), std::ios::in | std::ios::binary);

        
// Should check ensure open succeeded, in case fail for some reason.
        if (origStream->fail())
        {
            OGRE_DELETE_T(origStream, basic_ifstream, MEMCATEGORY_GENERAL);
            OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
                
"Cannot open file: " + filename,
                
"FileSystemArchive::open");
        }

        
/// Construct return stream, tell it to delete on destroy
        FileStreamDataStream* stream = OGRE_NEW FileStreamDataStream(filename,
            origStream, tagStat.st_size, 
true);
        
return DataStreamPtr(stream);
    }

相关文章: