当前位置: 首页>>代码示例>>C++>>正文


C++ FileStream::read方法代码示例

本文整理汇总了C++中FileStream::read方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::read方法的具体用法?C++ FileStream::read怎么用?C++ FileStream::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileStream的用法示例。


在下文中一共展示了FileStream::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _load

void TerrainFile::_load( FileStream &stream )
{
   // NOTE: We read using a loop instad of in one large chunk
   // because the stream will do endian conversions for us when
   // reading one type at a time.

   stream.read( &mSize );

   // Load the heightmap.
   mHeightMap.setSize( mSize * mSize );
   for ( U32 i=0; i < mHeightMap.size(); i++ )
      stream.read( &mHeightMap[i] );

   // Load the layer index map.
   mLayerMap.setSize( mSize * mSize );
   for ( U32 i=0; i < mLayerMap.size(); i++ )
      stream.read( &mLayerMap[i] );

   // Get the material name count.
   U32 materialCount;
   stream.read( &materialCount );
   Vector<String> materials;
   materials.setSize( materialCount );

   // Load the material names.
   for ( U32 i=0; i < materialCount; i++ )
      stream.read( &materials[i] );

   // Resolve the TerrainMaterial objects from the names.
   _resolveMaterials( materials );
}
开发者ID:campadrenalin,项目名称:terminal-overload,代码行数:31,代码来源:terrFile.cpp

示例2: serve

void FileHandler::serve( Falcon::WOPI::Request* req )
{
   String sMimeType;

   // Get the document -- for now a very simple thing
   if ( ! m_client->options().findMimeType( m_sFile, sMimeType ) )
      sMimeType = "unknown";

   // Send the file
   Falcon::FileStat stats;
   if( ! Falcon::Sys::fal_stats( m_sFile, stats ) )
   {
      m_client->replyError( 403 );
      return;
   }

   FileStream fs;
   if( ! fs.open( m_sFile ) )
   {
      m_client->log()->log( LOGLEVEL_WARN, "Can't open file "+ m_sFile );
      m_client->replyError( 403 );
      return;
   }

   m_client->log()->log( LOGLEVEL_INFO, "Sending file "+ m_sFile );

   // ok we can serve the file
   String sReply = "HTTP/1.1 200 OK\r\n";

   TimeStamp now;
   now.currentTime();
   sReply += "Content-Type: " + sMimeType + "; charset=" + m_client->options().m_sTextEncoding + "\r\n";
   sReply += "Date: " + now.toRFC2822() + "\r\n";
   sReply += "Last-Modified: " + stats.m_mtime->toRFC2822() + "\r\n";

   sReply += "\r\n";
   // content length not strictly necessary now

   m_client->sendData( sReply );
   char buffer[4096];
   int len = fs.read( buffer, 4096 );
   while( len > 0 )
   {
      m_client->sendData( buffer, len );
      len = fs.read( buffer, 4096 );
   }

   if ( len < 0 )
   {
      // error!
      m_client->log()->log( LOGLEVEL_WARN, "Error while reading file "+ m_sFile );
      m_client->replyError( 403 );
   }
}
开发者ID:Klaim,项目名称:falcon,代码行数:54,代码来源:falhttpd_filehandler.cpp

示例3: _loadCollection

bool PxSingleActorData::_loadCollection( const UTF8 *path, bool isBinary )
{
   if ( physicsCollection )
   {
      NXU::releaseCollection( physicsCollection );
      physicsCollection = NULL;
   }

   FileStream fs;
   if ( !fs.open( path, Torque::FS::File::Read ) )
      return false;

   // Load the data into memory.
   U32 size = fs.getStreamSize();
   FrameTemp<U8> buff( size );
   fs.read( size, buff );

   // If the stream didn't read anything, there's a problem.
   if ( size <= 0 )
      return false;

   // Ok... try to load it.
   physicsCollection = NXU::loadCollection(  path, 
                                             isBinary ? NXU::FT_BINARY : NXU::FT_XML, 
                                             buff, 
                                             size );

   return physicsCollection != NULL;
}
开发者ID:adhistac,项目名称:ee-client-2-0,代码行数:29,代码来源:pxSingleActor.cpp

