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


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

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


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

示例1: logValue

/**
 * logValue() Information
 *
 * This function writes data to the log file.
 */
static void logValue(String label, Uint16 value)
{
    // open file
    dataFile.open("dataLog.txt");

    // determine label length
    int size = 0;
    String temp = label;

    for(temp = label; *temp; ++temp)
    {
        ++size;
    }

    // write label
    dataFile.write((Byte*)label, size); // to suppress compiler warning

    // convert value
    char dataString[8] = {"0x0000\n"};
    static const char toHex[] = {"0123456789ABCDEF"};

    dataString[2] = toHex[(value & 0xF000) >> 12];
    dataString[3] = toHex[(value & 0x0F00) >> 8];
    dataString[4] = toHex[(value & 0x00F0) >> 4];
    dataString[5] = toHex[(value & 0x000F)];

    // write value
    dataFile.write((Byte*)dataString, 7); // to suppress compiler warning

    // close file
    dataFile.close();
}
开发者ID:ISSCentaurus,项目名称:MGE,代码行数:37,代码来源:datalog.c

示例2: init

   /// Open the file and emit a row with the names of all enabled keys.
   virtual bool init( const char* fileName )
   {
      if( !mStream.open( fileName, Torque::FS::File::Write ) )
      {
         Con::errorf( "CSVSamplerBackend::init -- could not open '%s' for writing", fileName );
         return false;
      }

      Con::printf( "CSVSamplerBackend::init -- writing samples to '%s'", fileName );

      bool first = true;
      for( U32 i = 0; i < gSampleKeys.size(); ++ i )
      {
         SampleKey& key = gSampleKeys[ i ];
         if( key.mEnabled )
         {
            if( !first )
               mStream.write( 1, "," );

            mRecords.push_back( SampleRecord( i + 1 ) );
            mStream.write( dStrlen( key.mName ), key.mName );
            first = false;
         }
      }

      newline();
      return true;
   }
开发者ID:fr1tz,项目名称:terminal-overload,代码行数:29,代码来源:sampler.cpp

