void write_magic(ostream& os, const string& magic) { os.write(magic.c_str(), 4); }
bool WriteByteOrder( ostream& o ) const { Uint8 order = 0x01234567; o.write( (const char*)&order, sizeof( order ) ); return o.good(); }
bool WriteData( ostream& o ) const { o.write( (const char*)m_data, sizeof( *m_data ) * m_size ); return o.good(); }
// string void operator& (string x, ostream& stream) { x.length() & stream; stream.write (x.c_str(), x.length()); }
void writeHoudiniStr(ostream& ostream,const string& s) { write<BIGEND>(ostream,(short)s.size()); ostream.write(s.c_str(),s.size()); }
void writeLength(ostream &os, short len) { len = htons(len); os.write((char *)&len, sizeof(short)); }
void Tempo::writeToFile(ostream & output) { MetaEvent::writeToFile(output); output.put((char)3); // size output.write(MidiUtil::intToBytes(mMPQN, 3), 3); }
void StreamUtils::write(ostream& os, int i) { os.write((char*) &i, sizeof(int)); }
void StreamUtils::write(ostream& os, float f) { os.write((char*) &f, sizeof(float)); }
void aol::Vector<_DataType>::saveRaw ( ostream &out, const qc::SaveType type, const DataType Minimum, const DataType Maximum ) const { int i = 0; DataType maximum = Maximum; if ( ( type == qc::PGM_UNSIGNED_CHAR_BINARY || type == qc::PGM_UNSIGNED_SHORT_BINARY ) && Maximum == 0 ) { cerr << "Cannot scale image to a maximum of 0, scaling to 1 instead.\n"; // This is necessary to write complete black images maximum = 1; } switch ( type ) { case qc::PGM_UNSIGNED_CHAR_ASCII: { aol::Vector<unsigned char> buffer ( this->_size ); bool flag = this->createOverflowHandledData ( buffer, Minimum, maximum ); for ( i = 0; i < this->_size; ++i ) { out << static_cast<int> ( buffer[i] ) << " "; if ( ( i % 10 ) == 9 ) out << std::endl; } if ( flag && !quietMode ) cerr << "warning: Data contains values < 0 that are converted to unsigned char\n"; } break; case qc::PGM_UNSIGNED_CHAR_BINARY: { aol::Vector<unsigned char> buffer ( this->_size ); bool flag = this->createOverflowHandledData ( buffer, Minimum, maximum ); out.write ( reinterpret_cast<char*> ( buffer.getData() ), this->_size ); if ( flag && !quietMode ) cerr << "warning: Data contains values < 0 that are converted to unsigned char\n"; } break; case qc::PGM_FLOAT_ASCII: { for ( i = 0; i < this->_size; ++i ) { out << this->_pData[i] << " "; if ( ( i % 10 ) == 9 ) out << std::endl; } } break; case qc::PGM_FLOAT_BINARY: { if ( ( sizeof ( float ) == sizeof ( DataType ) ) && !(std::numeric_limits<DataType>::is_integer) ) { out.write ( reinterpret_cast<char *> ( this->_pData ), this->_size * sizeof ( float ) ); } else { float * buffer = new float[this->_size]; for ( i = 0; i < this->_size; ++i ) buffer[i] = static_cast<float> ( this->_pData[i] ); out.write ( reinterpret_cast<char *> ( buffer ), this->_size * sizeof ( float ) ); delete[] buffer; } } break; case qc::PGM_DOUBLE_BINARY: { if ( ( sizeof ( double ) == sizeof ( DataType ) ) && !(std::numeric_limits<DataType>::is_integer) ) { out.write ( reinterpret_cast<char *> ( this->_pData ), this->_size * sizeof ( double ) ); } else { double * buffer = new double[this->_size]; for ( i = 0; i < this->_size; ++i ) buffer[i] = static_cast<double> ( this->_pData[i] ); out.write ( reinterpret_cast<char *> ( buffer ), this->_size * sizeof ( double ) ); delete[] buffer; } } break; case qc::PGM_UNSIGNED_SHORT_BINARY: { bool flag = false; unsigned short *buffer = new unsigned short[this->_size]; for ( i = 0; i < this->_size; ++i ) { DataType temp = this->_pData[i]; if ( static_cast<double> ( temp ) < 0 ) { flag = true; // Workaround for icc (replaced - with abs) temp = aol::Abs ( this->_pData[i] ); } buffer[i] = static_cast<unsigned short> ( static_cast<double> ( temp ) / static_cast<double> ( maximum ) * 65535.0 ); } out.write ( reinterpret_cast<char*> ( buffer ), this->_size * sizeof ( unsigned short ) ); delete[] buffer; if ( flag && !this->quietMode ) cerr << "warning: Data contains values < 0 that are converted to unsigned short\n"; } break; default: throw aol::TypeException ( "aol::Vector<DataType>::saveRaw: invalid type specified", __FILE__, __LINE__ ); } if ( out.good() ) { if ( !quietMode ) cerr << "Successfully wrote to PGM " << type << " stream\n"; } else { const aol::Bzipofstream* pOut = dynamic_cast<const aol::Bzipofstream*>(&out); if( pOut != NULL ) throw aol::Exception ( "aol::Vector<DataType>::saveRaw: Writing to aol::Bzipofstream failed. Is there enough free memory to hold the whole file?", __FILE__, __LINE__ ); else throw aol::Exception ( "aol::Vector<DataType>::saveRaw: Error writing file", __FILE__, __LINE__ ); } }
void CSRFormat::WriteSize(int size,ostream &ofs) { ofs.write((char*)&size,sizeof(int)); }
void Header::out(ostream & streamOut) { assert( _name[0] && _mode[0] && _uid[0] && _gid[0] && _size[0] && _mtime[0] && _magic[0] && _version[0] && _uname[0] && _gname[0] ); if (! _chksum[0]) { checksum(); } streamOut.write((char *) this, sizeof(Header)); }
void WavReader::readAndWriteHeaders( const std::string& name, istream& file, ostream& out, FormatSubchunk& formatSubchunk, FormatSubchunkHeader& formatSubchunkHeader) { RiffHeader header; file.read(reinterpret_cast<char*>(&header), sizeof(RiffHeader)); // ... if (toString(header.id, 4) != "RIFF") { rLog(channel, "ERROR: %s is not a RIFF file", name.c_str()); return; } if (toString(header.format, 4) != "WAVE") { rLog(channel, "ERROR: %s is not a wav file: %s", name.c_str(), toString(header.format, 4).c_str()); return; } out.write(reinterpret_cast<char*>(&header), sizeof(RiffHeader)); file.read(reinterpret_cast<char*>(&formatSubchunkHeader), sizeof(FormatSubchunkHeader)); if (toString(formatSubchunkHeader.id, 4) != "fmt ") { rLog(channel, "ERROR: %s expecting 'fmt' for subchunk header; got '%s'", name.c_str(), toString(formatSubchunkHeader.id, 4).c_str()); return; } out.write(reinterpret_cast<char*>(&formatSubchunkHeader), sizeof(FormatSubchunkHeader)); file.read(reinterpret_cast<char*>(&formatSubchunk), sizeof(FormatSubchunk)); out.write(reinterpret_cast<char*>(&formatSubchunk), sizeof(FormatSubchunk)); rLog(channel, "format tag: %u", formatSubchunk.formatTag); // show as hex? rLog(channel, "samples per second: %u", formatSubchunk.samplesPerSecond); rLog(channel, "channels: %u", formatSubchunk.channels); rLog(channel, "bits per sample: %u", formatSubchunk.bitsPerSample); auto bytes = formatSubchunkHeader.subchunkSize - sizeof(FormatSubchunk); auto additionalBytes = new char[bytes]; file.read(additionalBytes, bytes); out.write(additionalBytes, bytes); FactOrData factOrData; file.read(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData)); out.write(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData)); if (toString(factOrData.tag, 4) == "fact") { FactChunk factChunk; file.read(reinterpret_cast<char*>(&factChunk), sizeof(FactChunk)); out.write(reinterpret_cast<char*>(&factChunk), sizeof(FactChunk)); file.read(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData)); out.write(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData)); rLog(channel, "samples per channel: %u", factChunk.samplesPerChannel); } if (toString(factOrData.tag, 4) != "data") { string tag{toString(factOrData.tag, 4)}; rLog(channel, "%s ERROR: unknown tag>%s<", name.c_str(), tag.c_str()); return; } }
int FixedTextBuffer::Write(ostream & stream) { stream.write(Buffer, BufferSize); return stream.good(); }
//-------------------------------------------------- bool ofBuffer::writeTo(ostream & stream) const{ if( stream.bad() ) return false; stream.write(&(buffer[0]),buffer.size()-1); return true; }
void StreamUtils::write(ostream& os, const string& str) { int n = str.size(); os.write((char*) &n, sizeof(int)); os.write(str.c_str(), sizeof(char) * n); }
int DelimTextBuffer::Write(ostream & stream) const{ stream.write((char*) &bufferSize, sizeof(bufferSize)); stream.write(buffer, bufferSize); return stream.good(); }
void StreamUtils::write(ostream& os, bool b) { os.write((char*) &b, sizeof(bool)); }
static void writeString(ostream& stream, string str) { int length = str.size(); stream.write((char*) &length, sizeof(int)); stream.write((char*) &str[0], length); }
void save(ostream &os) { os.write((const char*)&size, sizeof(uint32_t)); os.write((const char*)bits.data(), bits.size() * sizeof(uint32_t)); os.write((const char*)blocks.data(), blocks.size() * sizeof(uint32_t)); }
uint32 NativeTexture::writeD3d(ostream &rw) { HeaderInfo header; header.build = version; uint32 writtenBytesReturn; if (platform != PLATFORM_D3D8 && platform != PLATFORM_D3D9) return 0; // Texture Native SKIP_HEADER(); // Struct { SKIP_HEADER(); bytesWritten += writeUInt32(platform, rw); bytesWritten += writeUInt32(filterFlags, rw); char buffer[32]; strncpy(buffer, name.c_str(), 32); rw.write(buffer, 32); strncpy(buffer, maskName.c_str(), 32); rw.write(buffer, 32); bytesWritten += 2*32; bytesWritten += writeUInt32(rasterFormat, rw); /* if(rasterFormat == RASTER_8888 && !hasAlpha || rasterFormat == RASTER_888 && hasAlpha) cout << "mismatch " << hex << rasterFormat << endl; */ if (platform == PLATFORM_D3D8) { bytesWritten += writeUInt32(hasAlpha, rw); } else { if (dxtCompression) { char fourcc[5] = "DXT0"; fourcc[3] += dxtCompression; rw.write(fourcc, 4); bytesWritten += 4; } else { // 0x15 or 0x16 bytesWritten += writeUInt32(0x16-hasAlpha, rw); } } bytesWritten += writeUInt16(width[0], rw); bytesWritten += writeUInt16(height[0], rw); bytesWritten += writeUInt8(depth, rw); bytesWritten += writeUInt8(mipmapCount, rw); bytesWritten += writeUInt8(0x4, rw); if (platform == PLATFORM_D3D8) bytesWritten += writeUInt8(dxtCompression, rw); else bytesWritten += writeUInt8( (dxtCompression ? 8 : 0) | hasAlpha, rw); /* Palette */ if (rasterFormat & RASTER_PAL8 || rasterFormat & RASTER_PAL4) { uint32 paletteSize = 1 << depth; rw.write(reinterpret_cast <char *> (palette), paletteSize*4*sizeof(uint8)); bytesWritten += paletteSize*4*sizeof(uint8); } /* Texels */ for (uint32 i = 0; i < mipmapCount; i++) { /* uint32 dataSize = width[i]*height[i]; if (!dxtCompression) dataSize *= depth/8; else if (dxtCompression == 1) dataSize /= 2; */ uint32 dataSize = dataSizes[i]; bytesWritten += writeUInt32(dataSize, rw); rw.write(reinterpret_cast <char *> (&texels[i][0]), dataSize*sizeof(uint8)); bytesWritten += dataSize*sizeof(uint8); } WRITE_HEADER(CHUNK_STRUCT); } bytesWritten += writtenBytesReturn; // Extension { SKIP_HEADER(); WRITE_HEADER(CHUNK_EXTENSION); } bytesWritten += writtenBytesReturn; WRITE_HEADER(CHUNK_TEXTURENATIVE); return bytesWritten; }
inline void Write(ostream& output, T value/*, size_t& written*/) { output.write(reinterpret_cast<const char*>(&value), sizeof(T)); //written += sizeof(T); }
void binary_write (T x, ostream& stream) { stream.write (reinterpret_cast<char*>(&x), sizeof(x)); }
MStatus blindDoubleData::writeBinary( ostream& out ) { out.write( (char*) &fValue, sizeof( fValue)); return out.fail() ? MS::kFailure : MS::kSuccess; }
/// Writes all unread bytes into \p os. void istream::write (ostream& os) const { os.write (ipos(), remaining()); }
static bool serialize(long &i,ostream &output){output.write(reinterpret_cast<const char*>(&i),4);return true;};
bool WriteSignature( ostream& o ) const { o.write( (const char*)Signature(m_version), SignatureSize() ); return o.good(); }
static bool serialize(double &d,ostream &output) { output.write(reinterpret_cast<const char*>(&d),8); return true; }
// 写一个NAL单元到输出流 void write(ostream& out, OutputNALUnit& nalu) { writeNalUnitHeader(out, nalu); /* write out rsbp_byte's, inserting any required * emulation_prevention_three_byte's */ /* 7.4.1 ... * emulation_prevention_three_byte is a byte equal to 0x03. When an * emulation_prevention_three_byte is present in the NAL unit, it shall be * discarded by the decoding process. * The last byte of the NAL unit shall not be equal to 0x00. * Within the NAL unit, the following three-byte sequences shall not occur at * any byte-aligned position: * - 0x000000 * - 0x000001 * - 0x000002 * Within the NAL unit, any four-byte sequence that starts with 0x000003 * other than the following sequences shall not occur at any byte-aligned * position: * - 0x00000300 * - 0x00000301 * - 0x00000302 * - 0x00000303 */ vector<uint8_t>& rbsp = nalu.m_Bitstream.getFIFO(); if (rbsp.size() == 0) { return; } for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();) { /* 1) find the next emulated 00 00 {00,01,02,03} * 2a) if not found, write all remaining bytes out, stop. * 2b) otherwise, write all non-emulated bytes out * 3) insert emulation_prevention_three_byte */ vector<uint8_t>::iterator found = it; do { /* NB, end()-1, prevents finding a trailing two byte sequence */ found = search_n(found, rbsp.end()-1, 2, 0); found++; /* if not found, found == end, otherwise found = second zero byte */ if (found == rbsp.end()) break; if (*(++found) <= 3) break; } while (true); it = found; if (found != rbsp.end()) { it = rbsp.insert(found, emulation_prevention_three_byte[0]); } } out.write((Char*)&(*rbsp.begin()), rbsp.end() - rbsp.begin()); /* 7.4.1.1 * ... when the last byte of the RBSP data is equal to 0x00 (which can * only occur when the RBSP ends in a cabac_zero_word), a final byte equal * to 0x03 is appended to the end of the data. */ if (rbsp.back() == 0x00) { out.write(emulation_prevention_three_byte, 1); } }
void ScoreFile::ScoreEntry::WriteOnStream(ostream& os) { os.write(reinterpret_cast<const char*>(&score), sizeof(int)); os.write(name, MAX_NAME); }