bool test_output_seekable(std::ostream& io) { int i; // old 'for' scope workaround. // Test seeking with ios::cur for (i = 0; i < data_reps; ++i) { for (int j = 0; j < chunk_size; ++j) io.put(narrow_data()[j]); io.seekp(-chunk_size, BOOST_IOS::cur); io.write(narrow_data(), chunk_size); } // Test seeking with ios::beg std::streamoff off = 0; io.seekp(0, BOOST_IOS::beg); for (i = 0; i < data_reps; ++i, off += chunk_size) { for (int j = 0; j < chunk_size; ++j) io.put(narrow_data()[j]); io.seekp(off, BOOST_IOS::beg); io.write(narrow_data(), chunk_size); } // Test seeking with ios::end io.seekp(0, BOOST_IOS::end); off = io.tellp(); io.seekp(-off, BOOST_IOS::end); for (i = 0; i < data_reps; ++i, off -= chunk_size) { for (int j = 0; j < chunk_size; ++j) io.put(narrow_data()[j]); io.seekp(-off, BOOST_IOS::end); io.write(narrow_data(), chunk_size); } return true; }
void join_lines_remove_shell_comments_function(std::istream& is, std::ostream& os) { bool skip = false; char current; while (is.get(current)) { if (skip) { if (current != '\n' && current != '\\') continue; } else if (skip = (current == '#')) { continue; } if (current != '\\') { if (current == '\n') skip = false; if (!skip) os.put(current); continue; } if (!is.get(current)) { if (!skip) os.put('\\'); return; } if (skip || current == '\n') continue; os.put('\\'); os.put(current); } }
void Image::savePPM(std::ostream &os) { // write header os << "P6\n" << m_nWidth << ' ' << m_nHeight << "\n255\n"; unsigned int nR, nG, nB; unsigned char cR, cG, cB; // write clamped [0, 255] values for(int y = m_nHeight-1; y >= 0; y--) { for(int x = 0; x < m_nWidth; x++) { nR = (unsigned int) (256 * m_rgbImage[x][y].r()); nG = (unsigned int) (256 * m_rgbImage[x][y].g()); nB = (unsigned int) (256 * m_rgbImage[x][y].b()); if(nR > 255) nR = 255; if(nG > 255) nG = 255; if(nB > 255) nB = 255; cR = (unsigned char) (nR); cG = (unsigned char) (nG); cB = (unsigned char) (nB); os.put(cR); os.put(cG); os.put(cB); } } }
inline size_t writeVarNumber(std::ostream& os, uint64_t varNumber) { if (varNumber < 253) { os.put(static_cast<char>(varNumber)); return 1; } else if (varNumber <= std::numeric_limits<uint16_t>::max()) { os.put(static_cast<char>(253)); uint16_t value = htobe16(static_cast<uint16_t>(varNumber)); os.write(reinterpret_cast<const char*>(&value), 2); return 3; } else if (varNumber <= std::numeric_limits<uint32_t>::max()) { os.put(static_cast<char>(254)); uint32_t value = htobe32(static_cast<uint32_t>(varNumber)); os.write(reinterpret_cast<const char*>(&value), 4); return 5; } else { os.put(static_cast<char>(255)); uint64_t value = htobe64(varNumber); os.write(reinterpret_cast<const char*>(&value), 8); return 9; } }
inline void write_and_pad_shader_source_header( std::ostream& output, shader_source_header& header, span_size_t source_text_size, span_size_t& spos ) { using eagine::memory::is_aligned_as; while(!is_aligned_as<shader_source_header>(spos)) { output.put('\0'); ++spos; } // if changing this also change shader_block // in write_and_pad_program_source_header const span_size_t size = 48; span_size_t done = 0; assert(size >= span_size(sizeof(shader_source_header))); eagine::memory::const_address hdraddr(&header); header.source_text.reset(hdraddr+std::ptrdiff_t(size),source_text_size); output.write(static_cast<const char*>(hdraddr), sizeof(header)); spos += sizeof(header); done += sizeof(header); while(done < size) { output.put('\0'); ++spos; ++done; } }
void Image::writePPM(std::ostream& s) const { s << "P6\n" << _width << " " << _height << "\n255\n"; unsigned int i; double gamma = 1.0 / 2.2; for (int y = 0; y < _height; y++) { for (int x = 0; x < _width; x++) { _pixels(y, x) = Color( pow(_pixels(y, x)[0], gamma), pow(_pixels(y, x)[1], gamma), pow(_pixels(y, x)[2], gamma) ); i = 256.0 * _pixels(y, x)[0]; if (i > 255) i = 255; s.put((unsigned char) i); i = 256.0 * _pixels(y, x)[1]; if (i > 255) i = 255; s.put((unsigned char) i); i = 256.0 * _pixels(y, x)[2]; if (i > 255) i = 255; s.put((unsigned char) i); } } }
FIT_UINT8 FieldDefinition::Write(std::ostream &file) const { file.put(num); file.put(size); file.put(type); return 3; }
// Save & change and restore stream properties void saver_tests_2 ( std::istream & input, std::ostream & output, std::ostream & err ) { using std::locale; using std::ios_base; boost::io::ios_tie_saver const its( input, &err ); boost::io::ios_rdbuf_saver const irs( output, err.rdbuf() ); boost::io::ios_iword_saver const iis( output, my_index, 69L ); boost::io::ios_pword_saver const ipws( output, my_index, &err ); output << "The data is (a third time; adding the numbers):\n"; boost::io::ios_flags_saver const ifls( output, (output.flags() & ~ios_base::adjustfield) | ios_base::showpos | ios_base::boolalpha | (ios_base::internal & ios_base::adjustfield) ); boost::io::ios_precision_saver const iprs( output, 9 ); boost::io::ios_fill_saver const ifis( output, '@' ); output << '\t' << test_string << '\n'; boost::io::ios_width_saver const iws( output, 12 ); output.put( '\t' ); output << test_num1 + test_num2; output.put( '\n' ); locale loc( locale::classic(), new backward_bool_names ); boost::io::ios_locale_saver const ils( output, loc ); output << '\t' << test_bool << '\n'; BOOST_CHECK( &err == output.pword(my_index) ); BOOST_CHECK( 69L == output.iword(my_index) ); try { boost::io::ios_exception_saver const ies( output, ios_base::eofbit ); boost::io::ios_iostate_saver const iis( output, output.rdstate() | ios_base::eofbit ); BOOST_ERROR( "previous line should have thrown" ); } catch ( ios_base::failure &f ) { err << "Got the expected I/O failure: \"" << f.what() << "\".\n"; BOOST_CHECK( output.exceptions() == ios_base::goodbit ); } catch ( ... ) { err << "Got an unknown error when doing exception test!\n"; throw; } }
int Mesg::Write(std::ostream& file, const MesgDefinition* mesgDef) const { MesgDefinition mesgDefOnNull; FIT_UINT8 mesgSize = 1; file.put((localNum & FIT_HDR_TYPE_MASK)); // Message record header with local message number. if (mesgDef == FIT_NULL) { mesgDefOnNull = MesgDefinition(*this); mesgDef = &mesgDefOnNull; } for (FIT_UINT16 fieldDefIndex = 0; fieldDefIndex < (mesgDef->GetFields().size()); fieldDefIndex++) { const Field* field = GetField(mesgDef->GetFieldByIndex(fieldDefIndex)->GetNum()); FIT_UINT8 fieldSize = 0; if (field != FIT_NULL) { fieldSize = field->Write(file); if (fieldSize == 0) return 0; } if (fieldSize < (mesgDef->GetFieldByIndex(fieldDefIndex)->GetSize())) { FIT_UINT8 baseTypeNum = ((mesgDef->GetFieldByIndex(fieldDefIndex)->GetType()) & FIT_BASE_TYPE_NUM_MASK); if (baseTypeNum < FIT_BASE_TYPES) { FIT_UINT8 baseTypeByteIndex = (fieldSize % (baseTypeSizes[baseTypeNum])); FIT_UINT8 numBytesRemaining = (mesgDef->GetFieldByIndex(fieldDefIndex)->GetSize()) - fieldSize; while (numBytesRemaining--) { file.put(*(baseTypeInvalids[baseTypeNum] + baseTypeByteIndex)); if ((++baseTypeByteIndex) >= baseTypeSizes[baseTypeNum]) baseTypeByteIndex = 0; fieldSize++; } } else { return 0; // Do not continue if base type not supported. } } mesgSize += fieldSize; } return mesgSize; }
void InfixPrinter::WriteToken(std::ostream& aOutput, const std::string& aString) { if (IsAlNum(iPrevLastChar) && (IsAlNum(aString[0]) || aString[0] == '_')) aOutput.put(' '); else if (IsSymbolic(iPrevLastChar) && IsSymbolic(aString[0])) aOutput.put(' '); aOutput.write(aString.c_str(), aString.size()); RememberLastChar(aString.back()); }
size_t u8_wc_toutf8(std::ostream &out, long ch) { if (ch < 0x80) { out.put((char)ch); return 1; } if (ch < 0x800) { out.put((ch>>6) | 0xC0); out.put((ch & 0x3F) | 0x80); return 2; }
void DoubleWord::writeSwappedOrder(std::ostream& destinationStream) const { DoubleWordValue value; value.doubleWord = mValue; destinationStream.put(value.bytes[3]); destinationStream.put(value.bytes[2]); destinationStream.put(value.bytes[1]); destinationStream.put(value.bytes[0]); }
void writeEscaped(std::ostream &out, InputIterator begin, InputIterator end, char delim = ',') { for (; begin != end; ++begin) { char c = *begin; if (c == delim || c == '\\') out.put('\\'); out.put(c); } }
void operator () (std::ostream &file, const film< rgb<uint8_t>, E > &image) { typedef typename film< rgb<uint8_t>, E >::size_type size_type; for ( size_type r = 0; r < image.height(); ++r ) for ( size_type c = 0; c < image.width(); ++c ) { rgb<uint8_t> col(image[c][r]); file.put(col.blue()); file.put(col.green()); file.put(col.red()); } }
void LafsFlat::encodeSkipName(std::ostream& out, const int iNext) { out.put('.'); out.put(0); WORD wBuffer = iNext; out.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD)); out.put(0); out.put(0); }
// // SaveInt // static void SaveInt(std::ostream &save, biguint i) { if(!i) return; SaveInt(save, i / 16); save.put("0123456789ABCDEF"[i % 16]); }
void Word::writeSwappedOrder(std::ostream& destinationStream) const { const Byte* bytes = reinterpret_cast<const Byte*>(&myValue); destinationStream.put(bytes[1]); destinationStream.put(bytes[0]); }
bool Reader::read_until_boundary(int sock, const std::string& boundary, std::ostream& out, size_t max) { size_t read_so_far = 0; unsigned got = 0; while (got < boundary.size()) { char c; ssize_t count = read(sock, &c, 1); if (count == 0) throw wibble::exception::Consistency("reading from socket", "data ends before MIME boundary"); if (count < 0) throw wibble::exception::System("reading from socket"); if (c == boundary[got]) ++got; else { if (max == 0 || read_so_far < max) { if (got > 0) { out.write(boundary.data(), got); read_so_far += got; } out.put(c); ++read_so_far; } got = 0; } } return readboundarytail(sock); }
void sign_helper ( std::ostream& aStr, const int64_t& aInt ) { if ( aInt < int64_t ( 0 ) ) { aStr.put ( '-' ); } }
static void dump_node(std::ostream&out, const Node*node){ for (unsigned line = 1, height = get_height(node); line <= height; ++line){ dump_line(out, node, line); out.put('\n'); } out.flush(); }
void write_array(std::ostream &_stream, Iter _begin, uint16_t _size) { _stream.put((uint8_t) 0xDC); _stream.write(reinterpret_cast<const char*>(&_size), sizeof(_size)); for (int i = 0; i < _size; i++) { msgpack<T>::write(_stream, *_begin++); } }
// // SaveRealInt // static void SaveRealInt(std::ostream &save, bigreal i) { if(!i) return; SaveRealInt(save, std::floor(i / 16)); save.put("0123456789ABCDEF"[static_cast<unsigned>(std::floor(std::fmod(i, 16)))]); }
void print(std::ostream &out) const { for (char ci='a'; ci <= 'z'; ++ci){ for (size_t i=0; i < count(ci); ++i){ out.put(ci); } } }
void write_template( std::ostream & out, mapper_impl<std::integer_sequence<std::size_t, Ints...>, Binders...> const & map, char const * fmt) { auto fmt_point = fmt; for (; *fmt; ++fmt) { if ('%' == *fmt && *(fmt+1)) { ++fmt; bool is_executed = false; (void)std::initializer_list<int>{( !is_executed && get_binder<Ints>(map).c == *fmt ? ((out.write(fmt_point, fmt - fmt_point - 1) << get_binder<Ints>(map).x), fmt_point = fmt+1, is_executed = true ) : 1 )...}; if (!is_executed) { out.write(fmt_point, fmt - fmt_point - 1); out.put(*fmt); fmt_point = fmt+1; } } } out.write(fmt_point, fmt - fmt_point); }
void writeDxfBinary(std::ostream &file,GroupCode code) { writeleshort(file,code.tag); switch(tagFormat(code.tag)) { case 1: file.put(code.flag); break; case 2: writeleshort(file,code.integer); break; case 4: writeleint(file,code.integer); break; case 8: writelelong(file,code.integer); break; case 72: writeledouble(file,code.real); break; case 128: writeustring(file,code.str); break; case 129: writeustring(file,hexEncodeString(code.str)); break; case 132: writeustring(file,hexEncodeInt(code.integer)); break; } }
static void decompress(BitInputStream &in, std::ostream &out) { // Set up decoder and model. In this PPM model, symbol 256 represents EOF; // its frequency is 1 in the order -1 context but its frequency // is 0 in all other contexts (which have non-negative order). ArithmeticDecoder dec(32, in); PpmModel model(MODEL_ORDER, 257, 256); vector<uint32_t> history; while (true) { // Decode and write one byte uint32_t symbol = decodeSymbol(dec, model, history); if (symbol == 256) // EOF symbol break; int b = static_cast<int>(symbol); if (std::numeric_limits<char>::is_signed) b -= (b >> 7) << 8; out.put(static_cast<char>(b)); model.incrementContexts(history, symbol); if (model.modelOrder >= 1) { // Prepend current symbol, dropping oldest symbol if necessary if (history.size() >= static_cast<unsigned int>(model.modelOrder)) history.erase(history.end() - 1); history.insert(history.begin(), symbol); } } }
uint32_t AsmHashTag::write(std::ostream &o) const { uint16_t strsize(value.size()); o.write((const char *) &strsize, 2); o.write(value.c_str(), strsize); o.put('\0'); return strsize + 3; }
void join_lines_function(std::istream& is, std::ostream& os) { char current; while (is.get(current)) { if (current != '\\') { os.put(current); continue; } if (!is.get(current)) { return; } if (current == '\n') { continue; } os.put('\\'); os.put(current); } }
void LafsFlat::encodeName(std::ostream& out, const std::string& sName) { if(sName.size() > LAFS_NAME_SIZE) throw FormattingException("Name of file exceeds permitted limit."); for(unsigned int i = 0; i < LAFS_NAME_SIZE; i++) out.put( i < sName.size() ? sName.c_str()[i] : 0); }
int CsoundFile::exportMidifile(std::ostream &stream) const { for(int i = 0, n = midifile.size(); i < n; i++) { stream.put(midifile[i]); } return stream.good(); }