示例3: write

	void write(LogMessageType type, const char* msg, ...)
	{
	#if XL_LOGGING_ENABLED || XL_DEBUG_OUT_ENABLED
		assert(type < LOG_COUNT);

		//first build up the string.
		va_list arg;
		va_start(arg, msg);
		vsprintf(s_tmpBuffer, msg, arg);
		va_end(arg);
	#endif

	#if XL_LOGGING_ENABLED
		sprintf(s_printString, "%s%s\r\n", c_logMsgType[type], s_tmpBuffer);
		const size_t len = strlen(s_printString);

		s_logFile.write(s_printString, (u32)len);
		s_logFile.flush();	//flush to disk in case of a crash.
	#endif

	#if XL_DEBUG_OUT_ENABLED
		sprintf(s_printString, "%s%s\n", c_logMsgType[type], s_tmpBuffer);
		debugMessage(s_printString);
	#endif
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:25,代码来源:log.cpp

示例4: write

	void write(const char* key, bool value)
	{
		sprintf(s_workBuffer, "%s=%s\r\n", key, value ? "true" : "false");

		size_t len = strlen(s_workBuffer);
		s_stream.write(s_workBuffer, (u32)len);
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:7,代码来源:iniWriter.cpp

示例5: writeStrNoQuotes

	void writeStrNoQuotes(const char* key, const char* value)
	{
		sprintf(s_workBuffer, "%s=%s\r\n", key, value);

		size_t len = strlen(s_workBuffer);
		s_stream.write(s_workBuffer, (u32)len);
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:7,代码来源:iniWriter.cpp

示例6: newLine

	void newLine()
	{
		strcpy(s_workBuffer, "\r\n");

		size_t len = strlen(s_workBuffer);
		s_stream.write(s_workBuffer, (u32)len);
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:7,代码来源:iniWriter.cpp

示例7: comment

	void comment(const char* comment)
	{
		sprintf(s_workBuffer, "#%s\r\n", comment);

		size_t len = strlen(s_workBuffer);
		s_stream.write(s_workBuffer, (u32)len);
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:7,代码来源:iniWriter.cpp

示例8: save

bool TerrainFile::save( const char *filename )
{
   FileStream stream;
   stream.open( filename, Torque::FS::File::Write );
   if ( stream.getStatus() != Stream::Ok )
      return false;

   stream.write( (U8)FILE_VERSION );

   stream.write( mSize );

   // Write out the height map.
   for ( U32 i=0; i < mHeightMap.size(); i++)
      stream.write( mHeightMap[i] );

   // Write out the layer map.
   for ( U32 i=0; i < mLayerMap.size(); i++)
      stream.write( mLayerMap[i] );

   // Write out the material names.
   stream.write( (U32)mMaterials.size() );
   for ( U32 i=0; i < mMaterials.size(); i++ )
      stream.write( String( mMaterials[i]->getInternalName() ) );

   return stream.getStatus() == FileStream::Ok;
}
开发者ID:campadrenalin,项目名称:terminal-overload,代码行数:26,代码来源:terrFile.cpp

示例9: endFrame

   virtual void endFrame()
   {
      char buffer[ 256 ];

      for( U32 i = 0; i < mRecords.size(); ++ i )
      {
         if( i != 0 )
            mStream.write( 1, "," );

         SampleRecord& record = mRecords[ i ];
         if( record.mSet )
         {
            if( record.mType == TypeBool )
            {
               if( record.mValue.mBool )
                  mStream.write( 4, "true" );
               else
                  mStream.write( 5, "false" );
            }
            else if( record.mType == TypeS32 )
            {
               dSprintf( buffer, sizeof( buffer ), "%d", record.mValue.mS32 );
               mStream.write( dStrlen( buffer ), buffer );
            }
            else if( record.mType == TypeF32 )
            {
               dSprintf( buffer, sizeof( buffer ), "%f", record.mValue.mF32 );
               mStream.write( dStrlen( buffer ), buffer );
            }
            else if( record.mType == TypeString )
            {
               //FIXME: does not do doubling of double quotes in the string at the moment
               mStream.write( 1, "\"" );
               mStream.write( dStrlen( record.mValue.mString ), record.mValue.mString );
               mStream.write( 1, "\"" );
            }
            else
               AssertWarn( false, "CSVSamplerBackend::endFrame - bug: invalid sample type" );
         }

         record.clean();
      }

      newline();
   }
开发者ID:fr1tz,项目名称:terminal-overload,代码行数:45,代码来源:sampler.cpp

示例10: chunkReceived

void NetConnection::chunkReceived(U8 *chunkData, U32 chunkLen)
{
   if(chunkLen == 0)
   {
      // the server didn't have the file... apparently it's one we don't need...
      dFree(mCurrentFileBuffer);
      mCurrentFileBuffer = NULL;
      dFree(mMissingFileList[0]);
      mMissingFileList.pop_front();
      return;
   }
   if(chunkLen + mCurrentFileBufferOffset > mCurrentFileBufferSize)
   {
      setLastError("Invalid file chunk from server.");
      return;
   }
   dMemcpy(((U8 *) mCurrentFileBuffer) + mCurrentFileBufferOffset, chunkData, chunkLen);
   mCurrentFileBufferOffset += chunkLen;
   if(mCurrentFileBufferOffset == mCurrentFileBufferSize)
   {
      // this file's done...
      // save it to disk:
      FileStream *stream;

      Con::printf("Saving file %s.", mMissingFileList[0]);
      if((stream = FileStream::createAndOpen( mMissingFileList[0], Torque::FS::File::Write )) == NULL)
      {
         setLastError("Couldn't open file downloaded by server.");
         return;
      }

      dFree(mMissingFileList[0]);
      mMissingFileList.pop_front();
      stream->write(mCurrentFileBufferSize, mCurrentFileBuffer);
      delete stream;
      mNumDownloadedFiles++;
      dFree(mCurrentFileBuffer);
      mCurrentFileBuffer = NULL;
      sendNextFileDownloadRequest();
   }
   else
   {
      Con::executef("onFileChunkReceived", mMissingFileList[0], Con::getIntArg(mCurrentFileBufferOffset), Con::getIntArg(mCurrentFileBufferSize));
   }
}
开发者ID:campadrenalin,项目名称:terminal-overload,代码行数:45,代码来源:netDownload.cpp

示例11: exportToFile

void BanList::exportToFile(const char *name)
{
   FileStream *banlist;

   char filename[1024];
   Con::expandScriptFilename(filename, sizeof(filename), name);
   if((banlist = FileStream::createAndOpen( filename, Torque::FS::File::Write )) == NULL)
      return;

   char buf[1024];
   Vector<BanInfo>::iterator i;
   for(i = list.begin(); i != list.end(); i++)
   {
      dSprintf(buf, sizeof(buf), "BanList::addAbsolute(%d, \"%s\", %d);\r\n", i->uniqueId, i->transportAddress, i->bannedUntil);
      banlist->write(dStrlen(buf), buf);
   }

   delete banlist;
}
开发者ID:03050903,项目名称:Torque3D,代码行数:19,代码来源:banList.cpp

示例12: outputPath

bool GFXD3D9Shader::_saveCompiledOutput( const Torque::Path &filePath, 
                                         LPD3DXBUFFER buffer, 
                                         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::Write))
      return false;
   if (!f.write(smCompiledShaderTag))
      return false;
   // We could reverse engineer the structure in the compiled output, but this
   // is a bit easier because we can just read it into the struct that we want.
   if (!bufferLayoutF->write(&f))
      return false;
   if (!bufferLayoutI->write(&f))
      return false;
   U32 bufferSize = buffer->GetBufferSize();
   if (!f.write(bufferSize))
      return false;
   if (!f.write(bufferSize, buffer->GetBufferPointer()))
      return false;

   // Write out sampler descriptions.

   f.write( samplerDescriptions.size() );   

   for ( U32 i = 0; i < samplerDescriptions.size(); i++ )
   {
      f.write( samplerDescriptions[i].name );
      f.write( (U32)(samplerDescriptions[i].constType) );
      f.write( samplerDescriptions[i].arraySize );
   }

   f.close();

   return true;
}
开发者ID:AlkexGas,项目名称:Torque3D,代码行数:41,代码来源:gfxD3D9Shader.cpp

示例13: newline

 void newline()
 {
    mStream.write( 1, "\n" );
 }
开发者ID:fr1tz,项目名称:terminal-overload,代码行数:4,代码来源:sampler.cpp

示例14: 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

示例15: sHLSLStr


//.........这里部分代码省略.........
      s.read(s.getStreamSize(), code->GetBufferPointer());
      
      if (res == D3D_OK)
      {
         DWORD* data = (DWORD*) code->GetBufferPointer();
         res = GFXD3DX.D3DXGetShaderConstantTable(data, &table);
      }
   }
   else
   {
      if ( smLogErrors )
         Con::errorf( "GFXD3D9Shader::_compileShader - Unsupported shader file type '%s'.", 
            filePath.getFullPath().c_str() );

      return false;
   }

   if ( res != D3D_OK && smLogErrors )
      Con::errorf( "GFXD3D9Shader::_compileShader - Error compiling shader: %s: %s (%x)", 
         DXGetErrorStringA(res), DXGetErrorDescriptionA(res), res );

   if ( errorBuff )
   {
      // remove \n at end of buffer
      U8 *buffPtr = (U8*) errorBuff->GetBufferPointer();
      U32 len = dStrlen( (const char*) buffPtr );
      buffPtr[len-1] = '\0';

      if( res != D3D_OK )
      {
         if ( smLogErrors )
            Con::errorf( "   %s", (const char*) errorBuff->GetBufferPointer() );
      }
      else
      {
         if ( smLogWarnings )
            Con::warnf( "%s", (const char*) errorBuff->GetBufferPointer() );
      }
   }
   else if ( code == NULL && smLogErrors )
      Con::errorf( "GFXD3D9Shader::_compileShader - no compiled code produced; possibly missing file '%s'.", 
         filePath.getFullPath().c_str() );

   // Create the proper shader if we have code
   if( code != NULL )
   {
      #ifndef TORQUE_SHIPPING

         LPD3DXBUFFER disassem = NULL;
         D3DXDisassembleShader( (DWORD*)code->GetBufferPointer(), false, NULL, &disassem );
         mDissasembly = (const char*)disassem->GetBufferPointer();         
         SAFE_RELEASE( disassem );

         if ( gDisassembleAllShaders )
         {
             String filename = filePath.getFullPath();
            filename.replace( ".hlsl", "_dis.txt" );

            FileStream *fstream = FileStream::createAndOpen( filename, Torque::FS::File::Write );
            if ( fstream )
            {            
               fstream->write( mDissasembly );
               fstream->close();
               delete fstream;   
            }
         }

      #endif

      if (target.compare("ps_", 3) == 0)      
         res = mD3D9Device->CreatePixelShader( (DWORD*)code->GetBufferPointer(), &mPixShader );
      else
         res = mD3D9Device->CreateVertexShader( (DWORD*)code->GetBufferPointer(), &mVertShader );

      if (res == S_OK)
         _getShaderConstants(table, bufferLayoutF, bufferLayoutI, samplerDescriptions);

#ifdef TORQUE_ENABLE_CSF_GENERATION

      // Ok, we've got a valid shader and constants, let's write them all out.
      if ( !_saveCompiledOutput(filePath, code, bufferLayoutF, bufferLayoutI) && smLogErrors )
         Con::errorf( "GFXD3D9Shader::_compileShader - Unable to save shader compile output for: %s", 
            filePath.getFullPath().c_str() );

#endif

      SAFE_RELEASE(table);

      if ( res != S_OK && smLogErrors )
         Con::errorf( "GFXD3D9Shader::_compileShader - Unable to create shader for '%s'.", 
            filePath.getFullPath().c_str() );
   }

   bool result = code != NULL && res == S_OK;

   SAFE_RELEASE( code );
   SAFE_RELEASE( errorBuff );

   return result;
}
开发者ID:AlkexGas,项目名称:Torque3D,代码行数:101,代码来源:gfxD3D9Shader.cpp


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