std::string StreamBuffString(Value* eos, EnvironmentFrame* env) { OStream* os = assert_type<OStream>(Eval(eos, env)); std::ostringstream* oss = dynamic_cast<std::ostringstream*>(os->value()); if (!oss) throw std::runtime_error("Expected a stream buffer to read."); return oss->str(); }
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"); } }
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); }
OutputFile::OutputFile (OStream &os, const Header &header, int numThreads) : _data (new Data (false, numThreads)) { try { header.sanityCheck(); _data->os = &os; initialize (header); } catch (Iex::BaseExc &e) { delete _data; REPLACE_EXC (e, "Cannot open image file " "\"" << os.fileName() << "\". " << e); throw; } catch (...) { delete _data; throw; } }
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 TileOffsets::writeTo (OStream &os) const { // // Write the tile offset table to the file, and // return the position of the start of the table // in the file. // Int64 pos = os.tellp(); if (pos == -1) Iex::throwErrnoExc ("Cannot determine current file position (%T)."); for (unsigned int l = 0; l < _offsets.size(); ++l) for (unsigned int dy = 0; dy < _offsets[l].size(); ++dy) for (unsigned int dx = 0; dx < _offsets[l][dy].size(); ++dx) Xdr::write <StreamIO> (os, _offsets[l][dy][dx]); return pos; }
TiledRgbaOutputFile::TiledRgbaOutputFile (OStream &os, const Header &header, RgbaChannels rgbaChannels, int tileXSize, int tileYSize, LevelMode mode, LevelRoundingMode rmode, int numThreads) : _outputFile (0), _toYa (0) { Header hd (header); insertChannels (hd, rgbaChannels, os.fileName()); hd.setTileDescription (TileDescription (tileXSize, tileYSize, mode, rmode)); _outputFile = new TiledOutputFile (os, hd, numThreads); if (rgbaChannels & WRITE_Y) _toYa = new ToYa (*_outputFile, rgbaChannels); }
void png_pov_flush_data(png_structp png_ptr) { OStream *file = reinterpret_cast<OStream *>(png_get_io_ptr(png_ptr)); file->flush(); }
void png_pov_flush_data(png_structp png_ptr) { OStream *file = (OStream *)png_get_io_ptr(png_ptr); file->flush(); }
/* Released all unfree'd memory from all pools */ void mem_release_all() { #if defined(MEM_RECLAIM) OStream *f = NULL; MEMNODE *p, *tmp; size_t totsize; Send_Progress("Reclaiming memory", PROGRESS_RECLAIMING_MEMORY); p = memlist; totsize = 0; #if defined(MEM_TRACE) if (p != NULL) f = New_OStream(MEM_LOG_FNAME, POV_File_Data_LOG, true); #endif while (p != NULL) { #if defined(MEM_TRACE) #if defined(MEM_TAG) if (!mem_check_tag(p)) Debug_Info("mem_release_all(): Memory pointer corrupt!\n"); #endif /* MEM_TAG */ totsize += (p->size - NODESIZE - (MEM_GUARD_SIZE * 2)); if (!leak_msg) { Debug_Info("Memory leakage detected, see file '%s' for list\n",MEM_LOG_FNAME); leak_msg = true; } if (f != NULL) f->printf("File:%13s Line:%4d Size:%lu\n", p->file, p->line, (unsigned long)(p->size - NODESIZE - (MEM_GUARD_SIZE * 2))); #endif #if defined(MEM_STATS) /* This is after we have printed stats, and this may slow us down a little, */ /* so we may want to simply re-initialize the mem-stats at the end of this loop. */ mem_stats_free(p->size); #endif tmp = p; p = p->next; remove_node(tmp); FREE(tmp); } if (f != NULL) delete f; if (totsize > 0) Debug_Info("\n%lu bytes reclaimed\n", totsize); poolno = 0; memlist = NULL; #endif #if defined(MEM_STATS) /* reinitialize the stats structure for next time through */ mem_stats_init(); #endif }
/* Releases all unfree'd memory from current memory pool */ void mem_release() { #if defined(MEM_RECLAIM) OStream *f = NULL; MEMNODE *p, *tmp; size_t totsize; p = memlist; totsize = 0; #if defined(MEM_TRACE) if (p != NULL && (p->poolno == poolno)) f = New_OStream(MEM_LOG_FNAME, POV_File_Data_LOG, true); #endif /* MEM_TRACE */ while (p != NULL && (p->poolno == poolno)) { #if defined(MEM_TRACE) #if defined(MEM_TAG) if (!mem_check_tag(p)) Debug_Info("mem_release(): Memory pointer corrupt!\n"); #endif /* MEM_TAG */ totsize += (p->size - NODESIZE - (MEM_GUARD_SIZE * 2)); if (!leak_msg) { Debug_Info("Memory leakage detected, see file '%s' for list\n",MEM_LOG_FNAME); leak_msg = true; } if (f != NULL) f->printf("File:%13s Line:%4d Size:%lu\n", p->file, p->line, (unsigned long)(p->size - NODESIZE - (MEM_GUARD_SIZE * 2))); #endif /* MEM_TRACE */ #if defined(MEM_STATS) mem_stats_free(p->size); #endif tmp = p; p = p->next; remove_node(tmp); FREE(tmp); } if (f != NULL) delete f; if (totsize > 0) Debug_Info("%lu bytes reclaimed (pool #%d)\n", totsize, poolno); if (poolno > 0) poolno--; #if defined(MEM_STATS) /* reinitialize the stats structure for next time through */ mem_stats_init(); #endif #endif /* MEM_RECLAIM */ }
// print - Implement the Pass::print method... void SteensgaardDataStructures::print(OStream O, const Module *M) const { if (O.stream()) print(*O.stream(), M); }
static void write_impl(OStream & ost, array<typename OStream::char_type, N> const & s) { ost.write(s.data(), N); }