void pos_to_str(Pos p, OStream & buf) { if (p.name.empty()) buf.write("<anon>"); else buf.write(p.name); if (p.line == NPOS) ;//buf.write(":"); else if (p.col == NPOS) buf.printf(":%u", p.line); else buf.printf(":%u:%u", p.line, p.col); }
inline void quantize(ngram_type& ngram, OStream& os, LogProbs& logprobs, Hashed& hashed, Counts& counts, Codemap& codemap, Codebook& codebook, int order, int shard) { hashed.clear(); counts.clear(); codemap.clear(); const size_type pos_first = ngram.index[shard].offsets[order - 1]; const size_type pos_last = ngram.index[shard].offsets[order]; for (size_type pos = pos_first; pos < pos_last; ++ pos) ++ hashed[logprobs(pos, order)]; counts.insert(hashed.begin(), hashed.end()); hashed.clear(); expgram::Quantizer::quantize(ngram, counts, codebook, codemap); for (size_type pos = pos_first; pos < pos_last; ++ pos) { typename Codemap::const_iterator citer = codemap.find(logprobs(pos, order)); if (citer == codemap.end()) throw std::runtime_error("no codemap?"); os.write((char*) &(citer->second), sizeof(quantized_type)); } }
Int64 Header::writeTo (OStream &os, bool isTiled) const { // // Write a "magic number" to identify the file as an image file. // Write the current file format version number. // Xdr::write <StreamIO> (os, MAGIC); int version = isTiled ? makeTiled (EXR_VERSION) : EXR_VERSION; Xdr::write <StreamIO> (os, version); // // Write all attributes. If we have a preview image attribute, // keep track of its position in the file. // Int64 previewPosition = 0; const Attribute *preview = findTypedAttribute <PreviewImageAttribute> ("preview"); for (ConstIterator i = begin(); i != end(); ++i) { // // Write the attribute's name and type. // Xdr::write <StreamIO> (os, i.name()); Xdr::write <StreamIO> (os, i.attribute().typeName()); // // Write the size of the attribute value, // and the value itself. // StdOSStream oss; i.attribute().writeValueTo (oss, version); std::string s = oss.str(); Xdr::write <StreamIO> (os, (int) s.length()); if (&i.attribute() == preview) previewPosition = os.tellp(); os.write (s.data(), s.length()); } // // Write zero-length attribute name to mark the end of the header. // Xdr::write <StreamIO> (os, ""); return previewPosition; }
void png_pov_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { OStream *file = reinterpret_cast<OStream *>(png_get_io_ptr(png_ptr)); if (!file->write (data, length)) { Messages *m = reinterpret_cast<Messages *>(png_get_error_ptr(png_ptr)); if (m) m->error = string("Cannot write PNG data"); throw POV_EXCEPTION(kFileDataErr, "Cannot write PNG data"); } }
void png_pov_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { OStream *file = (OStream *)png_get_io_ptr(png_ptr); if (!file->write ((char *)data, length)) { Messages *m = (Messages *)png_get_error_ptr(png_ptr); if (m) m->error = string("Cannot write PNG data"); throw POV_EXCEPTION(kFileDataErr, "Cannot write PNG data"); } }
static void write_impl(OStream & ost, array<typename OStream::char_type, N> const & s) { ost.write(s.data(), N); }