void sintoxml(std::ostream& s, const char* filename, sinparms& sp) { std::ifstream f(filename); if (!f.is_open()) { throw std::runtime_error("Unable to open SIN file for XML conversion"); } pugi::xml_document doc; pugi::xml_node root = doc.append_child(); root.set_name("philips"); std::string line; const size_t buffer_size = 4096; char buffer[buffer_size]; while (!f.eof()) { f.getline(buffer,buffer_size); std::string line(buffer); std::stringstream s; uint16_t idx1, idx2, idx3; char tmp; std::string parameter_name; std::string parameter_value; if (line.find(':') != std::string::npos && isdigit(line[1])) { boost::algorithm::trim_right(line); s << line; s >> idx1; s >> idx2; s >> idx3; s >> tmp; s >> parameter_name; pugi::xml_node parm = root.append_child(parameter_name.c_str()); pugi::xml_attribute attr_idx1 = parm.append_attribute("idx1"); attr_idx1.set_value(idx1); pugi::xml_attribute attr_idx2 = parm.append_attribute("idx2"); attr_idx2.set_value(idx2); pugi::xml_attribute attr_idx3 = parm.append_attribute("idx3"); attr_idx3.set_value(idx3); s >> tmp; bool get_nchan = false; float pda[2]; bool get_pda = false; int pda_comp = 0; if (parameter_name == "enable_pda") { sp.ismira = false; } else if (parameter_name == "max_measured_channels") { get_nchan = true; } else if (parameter_name == "nr_measured_channels") { get_nchan = true; } else if (parameter_name == "pda_ampl_factors") { get_pda = true; } while (!s.eof()) { s >> parameter_value; if (get_nchan) { sp.nchan = std::atoi(parameter_value.c_str()); } if (get_pda) { pda[pda_comp++] = std::atof(parameter_value.c_str()); if (pda_comp > 1) { sp.pda_amp_factors.push_back(std::complex<float>(pda[0],pda[1])); pda_comp = 0; } } pugi::xml_node v = parm.append_child("value"); v.append_child(pugi::node_pcdata).set_value(parameter_value.c_str()); } } }
int CsoundFile::exportScore(std::ostream &stream) const { stream << score << std::endl; return stream.good(); }
S32 LLSDXMLFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32 options, U32 level) const { S32 format_count = 1; std::string pre; std::string post; if (options & LLSDFormatter::OPTIONS_PRETTY) { for (U32 i = 0; i < level; i++) { pre += " "; } post = "\n"; } switch(data.type()) { case LLSD::TypeMap: if (0 == data.size()) { ostr << pre << "<map />" << post; } else { ostr << pre << "<map>" << post; LLSD::map_const_iterator iter = data.beginMap(); LLSD::map_const_iterator end = data.endMap(); for (; iter != end; ++iter) { ostr << pre << "<key>" << escapeString((*iter).first) << "</key>" << post; format_count += format_impl((*iter).second, ostr, options, level + 1); } ostr << pre << "</map>" << post; } break; case LLSD::TypeArray: if (0 == data.size()) { ostr << pre << "<array />" << post; } else { ostr << pre << "<array>" << post; LLSD::array_const_iterator iter = data.beginArray(); LLSD::array_const_iterator end = data.endArray(); for(; iter != end; ++iter) { format_count += format_impl(*iter, ostr, options, level + 1); } ostr << pre << "</array>" << post; } break; case LLSD::TypeUndefined: ostr << pre << "<undef />" << post; break; case LLSD::TypeBoolean: ostr << pre << "<boolean>"; if (mBoolAlpha || (ostr.flags() & std::ios::boolalpha)) { ostr << (data.asBoolean() ? "true" : "false"); } else { ostr << (data.asBoolean() ? 1 : 0); } ostr << "</boolean>" << post; break; case LLSD::TypeInteger: ostr << pre << "<integer>" << data.asInteger() << "</integer>" << post; break; case LLSD::TypeReal: ostr << pre << "<real>"; if (mRealFormat.empty()) { ostr << data.asReal(); } else { formatReal(data.asReal(), ostr); } ostr << "</real>" << post; break; case LLSD::TypeUUID: if (data.asUUID().isNull()) { ostr << pre << "<uuid />" << post; } else { ostr << pre << "<uuid>" << data.asUUID() << "</uuid>" << post; } break; case LLSD::TypeString: if (data.asString().empty()) ostr << pre << "<string />" << post; else ostr << pre << "<string>" << escapeString(data.asString()) <<"</string>" << post; break; case LLSD::TypeDate: ostr << pre << "<date>" << data.asDate() << "</date>" << post; break; case LLSD::TypeURI: ostr << pre << "<uri>" << escapeString(data.asString()) << "</uri>" << post; break; case LLSD::TypeBinary: { LLSD::Binary buffer = data.asBinary(); if (buffer.empty()) { ostr << pre << "<binary />" << post; } else { // *FIX: memory inefficient. // *TODO: convert to use LLBase64 ostr << pre << "<binary encoding=\"base64\">"; int b64_buffer_length = apr_base64_encode_len(buffer.size()); char* b64_buffer = new char[b64_buffer_length]; b64_buffer_length = apr_base64_encode_binary(b64_buffer, &buffer[0], buffer.size()); ostr.write(b64_buffer, b64_buffer_length - 1); delete[] b64_buffer; ostr << "</binary>" << post; } break; } default: // *NOTE: This should never happen. ostr << pre << "<undef />" << post; break; } return format_count; }
void ChunkPillar::saveToStream(std::ostream& pillarData) { // Save the heightmap pillarData.write(reinterpret_cast<char*>(heightMap.data()), heightMap.size() * sizeof(heightMap[0])); }
int CsoundFile::exportCommand(std::ostream &stream) const { stream << command.c_str() << std::endl; return stream.good(); }
void PeSectionHeader::save(std::ostream& os) const { os.write(reinterpret_cast<const char*>(&this->st), sizeof(this->st)); }
void write_uint16(std::ostream& s, uint16_t x) { uint8_t buf[2]; buf[0] = x; buf[1] = x >> 8; s.write(reinterpret_cast<char*>(buf), 2); }
void install_separator(std::ostream& o1, std::ostream& o2) { static custom_separator csep(o2); o1.rdbuf(&csep); o1.tie(&o2); }
void VerifSuite_CppPrintfComp_1_t::print ( std::ostream& s ) { #if __cplusplus >= 201103L if (T1.values[0]) dat_prints<104>(s, "display %h %h", T3, T2); #endif s.flush(); }
void CLogger::LogError( std::ostream const & msg ) { std::stringstream ss; ss << msg.rdbuf(); LogError( ss.str() ); }
void write32(std::ostream &s, uint32 v) { uint32 t = swapEndianLong(v); s.write((char *)&t, 4); }
void swrite(std::ostream& s, std::string t) { int32_t len = (int32_t)t.size(); swrite(s, len); s.write(t.c_str(), len); while (len++ % 4) s.put(0); }
void swrite(std::ostream& s, T t) { char buf[sizeof(T)]; memcpy(buf, &t, sizeof(T)); s.write(buf, sizeof(T)); }
WriteResult writeRGBStream(const osg::Image& img, std::ostream &fout, const std::string& name) const { rawImageRec raw; raw.imagic = 0732; GLenum dataType = img.getDataType(); raw.type = dataType == GL_UNSIGNED_BYTE ? 1 : dataType == GL_BYTE ? 1 : dataType == GL_BITMAP ? 1 : dataType == GL_UNSIGNED_SHORT ? 2 : dataType == GL_SHORT ? 2 : dataType == GL_UNSIGNED_INT ? 4 : dataType == GL_INT ? 4 : dataType == GL_FLOAT ? 4 : dataType == GL_UNSIGNED_BYTE_3_3_2 ? 1 : dataType == GL_UNSIGNED_BYTE_2_3_3_REV ? 1 : dataType == GL_UNSIGNED_SHORT_5_6_5 ? 2 : dataType == GL_UNSIGNED_SHORT_5_6_5_REV ? 2 : dataType == GL_UNSIGNED_SHORT_4_4_4_4 ? 2 : dataType == GL_UNSIGNED_SHORT_4_4_4_4_REV ? 2 : dataType == GL_UNSIGNED_SHORT_5_5_5_1 ? 2 : dataType == GL_UNSIGNED_SHORT_1_5_5_5_REV ? 2 : dataType == GL_UNSIGNED_INT_8_8_8_8 ? 4 : dataType == GL_UNSIGNED_INT_8_8_8_8_REV ? 4 : dataType == GL_UNSIGNED_INT_10_10_10_2 ? 4 : dataType == GL_UNSIGNED_INT_2_10_10_10_REV ? 4 : 4; GLenum pixelFormat = img.getPixelFormat(); raw.dim = 3; raw.sizeX = img.s(); raw.sizeY = img.t(); raw.sizeZ = pixelFormat == GL_COLOR_INDEX? 1 : pixelFormat == GL_RED? 1 : pixelFormat == GL_GREEN? 1 : pixelFormat == GL_BLUE? 1 : pixelFormat == GL_ALPHA? 1 : pixelFormat == GL_RGB? 3 : pixelFormat == GL_BGR ? 3 : pixelFormat == GL_RGBA? 4 : pixelFormat == GL_BGRA? 4 : pixelFormat == GL_LUMINANCE? 1 : pixelFormat == GL_LUMINANCE_ALPHA ? 2 : 1; raw.min = 0; raw.max = 0xFF; raw.wasteBytes = 0; strncpy( raw.name, name.c_str(), 80); raw.colorMap = 0; raw.bpc = (img.getPixelSizeInBits()/raw.sizeZ)/8; int isize = img.getImageSizeInBytes(); unsigned char *buffer = new unsigned char[isize]; if(raw.bpc == 1) { unsigned char *dptr = buffer; int i, j; for( i = 0; i < raw.sizeZ; ++i ) { const unsigned char *ptr = img.data(); ptr += i; for( j = 0; j < isize/raw.sizeZ; ++j ) { *(dptr++) = *ptr; ptr += raw.sizeZ; } } } else { // bpc == 2 unsigned short *dptr = reinterpret_cast<unsigned short*>(buffer); int i, j; for( i = 0; i < raw.sizeZ; ++i ) { const unsigned short *ptr = reinterpret_cast<const unsigned short*>(img.data()); ptr += i; for( j = 0; j < isize/(raw.sizeZ*2); ++j ) { *dptr = *ptr; ConvertShort(dptr++, 1); ptr += raw.sizeZ; } } } if( raw.needsBytesSwapped() ) raw.swapBytes(); /* swapBytes( raw.imagic ); swapBytes( raw.type ); swapBytes( raw.dim ); swapBytes( raw.sizeX ); swapBytes( raw.sizeY ); swapBytes( raw.sizeZ ); swapBytes( raw.min ); swapBytes( raw.max ); swapBytes( raw.colorMap ); */ char pad[512 - sizeof(rawImageRec)]; memset( pad, 0, sizeof(pad)); fout.write((const char*)&raw,sizeof(rawImageRec)); fout.write((const char*)pad,sizeof(pad)); fout.write((const char*)buffer,isize); delete [] buffer; return WriteResult::FILE_SAVED; }
ErrorStatus serialize(std::ostream &dst) const { uint16_t tmp16; dst.write(reinterpret_cast<const char *>(&_clientIP), sizeof(_clientIP)); if (!dst) { return E_FSTREAM; } dst.write(reinterpret_cast<const char *>(&_serverIP), sizeof(_serverIP)); if (!dst) { return E_FSTREAM; } dst.write(reinterpret_cast<const char *>(&_queryTime), sizeof(_queryTime)); if (!dst) { return E_FSTREAM; } dst.write(reinterpret_cast<const char *>(&_responseTime), sizeof(_responseTime)); if (!dst) { return E_FSTREAM; } dst.write(reinterpret_cast<const char *>(&_queryFlags), sizeof(_queryFlags)); if (!dst) { return E_FSTREAM; } dst.write(reinterpret_cast<const char *>(&_responseFlags), sizeof(_responseFlags)); if (!dst) { return E_FSTREAM; } dst.put(boost::numeric_cast<uint8_t>(_queryName.length())); if (!dst) { return E_FSTREAM; } dst.write(_queryName.data(), _queryName.length()); if (!dst) { return E_FSTREAM; } dst.write(reinterpret_cast<const char *>(&_queryType), sizeof(_queryType)); if (!dst) { return E_FSTREAM; } tmp16 = boost::numeric_cast<uint16_t>(_responses.size()); dst.write(reinterpret_cast<const char *>(&tmp16), sizeof(tmp16)); if (!dst) { return E_FSTREAM; } for (std::vector<DNSResponse*>::const_iterator it(_responses.begin()); it != _responses.end(); ++it) { dst.put(boost::numeric_cast<uint8_t>((*it)->name().length())); if (!dst) { return E_FSTREAM; } dst.write((*it)->name().data(), (*it)->name().length()); if (!dst) { return E_FSTREAM; } tmp16 = (*it)->rawType(); dst.write(reinterpret_cast<const char *>(&tmp16), sizeof(tmp16)); if (!dst) { return E_FSTREAM; } tmp16 = boost::numeric_cast<uint16_t>((*it)->resourceData().length()); dst.write(reinterpret_cast<const char *>(&tmp16), sizeof(tmp16)); if (!dst) { return E_FSTREAM; } dst.write((*it)->resourceData().data(), (*it)->resourceData().length()); if (!dst) { return E_FSTREAM; } } return E_SUCCESS; }
void BoxLib::WriteGenericPlotfileHeader (std::ostream &HeaderFile, int nlevels, const Array<BoxArray> &bArray, const Array<std::string> &varnames, const Array<Geometry> &geom, Real time, const Array<int> &level_steps, const Array<IntVect> &ref_ratio, const std::string &versionName, const std::string &levelPrefix, const std::string &mfPrefix) { BL_PROFILE("WriteGenericPlotfileHeader()"); BL_ASSERT(nlevels <= bArray.size()); BL_ASSERT(nlevels <= geom.size()); BL_ASSERT(nlevels <= ref_ratio.size()+1); BL_ASSERT(nlevels <= level_steps.size()); int finest_level(nlevels - 1); HeaderFile.precision(17); VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size); HeaderFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size()); // ---- this is the generic plot file type name HeaderFile << versionName << '\n'; HeaderFile << varnames.size() << '\n'; for (int ivar = 0; ivar < varnames.size(); ++ivar) { HeaderFile << varnames[ivar] << "\n"; } HeaderFile << BL_SPACEDIM << '\n'; HeaderFile << time << '\n'; HeaderFile << finest_level << '\n'; for (int i = 0; i < BL_SPACEDIM; ++i) { HeaderFile << Geometry::ProbLo(i) << ' '; } HeaderFile << '\n'; for (int i = 0; i < BL_SPACEDIM; ++i) { HeaderFile << Geometry::ProbHi(i) << ' '; } HeaderFile << '\n'; for (int i = 0; i < finest_level; ++i) { HeaderFile << ref_ratio[i][0] << ' '; } HeaderFile << '\n'; for (int i = 0; i <= finest_level; ++i) { HeaderFile << geom[i].Domain() << ' '; } HeaderFile << '\n'; for (int i = 0; i <= finest_level; ++i) { HeaderFile << level_steps[i] << ' '; } HeaderFile << '\n'; for (int i = 0; i <= finest_level; ++i) { for (int k = 0; k < BL_SPACEDIM; ++k) { HeaderFile << geom[i].CellSize()[k] << ' '; } HeaderFile << '\n'; } HeaderFile << (int) Geometry::Coord() << '\n'; HeaderFile << "0\n"; for (int level = 0; level <= finest_level; ++level) { HeaderFile << level << ' ' << bArray[level].size() << ' ' << time << '\n'; HeaderFile << level_steps[level] << '\n'; for (int i = 0; i < bArray[level].size(); ++i) { const Box &b(bArray[level][i]); RealBox loc = RealBox(b, geom[level].CellSize(), geom[level].ProbLo()); for (int n = 0; n < BL_SPACEDIM; ++n) { HeaderFile << loc.lo(n) << ' ' << loc.hi(n) << '\n'; } } HeaderFile << MultiFabHeaderPath(level, levelPrefix, mfPrefix) << '\n'; } }
/** * Print the summary of the move. * * The summary just contains the current value of the tuning parameter. * It is printed to the stream that it passed in. * * \param[in] o The stream to which we print the summary. */ void MetropolisHastingsMove::printSummary(std::ostream &o) const { std::streamsize previousPrecision = o.precision(); std::ios_base::fmtflags previousFlags = o.flags(); o << std::fixed; o << std::setprecision(4); // print the name const std::string &n = getMoveName(); size_t spaces = 40 - (n.length() > 40 ? 40 : n.length()); o << n; for (size_t i = 0; i < spaces; ++i) { o << " "; } o << " "; // print the DagNode name const std::string &dn_name = (*nodes.begin())->getName(); spaces = 20 - (dn_name.length() > 20 ? 20 : dn_name.length()); o << dn_name; for (size_t i = 0; i < spaces; ++i) { o << " "; } o << " "; // print the weight int w_length = 4 - (int)log10(weight); for (int i = 0; i < w_length; ++i) { o << " "; } o << weight; o << " "; // print the number of tries int t_length = 9 - (int)log10(numTried); for (int i = 0; i < t_length; ++i) { o << " "; } o << numTried; o << " "; // print the number of accepted int a_length = 9; if (numAccepted > 0) a_length -= (int)log10(numAccepted); for (int i = 0; i < a_length; ++i) { o << " "; } o << numAccepted; o << " "; // print the acceptance ratio double ratio = numAccepted / (double)numTried; if (numTried == 0) ratio = 0; int r_length = 5; for (int i = 0; i < r_length; ++i) { o << " "; } o << ratio; o << " "; proposal->printParameterSummary( o ); o << std::endl; o.setf(previousFlags); o.precision(previousPrecision); }
void finish(std::ostream& out) { out.flush(); }
void decompressZlib(std::istream &is, std::ostream &os) { z_stream z; const s32 bufsize = 16384; char input_buffer[bufsize]; char output_buffer[bufsize]; int status = 0; int ret; int bytes_read = 0; int input_buffer_len = 0; z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; ret = inflateInit(&z); if(ret != Z_OK) throw SerializationError("dcompressZlib: inflateInit failed"); z.avail_in = 0; //dstream<<"initial fail="<<is.fail()<<" bad="<<is.bad()<<std::endl; for(;;) { z.next_out = (Bytef*)output_buffer; z.avail_out = bufsize; if(z.avail_in == 0) { z.next_in = (Bytef*)input_buffer; input_buffer_len = is.readsome(input_buffer, bufsize); z.avail_in = input_buffer_len; //dstream<<"read fail="<<is.fail()<<" bad="<<is.bad()<<std::endl; } if(z.avail_in == 0) { //dstream<<"z.avail_in == 0"<<std::endl; break; } //dstream<<"1 z.avail_in="<<z.avail_in<<std::endl; status = inflate(&z, Z_NO_FLUSH); //dstream<<"2 z.avail_in="<<z.avail_in<<std::endl; bytes_read += is.gcount() - z.avail_in; //dstream<<"bytes_read="<<bytes_read<<std::endl; if(status == Z_NEED_DICT || status == Z_DATA_ERROR || status == Z_MEM_ERROR) { zerr(status); throw SerializationError("decompressZlib: inflate failed"); } int count = bufsize - z.avail_out; //dstream<<"count="<<count<<std::endl; if(count) os.write(output_buffer, count); if(status == Z_STREAM_END) { //dstream<<"Z_STREAM_END"<<std::endl; //dstream<<"z.avail_in="<<z.avail_in<<std::endl; //dstream<<"fail="<<is.fail()<<" bad="<<is.bad()<<std::endl; // Unget all the data that inflate didn't take for(u32 i=0; i < z.avail_in; i++) { is.unget(); if(is.fail() || is.bad()) { dstream<<"unget #"<<i<<" failed"<<std::endl; dstream<<"fail="<<is.fail()<<" bad="<<is.bad()<<std::endl; throw SerializationError("decompressZlib: unget failed"); } } break; } } inflateEnd(&z); }
void Gaussian::writeToStream(std::ostream& o) const{ o.precision(3); o << "{" << "Gaussian:" << " " << "mu = " << mu << " sigma = " << sigma << " " << "}"; }
// Say whether a given stream should be colorized or not. It's always // true for ATTY streams and may be true for streams marked with // colorize flag. inline bool is_colorized(std::ostream& stream) { return is_atty(stream) || static_cast<bool>(stream.iword(colorize_index)); }
void setStream(std::ostream&os) { __os = &os; __os->precision(8); }
static void printAmdOutput(std::ostream& os, const AmdInput* output) { os << "AmdBinDump:" << std::endl; os << " Bitness=" << ((output->is64Bit) ? "64-bit" : "32-bit") << ", " "devType=" << getGPUDeviceTypeName(output->deviceType) << ", " "drvVersion=" << output->driverVersion << ", " "drvInfo=\"" << output->driverInfo << "\", " "compileOptions=\"" << output->compileOptions << "\"\n"; for (const AmdKernelInput& kernel: output->kernels) { os << " Kernel: " << kernel.kernelName << "\n"; os << " Data:\n"; printHexData(os, 2, kernel.dataSize, kernel.data); os << " Code:\n"; printHexData(os, 2, kernel.codeSize, kernel.code); if (!kernel.useConfig) { os << " Header:\n"; printHexData(os, 2, kernel.headerSize, kernel.header); os << " Metadata:\n"; printHexData(os, 2, kernel.metadataSize, (const cxbyte*)kernel.metadata); // CALNotes if (!kernel.calNotes.empty()) { for(const CALNoteInput calNote: kernel.calNotes) { os << " CALNote: type="; if (calNote.header.type<=CALNOTE_ATI_MAXTYPE) os << calNoteNamesTbl[calNote.header.type]; else // unknown os << calNote.header.type; os << ", nameSize=" << calNote.header.nameSize << "\n"; printHexData(os, 2, calNote.header.descSize, calNote.data); } } } else { // when config const AmdKernelConfig& config = kernel.config; os << " Config:\n"; for (AmdKernelArgInput arg: config.args) os << " Arg: \"" << arg.argName << "\", \"" << arg.typeName << "\", " << argTypeNameTbl[cxuint(arg.argType)] << ", " << argTypeNameTbl[cxuint(arg.pointerType)] << ", " << ptrSpaceNameTbl[cxuint(arg.ptrSpace)] << ", " << cxuint(arg.ptrAccess) << ", " << arg.structSize << ", " << arg.constSpaceSize << ", " << confValueToString(arg.resId) << ", " << (arg.used ? "true":"false")<< "\n"; if (!config.samplers.empty()) { os << " Sampler:"; for (cxuint sampler: config.samplers) os << " " << sampler; os << '\n'; } os << " dims=" << confValueToString(config.dimMask) << ", " "cws=" << config.reqdWorkGroupSize[0] << " " << config.reqdWorkGroupSize[1] << " " << config.reqdWorkGroupSize[2] << ", " "SGPRS=" << confValueToString(config.usedSGPRsNum) << ", " "VGPRS=" << confValueToString(config.usedVGPRsNum) << ", " "pgmRSRC2=" << std::hex << "0x" << config.pgmRSRC2 << ", " "ieeeMode=0x" << config.ieeeMode << "\n " "floatMode=0x" << config.floatMode<< std::dec << ", " "hwLocalSize=" << config.hwLocalSize << ", " "hwRegion=" << confValueToString(config.hwRegion) << ", " "scratchBuffer=" << config.scratchBufferSize << "\n " "uavPrivate=" << confValueToString(config.uavPrivate) << ", " "uavId=" << confValueToString(config.uavId) << ", " "constBufferId=" << confValueToString(config.constBufferId) << ", " "printfId=" << confValueToString(config.printfId) << "\n " "privateId=" << confValueToString(config.privateId) << ", " "earlyExit=" << config.earlyExit << "," "condOut=" << config.condOut << ", " << (config.usePrintf?"usePrintf ":"") << (config.useConstantData?"useConstantData ":"") << "\n"; for (cxuint u = 0; u < config.userDatas.size(); u++) os << " UserData: " << config.userDatas[u].dataClass << ", " << config.userDatas[u].apiSlot << ", " << config.userDatas[u].regStart << ", " << config.userDatas[u].regSize << "\n"; } for (BinSection section: kernel.extraSections) { os << " Section " << section.name << ", type=" << section.type << ", flags=" << section.flags << ":\n"; printHexData(os, 2, section.size, section.data); } for (BinSymbol symbol: kernel.extraSymbols) os << " Symbol: name=" << symbol.name << ", value=" << symbol.value << ", size=" << symbol.size << ", section=" << symbol.sectionId << "\n"; os.flush(); } os << " GlobalData:\n"; printHexData(os, 1, output->globalDataSize, output->globalData); for (BinSection section: output->extraSections) { os << " Section " << section.name << ", type=" << section.type << ", flags=" << section.flags << ":\n"; printHexData(os, 1, section.size, section.data); } for (BinSymbol symbol: output->extraSymbols) os << " Symbol: name=" << symbol.name << ", value=" << symbol.value << ", size=" << symbol.size << ", section=" << symbol.sectionId << "\n"; os.flush(); }
/*! Pretty print a column vector. The data are tabulated. The common widths before and after the decimal point are set with respect to the parameter maxlen. \param s Stream used for the printing. \param length The suggested width of each vector element. The actual width grows in order to accomodate the whole integral part, and shrinks if the whole extent is not needed for all the numbers. \param intro The introduction which is printed before the vector. Can be set to zero (or omitted), in which case the introduction is not printed. \return Returns the common total width for all vector elements. \sa std::ostream &operator<<(std::ostream &s, const vpArray2D<Type> &A) */ int vpColVector::print(std::ostream& s, unsigned int length, char const* intro) const { typedef std::string::size_type size_type; unsigned int m = getRows(); unsigned int n = 1; std::vector<std::string> values(m*n); std::ostringstream oss; std::ostringstream ossFixed; std::ios_base::fmtflags original_flags = oss.flags(); // ossFixed <<std::fixed; ossFixed.setf ( std::ios::fixed, std::ios::floatfield ); size_type maxBefore=0; // the length of the integral part size_type maxAfter=0; // number of decimals plus // one place for the decimal point for (unsigned int i=0;i<m;++i) { oss.str(""); oss << (*this)[i]; if (oss.str().find("e")!=std::string::npos){ ossFixed.str(""); ossFixed << (*this)[i]; oss.str(ossFixed.str()); } values[i]=oss.str(); size_type thislen=values[i].size(); size_type p=values[i].find('.'); if (p==std::string::npos){ maxBefore=vpMath::maximum(maxBefore, thislen); // maxAfter remains the same } else{ maxBefore=vpMath::maximum(maxBefore, p); maxAfter=vpMath::maximum(maxAfter, thislen-p-1); } } size_type totalLength=length; // increase totalLength according to maxBefore totalLength=vpMath::maximum(totalLength,maxBefore); // decrease maxAfter according to totalLength maxAfter=std::min(maxAfter, totalLength-maxBefore); if (maxAfter==1) maxAfter=0; // the following line is useful for debugging //std::cerr <<totalLength <<" " <<maxBefore <<" " <<maxAfter <<"\n"; if (intro) s <<intro; s <<"["<<m<<","<<n<<"]=\n"; for (unsigned int i=0;i<m;i++) { s <<" "; size_type p=values[i].find('.'); s.setf(std::ios::right, std::ios::adjustfield); s.width((std::streamsize)maxBefore); s <<values[i].substr(0,p).c_str(); if (maxAfter>0){ s.setf(std::ios::left, std::ios::adjustfield); if (p!=std::string::npos){ s.width((std::streamsize)maxAfter); s <<values[i].substr(p,maxAfter).c_str(); } else{ assert(maxAfter>1); s.width((std::streamsize)maxAfter); s <<".0"; } } s <<' '; s <<std::endl; } s.flags(original_flags); // restore s to standard state return (int)(maxBefore+maxAfter); }
int CsoundFile::exportOrchestra(std::ostream &stream) const { stream << orchestra; stream.flush(); return stream.good(); }
void Server::setLogStream( const std::ostream& s ) { log.rdbuf( s.rdbuf() ); }
void Dice::serialize(std::ostream& ostr) { ostr.write((char*)&diceNumber, sizeof(int)); ostr.write((char*)&diceSides, sizeof(int)); }
/// Returns true if the underlying stream is in a failure state inline bool fail() { return out == NULL ? false : out->fail(); }
void ossimNitfCscrnaTag::writeStream(std::ostream& out) { out.write(thePredictedCornerFlag, 1); out.write(theUlLat, 9); out.write(theUlLon, 10); out.write(theUlHt, 8); out.write(theUrLat, 9); out.write(theUrLon, 10); out.write(theUrHt, 8); out.write(theLrLat, 9); out.write(theLrLon, 10); out.write(theLrHt, 8); out.write(theLlLat, 9); out.write(theLlLon, 10); out.write(theLlHt, 8); }
bool SCENEGRAPH::WriteCache( std::ostream& aFile, SGNODE* parentNode ) { if( NULL == parentNode && NULL != m_Parent ) { SGNODE* np = m_Parent; while( NULL != np->GetParent() ) np = np->GetParent(); if( np->WriteCache( aFile, NULL ) ) { m_written = true; return true; } return false; } if( parentNode != m_Parent ) { #ifdef DEBUG std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [BUG] corrupt data; parentNode != m_aParent"; wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); #endif return false; } if( NULL == m_Parent ) { // ensure unique node names ResetNodeIndex(); ReNameNodes(); } if( aFile.fail() ) { #ifdef DEBUG std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [INFO] bad stream"; wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); #endif return false; } aFile << "[" << GetName() << "]"; S3D::WritePoint( aFile, center ); S3D::WritePoint( aFile, translation ); S3D::WriteVector( aFile, rotation_axis ); aFile.write( (char*)&rotation_angle, sizeof( rotation_angle ) ); S3D::WritePoint( aFile, scale ); S3D::WriteVector( aFile, scale_axis ); aFile.write( (char*)&scale_angle, sizeof( scale_angle ) ); // Transfer ownership of any Transform references which hadn't been written size_t asize = m_RTransforms.size(); size_t i; for( i = 0; i < asize; ++i ) { if( !m_RTransforms[i]->isWritten() ) { m_RTransforms[i]->SwapParent( this ); --asize; --i; } } // Transfer ownership of any Shape references which hadn't been written asize = m_RShape.size(); for( i = 0; i < asize; ++i ) { if( !m_RShape[i]->isWritten() ) { m_RShape[i]->SwapParent( this ); --asize; --i; } } asize = m_Transforms.size(); aFile.write( (char*)&asize, sizeof( size_t ) ); asize = m_RTransforms.size(); aFile.write( (char*)&asize, sizeof( size_t ) ); asize = m_Shape.size(); aFile.write( (char*)&asize, sizeof( size_t ) ); asize = m_RShape.size(); aFile.write( (char*)&asize, sizeof( size_t ) ); asize = m_Transforms.size(); // write child transforms for( i = 0; i < asize; ++i ) { if( !m_Transforms[i]->WriteCache( aFile, this ) ) { #ifdef DEBUG std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [INFO] bad stream while writing child transforms"; wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); #endif return false; } } // write referenced transform names asize = m_RTransforms.size(); for( i = 0; i < asize; ++i ) aFile << "[" << m_RTransforms[i]->GetName() << "]"; // write child shapes asize = m_Shape.size(); for( i = 0; i < asize; ++i ) { if( !m_Shape[i]->WriteCache( aFile, this ) ) { #ifdef DEBUG std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [INFO] bad stream while writing child shapes"; wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); #endif return false; } } // write referenced transform names asize = m_RShape.size(); for( i = 0; i < asize; ++i ) aFile << "[" << m_RShape[i]->GetName() << "]"; if( aFile.fail() ) return false; m_written = true; return true; }