示例4: init

	void init(StartGameFunc startGame, StopGameFunc stopGame)
	{
		s_startGame = startGame;
		s_stopGame  = stopGame;

		for (u32 s=0; s<SOUND_COUNT; s++)
		{
			UI_Sound& sound = s_sounds[s];
			sound.filename = c_sounds[s];

			FileStream file;
			if (file.open(sound.filename, FileStream::MODE_READ))
			{
				sound.size = file.getSize();
				sound.data = malloc(sound.size);

				file.read((u8*)sound.data, sound.size);
				file.close();
			}
			else
			{
				sound.filename = NULL;
			}
		}

		UISystem::setMouseOverSound(&s_sounds[SOUND_MOUSEOVER]);
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:27,代码来源:gameUI.cpp

示例5: tex

FTGlyph::FTGlyph(FileStream & stream, char * data,
                 int x_offset, int y_offset,
                 int tex_width, int tex_height)
: tex(0)
{
    charcode = stream.read_uint32();
    float x1, y1, x2, y2;
    x1 = stream.read_float();
    y1 = stream.read_float();
    x2 = stream.read_float();
    y2 = stream.read_float();
    bBox = FTBBox(x1, y1, x2, y2);
    float advance_x, advance_y;
    advance_x = stream.read_float();
    advance_y = stream.read_float();
    advance = FTPoint(advance_x, advance_y);
    float corner_x, corner_y;
    corner_x = stream.read_float();
    corner_y = stream.read_float();
    corner = FTPoint(corner_x, corner_y);
    width = stream.read_int32();
    height = stream.read_int32();

    char * glyph = new char[width*height];
    stream.read(glyph, width * height);

    if (width && height) {
        if (y_offset + height > tex_height) {
            // copy subimage
            height = tex_height - y_offset;
        }
        if (height >= 0) {
            for (int y = 0; y < height; ++y) {
                for (int x = 0; x < width; ++x) {
                    char c = glyph[y * width + x];
                    data[(y + y_offset) * tex_width + x + x_offset] = c;
                }
            }
        }
    }

#ifdef USE_OUTLINE
    uv[0].X(float(x_offset - 1) / float(tex_width));
    uv[0].Y(float(y_offset - 1) / float(tex_height));
    uv[1].X(float(x_offset + width + 1) / float(tex_width));
    uv[1].Y(float(y_offset + height + 1) / float(tex_height));
#else
    uv[0].X(float(x_offset) / float(tex_width));
    uv[0].Y(float(y_offset) / float(tex_height));
    uv[1].X(float(x_offset + width) / float(tex_width));
    uv[1].Y(float(y_offset + height) / float(tex_height));
#endif

    delete[] glyph;
}
开发者ID:joaormatos,项目名称:anaconda,代码行数:55,代码来源:font.cpp

示例6: readIni

	bool readIni(const char* filename, ReadIniCallback callback, bool liberal)
	{
		if (!callback)
		{
			return false;
		}

		bool res = false;
		FileStream file;
		if ( file.open(filename, FileStream::MODE_READ) )
		{
			size_t size = file.getSize();
			char* fileData = new char[size+1];
			if (fileData)
			{
				file.read(fileData, (u32)size);
				res = true;
			}
			file.close();

			if (res)
			{
				const char* fileEnd = &fileData[size];
				char* readPos = fileData;

				//now read the data.
				while (1)
				{
					char keyName[512], keyValue[512];

					//we are done here.
					if (!getKey(&readPos, keyName, fileEnd))
					{
						break;
					}

					if (!readValue(&readPos, keyValue, fileEnd, liberal))
					{
						break;
					}

					//remove preceding or trailing spaces, remove exterior quotation marks.
					fixupString(keyName);
					fixupString(keyValue);

					res &= callback(keyName, keyValue);
				};
			}

			delete [] fileData;
		}

		return res;
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:54,代码来源:iniReader.cpp

示例7: outputPath

bool GFXD3D9Shader::_loadCompiledOutput( const Torque::Path &filePath, 
                                         const String &target, 
                                         GenericConstBufferLayout *bufferLayoutF, 
                                         GenericConstBufferLayout *bufferLayoutI,
                                         Vector<GFXShaderConstDesc> &samplerDescriptions )
{
   Torque::Path outputPath(filePath);
   outputPath.setExtension("csf");     // "C"ompiled "S"hader "F"ile (fancy!)

   FileStream f;
   if (!f.open(outputPath, Torque::FS::File::Read))
      return false;
   U32 fileTag;
   if (!f.read(&fileTag))
      return false;
   if (fileTag != smCompiledShaderTag)
      return false;
   if (!bufferLayoutF->read(&f))
      return false;
   if (!bufferLayoutI->read(&f))
      return false;
   U32 bufferSize;
   if (!f.read(&bufferSize))
      return false;
   U32 waterMark = FrameAllocator::getWaterMark();
   DWORD* buffer = static_cast<DWORD*>(FrameAllocator::alloc(bufferSize));
   if (!f.read(bufferSize, buffer))
      return false;

   // Read sampler descriptions.

   U32 samplerCount;
   f.read( &samplerCount );   

   for ( U32 i = 0; i < samplerCount; i++ )
   {
      GFXShaderConstDesc samplerDesc;
      f.read( &(samplerDesc.name) );
      f.read( (U32*)&(samplerDesc.constType) );
      f.read( &(samplerDesc.arraySize) );

      samplerDescriptions.push_back( samplerDesc );
   }

   f.close();

   HRESULT res;
   if (target.compare("ps_", 3) == 0)      
      res = mD3D9Device->CreatePixelShader(buffer, &mPixShader );
   else
      res = mD3D9Device->CreateVertexShader(buffer, &mVertShader );
   AssertFatal(SUCCEEDED(res), "Unable to load shader!");

   FrameAllocator::setWaterMark(waterMark);
   return SUCCEEDED(res);
}
开发者ID:AlkexGas,项目名称:Torque3D,代码行数:56,代码来源:gfxD3D9Shader.cpp

示例8: ReadRawData

	void* FileUtil::ReadRawData(const String& filepath, size_t &size)
	{
		FileStream file;
		if(!file.open(filepath))
			return 0;
		size = file.size();
		file.seek(0,Seek_begin);

		binary data = reinterpret_cast<binary>(base_malloc(sizeof(byte)*size));
		file.read(data,size);
		return data;
	}
开发者ID:EtcDot,项目名称:PomeloCpp,代码行数:12,代码来源:FileUtil.cpp

示例9: readColladaFile

domCOLLADA* ColladaShapeLoader::readColladaFile(const String& path)
{
   // Check if this file is already loaded into the database
   domCOLLADA* root = mDAE.getRoot(path.c_str());
   if (root)
      return root;

   // Load the Collada file into memory
   FileStream colladaFile;
   U8 *data = NULL;
   
   if (colladaFile.open(path, FileStream::Read))
   {
      U32 size = colladaFile.getStreamSize();
      data = (U8*)dMalloc(size);
      colladaFile.read(size, data);
   }
   
   if (!data)
   {
      daeErrorHandler::get()->handleError(avar("Could not read %s into memory", path.c_str()));
      return NULL;
   }

   root = mDAE.openFromMemory(path.c_str(), (const char*)data);
   dFree(data);
   
   if (!root || !root->getLibrary_visual_scenes_array().getCount()) {
      daeErrorHandler::get()->handleError(avar("Could not parse %s", path.c_str()));
      return NULL;
   }

   // Fixup issues in the model
   ColladaUtils::applyConditioners(root);

   // Recursively load external DAE references
   //TSShapeLoader::updateProgress(TSShapeLoader::Load_ExternalRefs, "Loading external references...");
   for (S32 iRef = 0; iRef < root->getDocument()->getReferencedDocuments().getCount(); iRef++) {
      String refPath = (daeString)root->getDocument()->getReferencedDocuments()[iRef];
      if (refPath.endsWith(".dae") && !readColladaFile(refPath))
         daeErrorHandler::get()->handleError(avar("Failed to load external reference: %s", refPath.c_str()));
   }
   return root;
}
开发者ID:jamesu,项目名称:libDTShape,代码行数:44,代码来源:colladaShapeLoader.cpp

示例10: vnmalloc

Variable_array * VariableScript::parse(const FilePath &file) {
    FileStream *fs = FileManager::instance().open(file);
    if (!fs) {
        _makeErrorMsg("open file \"%u:/%s\" failed!", file.fsId, file.fileName.c_str());
        return 0;
    }
    fs->seek(0, DataStream::kEnd);
    size_t size = (size_t)fs->tell();
    fs->seek(0);
    c8 *ptr = vnmalloc(c8, size);
    if (fs->read(ptr, size) != size) {
        _makeErrorMsg("read file \"%u:/%s\" failed!", file.fsId, file.fileName.c_str());
        fs->close();
        vnfree(ptr);
        return 0;
    }
    fs->close();
    
    c8 *txt = ptr;
    // utf8 bom
    if (strncmp(txt, "\xEF\xBB\xBF", 3) == 0) {
        txt += 3;
        size -= 3;
    }
    
    Token::File *tf = vnnew Token::File();
    c8 buf[512];
    int len = sprintf(buf, "%u:/%s", file.fsId, file.fileName.c_str());
    tf->name.assign(buf, len);
    
    Variable_array *ret = parse(txt, size, tf);
    
    vnfree(ptr);
    tf->drop();
    
    return ret;
}
开发者ID:signorinotang,项目名称:tools,代码行数:37,代码来源:vnVariableScript.cpp

示例11: openFile

bool Tokenizer::openFile(const char* pFileName)
{
   AssertFatal(mFileName[0] == '\0', "Reuse of Tokenizers not allowed!");

   FileStream* pStream = new FileStream;
   if (pStream->open(pFileName, Torque::FS::File::Read) == false)
   {
      delete pStream;
      return false;
   }
   dStrcpy(mFileName, pFileName);

   mBufferSize = pStream->getStreamSize();
   mpBuffer    = new char[mBufferSize];
   pStream->read(mBufferSize, mpBuffer);
   pStream->close();
   delete pStream;

   reset();

   buildLinePositions();

   return true;
}
开发者ID:03050903,项目名称:Torque3D,代码行数:24,代码来源:tokenizer.cpp

示例12: load

TerrainFile* TerrainFile::load( const Torque::Path &path )
{
   FileStream stream;

   stream.open( path.getFullPath(), Torque::FS::File::Read );
   if ( stream.getStatus() != Stream::Ok )
   {
      Con::errorf( "Resource<TerrainFile>::create - could not open '%s'", path.getFullPath().c_str() );
      return NULL;
   }

   U8 version;
   stream.read(&version);
   if (version > TerrainFile::FILE_VERSION)
   {
      Con::errorf( "Resource<TerrainFile>::create - file version '%i' is newer than engine version '%i'", version, TerrainFile::FILE_VERSION );
      return NULL;
   }

   TerrainFile *ret = new TerrainFile;
   ret->mFileVersion = version;
   ret->mFilePath = path;

   if ( version >= 7 )
      ret->_load( stream );
   else
      ret->_loadLegacy( stream );

   // Update the collision structures.
   ret->_buildGridMap();
   
   // Do the material mapping.
   ret->_initMaterialInstMapping();
   
   return ret;
}
开发者ID:campadrenalin,项目名称:terminal-overload,代码行数:36,代码来源:terrFile.cpp

示例13: run

    void run()
    {
        bool doDecode = false;

        static const int samples = 450*1024;
        static const int inputBufferSize = samples;
        static const int sampleSpaceBefore = 256;
        static const int sampleSpaceAfter = 256;

        FileStream in = File("captured.zdr", true).openRead();
        UInt64 inputFileSizeRemaining = in.size();
        Array<Byte> inputBuffer(inputBufferSize);
        int inputBufferRemaining = 0;
        Byte* inputPointer = 0;
        z_stream zs;
        memset(&zs, 0, sizeof(z_stream));
        if (inflateInit(&zs) != Z_OK)
            throw Exception("inflateInit failed");

        Array<Byte> buffer(sampleSpaceBefore + samples + sampleSpaceAfter);
        Byte* b = &buffer[0] + sampleSpaceBefore;
        for (int i = 0; i < sampleSpaceBefore; ++i)
            b[i - sampleSpaceBefore] = 0;
        for (int i = 0; i < sampleSpaceAfter; ++i)
            b[i + samples] = 0;
        int outputBytesRemaining = samples;

        Vector outputSize;
        NTSCCaptureDecoder<UInt32> decoder;

        if (doDecode)
            outputSize = Vector(960, 240);
        else
            outputSize = Vector(1824, 253);
        Bitmap<UInt32> decoded(outputSize);
        decoder.setOutputBuffer(decoded);
        decoded.fill(0);
        decoder.setInputBuffer(b);
        decoder.setOutputPixelsPerLine(1140);
        decoder.setYScale(1);
        decoder.setDoDecode(doDecode);

        FileStream outputStream = File("u:\\captured.bin", true).openWrite();

        do {
            if (inputBufferRemaining == 0) {
                int bytesToRead = inputBufferSize;
                if (bytesToRead > inputFileSizeRemaining)
                    bytesToRead = inputFileSizeRemaining;
                inputPointer = &inputBuffer[0];
                in.read(inputPointer, bytesToRead);
                inputBufferRemaining = bytesToRead;
                inputFileSizeRemaining -= bytesToRead;
            }
            zs.avail_in = inputBufferRemaining;
            zs.next_in = inputPointer;
            zs.avail_out = outputBytesRemaining;
            zs.next_out = b + samples - outputBytesRemaining;
            int r = inflate(&zs, Z_SYNC_FLUSH);
            if (r != Z_STREAM_END && r != Z_OK)
                throw Exception("inflate failed");
            outputBytesRemaining = zs.avail_out;
            inputPointer = zs.next_in;
            inputBufferRemaining = zs.avail_in;

            if (outputBytesRemaining == 0) {
                if (inflateReset(&zs) != Z_OK)
                    throw Exception("inflateReset failed");
                outputBytesRemaining = samples;
                console.write(".");

                if (doDecode) {
                    decoder.decode();
                    outputStream.write(decoded.data(), decoded.stride()*outputSize.y);
                }
                else
                    outputStream.write(b, 1824*253);
            }

        } while (inputFileSizeRemaining != 0);

        if (inflateEnd(&zs) != Z_OK)
            throw Exception("inflateEnd failed");
    }
开发者ID:reenigne,项目名称:reenigne,代码行数:84,代码来源:captobin.cpp

示例14: cb_read

size_t OggSoundFile::cb_read(void* ptr, size_t size, size_t nmemb, void* source)
{
    FileStream *file = static_cast<FileStream*>(source);
    return file->read(ptr, size, nmemb);
}
开发者ID:Cayan,项目名称:otclient,代码行数:5,代码来源:oggsoundfile.cpp

示例15:

Workspace::Workspace(FileStream & stream)
{
    stream.read_c_string(name);
    stream.read(data, stream.read_uint32());
}
开发者ID:mattl,项目名称:anaconda,代码行数:5,代码来源:binaryarray.cpp


注:本文中的FileStream::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。