streamsize cb::transfer(istream &in, ostream &out, streamsize length, SmartPointer<TransferCallback> callback) { char buffer[BUFFER_SIZE]; streamsize total = 0; while (!in.fail() && !out.fail()) { in.read(buffer, length ? min(length, BUFFER_SIZE) : BUFFER_SIZE); streamsize bytes = in.gcount(); out.write(buffer, bytes); total += bytes; if (!callback.isNull() && !callback->transferCallback(bytes)) break; if (length) { length -= bytes; if (!length) break; } } out.flush(); if (out.fail() || length) THROW("Transfer failed"); return total; }
MStatus CVData::writeBinary ( ostream& out ) { out.write( (char*) &_intData, sizeof(_intData) ); if ( !out.fail() ) { out.write( (char*) &_doubleData, sizeof(_doubleData) ); } else { return MS::kFailure; } return out.fail() ? MS::kFailure : MS::kSuccess; }
void Simulation::checkpoint (ostream& stream, int checkpointNum) { util::checkpoint::header (stream); if (stream == NULL || !stream.good()) throw util::checkpoint_error ("Unable to write to file"); util::timer::startCheckpoint (); util::CommandLine::staticCheckpoint (stream); Population::staticCheckpoint (stream); Surveys & stream; Global::simulationTime & stream; Global::timeStep & stream; simPeriodEnd & stream; totalSimDuration & stream; phase & stream; (*_population) & stream; util::random::checkpoint (stream, checkpointNum); workUnitIdentifier & stream; cksum & stream; util::timer::stopCheckpoint (); if (stream.fail()) throw util::checkpoint_error ("stream write error"); }
bool drwnDataRecord::write(ostream& os) const { // TODO: fix 32-bit/64-bit problems int rows = _structure.rows(); os.write((char *)&rows, sizeof(int)); if (rows > 0) { os.write((char *)_structure.data(), rows * sizeof(int)); } rows = _data.rows(); int cols = _data.cols(); os.write((char *)&rows, sizeof(int)); os.write((char *)&cols, sizeof(int)); if (rows > 0) { os.write((char *)_data.data(), rows * cols * sizeof(double)); } rows = _objective.rows(); os.write((char *)&rows, sizeof(int)); if (rows > 0) { os.write((char *)_objective.data(), rows * sizeof(double)); } rows = _gradient.rows(); cols = _gradient.cols(); os.write((char *)&rows, sizeof(int)); os.write((char *)&cols, sizeof(int)); if (rows > 0) { os.write((char *)_gradient.data(), rows * cols * sizeof(double)); } DRWN_ASSERT_MSG(!os.fail(), "bytes: " << this->numBytesOnDisk()); _bDirty = false; return true; }
/** * Saves signature to file using XAdES XML format. * * @param path path, where the signature XML file is saved. * @throws IOException throws exception if the signature file creation failed. */ void SignatureBES::saveToXml(ostream &os) const { if(!sigdata_.empty()) { os << sigdata_; return; } try { NamespaceInfomap map; map["ds"].name = URI_ID_DSIG; map["xades"].name = XADES_NAMESPACE; if(asicsignature) { map["asic"].name = ASIC_NAMESPACE; XAdESSignaturesType asic; asic.signature().push_back(*signature); xAdESSignatures(os, asic, map, "UTF-8", Flags::dont_initialize); } else dsig::signature(os, *signature, map, "UTF-8", Flags::dont_initialize); } catch ( xsd::cxx::xml::invalid_utf8_string ) { THROW_IOEXCEPTION("Failed to create signature XML file. Parameters must be in UTF-8."); } if(os.fail()) THROW_IOEXCEPTION("Failed to create signature XML file."); }
int CCombineGenome::write( ostream & os ) const { for(int i=0; i<paths; i++) { os << "list " << i << ":\t" ; YK_LLONG *cur, *head; GAListIter<YK_LLONG> iter(*list[i]); float sum = 0; if((head=iter.head()) != 0) { sum +=*head; os << *head << " "; } for(cur=iter.next(); cur && cur != head; cur=iter.next()) { sum += *cur; os << *cur << " "; } os<<"\t"<<"size: "<<list[i]->size()<<"\t"; if (list[i]->size() > 0) { os<<"aver: "<<sum/list[i]->size()<<" "; } os << "\n"; } return os.fail() ? 1 : 0; }
int Trafo::write (ostream& os) const { os << NAME "("; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) os << m[i][j] << ((i==2 && j==3) ? ")" : ","); return (os.fail()) ? 1 : 0; }
int RobotPathGenome::write(ostream & os) const { for(int i = 0; i < n; i++) { os << "list " << i << ":\t" << *(list[i]) << "\n"; } return os.fail() ? 1 : 0; }
//------------------------------------------------------------------------------ // writeSynLines (vector <Line>, ostream) : Requests the XGremlin 'syn' string // from each Line in the vector at arg1 and sends this string to the stream at // arg2. // void writeSynLines (vector <Line> Lines, ostream &Output = std::cout) throw (const char*) { for (unsigned int i = 0; i < Lines.size (); i ++) { Output << Lines[i].getLineSynString() << endl; if (Output.fail ()) { ostringstream oss; oss << "line " << Lines[i].line (); throw oss.str().c_str(); } } }
int MpViewLabelList::write (ostream& os) const { for (vector<MpViewLabelData>::const_iterator i = list.begin(); i != list.end(); ++i) { if (i != list.begin()) os << ", " << endl; i->write(os); } return (os.fail()) ? 1 : 0; }
bool drwnCompressionBuffer::write(ostream& os) const { os.write((char *)&_bytesOriginal, sizeof(unsigned int)); os.write((char *)&_bytesCompressed, sizeof(unsigned int)); if (_bytesCompressed > 0) { os.write((char *)_data, _bytesCompressed * sizeof(unsigned char)); } return (!os.fail()); }
// Here we specialize the write method for the List class. This lets us see // exactly what we want (the default write method dumps out pointers to the // data rather than the data contents). // This routine prints out the contents of each element of the list, // separated by a space. It does not put a newline at the end of the list. // Notice that you can specialize ANY function of a template class, but // some compilers are more finicky about how you do it than others. For the // metrowerks compiler this specialization must come before the forced // instantiation. template<> int GAListGenome<int>::write(ostream & os) const { int *cur, *head; GAListIter<int> tmpiter(*this); if((head=tmpiter.head()) != 0) os << *head << " "; for(cur=tmpiter.next(); cur && cur != head; cur=tmpiter.next()) os << *cur << " "; return os.fail() ? 1 : 0; }
bool TactileFinger::toStream(ostream &str) const { str<<"name "<<name<<endl; str<<"logic "<<(directLogic?"direct":"inverse")<<endl; str<<"output_gain "<<outputGain<<endl; if (str.fail()) return false; else return true; }
bool SpringyFinger::toStream(ostream &str) const { str<<"name "<<name<<endl; str<<"calib_vel "<<calibratingVelocity<<endl; str<<"output_gain "<<outputGain<<endl; str<<"calibrated "<<(calibrated?"true":"false")<<endl; str<<"scaler "<<("("+string(scaler.toString().c_str())+")").c_str()<<endl; str<<"lssvm "<<("("+string(lssvm.toString().c_str())+")").c_str()<<endl; return !str.fail(); }
//------------------------------------------------------------------------------ // writeLines (vector <Line>, ostream) : Requests the XGremlin writelines string // from each Line in the vector at arg1 and sends this string to the stream at // arg2. // void writeLines (vector <Line> Lines, ostream &Output = std::cout) throw (const char*) { if (Lines[0].wavCorr () != 0.0) { Output << " WAVENUMBER CORRECTION APPLIED: wavcorr = " << Lines[0].wavCorr () << endl; } else { Output << writelines_header::WaveCorr << endl; } Output << writelines_header::AirCorr << endl; Output << writelines_header::IntCal << endl; Output << writelines_header::Columns << endl; if (Output.fail()) throw "the file header"; for (unsigned int i = 0; i < Lines.size (); i ++) { Output << Lines[i].getLineString() << endl; if (Output.fail ()) { ostringstream oss; oss << "line " << Lines[i].line (); throw oss.str().c_str(); } } }
unsigned Buffer::remove(ostream &stream, unsigned length) { unsigned total = 0; char buffer[4096]; while (!stream.fail() && 0 < length) { unsigned size = remove(buffer, min(length, (unsigned)4096)); stream.write(buffer, size); length -= size; total += size; } return total; }
bool fcnn::internal::write_comment(ostream &os, const string &s) { const char *c = s.c_str(); if (*c) os << "# "; else return true; while (*c) { os << *c; if ((*c == '\n') && (c[1])) os << "# "; ++c; } os << '\n'; if (os.fail()) return false; return true; }
// Here we override the built-in write method for the 2DArray genome so // that we get better spacing. The default just stacks the characters one // after another. Here we do fixed spacing so that the -1 and 1 don't screw // each other up. template <> int GA2DArrayAlleleGenome<int>::write(ostream & os) const { for(unsigned int j = 0; j < ny; j++) { for(unsigned int i = 0; i < nx; i++) { os.width(3); os << gene(i, j); } os << "\n"; } return os.fail() ? 1 : 0; }
MStatus blindComplexData::writeBinary( ostream& out ) { MStatus status; out.write( (char*) &_length, sizeof(_length) ); if ( ! out.fail() ) { for ( unsigned int i=0; i < _length; i++ ) { status = _CVDataArrayPtr[i].writeBinary(out); if ( status != MS::kSuccess ) { return status; } } } else { return MS::kFailure; } return MS::kSuccess; }
bool writeObject2dFrame(ostream &os, const svlObject2dFrame& v, int index) { if (os.fail()) return false; os << " <Object2dFrame index=\"" << index << "\">" << endl; for (unsigned j = 0; j < v.size(); j++) { os << " <Object name=\"" << v[j].name.c_str() << "\"" << " x=\"" << v[j].x << "\"" << " y=\"" << v[j].y << "\"" << " w=\"" << v[j].w << "\"" << " h=\"" << v[j].h << "\"" << " pr=\"" << v[j].pr << "\" />" << endl; } os << " </Object2dFrame>" << endl; return true; }
/** * Creates BDoc container manifest file and returns its path. * * Note: If non-ascii characters are present in XML data, we depend on the LANG variable to be set properly * (see iconv --list for the list of supported encoding values for libiconv). * * * @return returns created manifest file path. * @throws IOException exception is thrown if manifest file creation failed. */ void BDoc::createManifest(ostream &os) { DEBUG("BDoc::createManifest()"); try { manifest::Manifest manifest; manifest.file_entry().push_back(manifest::File_entry("/", mediaType())); for(DataFileList::const_iterator iter = d->documents.begin(); iter != d->documents.end(); ++iter) manifest.file_entry().push_back(manifest::File_entry(iter->fileName(), iter->mediaType())); xml_schema::NamespaceInfomap map; map["manifest"].name = BDocPrivate::MANIFEST_NAMESPACE; manifest::manifest(os, manifest, map, "", xml_schema::Flags::dont_initialize); if(os.fail()) THROW("Failed to create manifest XML"); } catch(const xml_schema::Exception& e) { THROW("Failed to create manifest XML file. Error: %s", e.what()); } }
void RandomSampleJob::ReportResults (ostream& r) { bool errorOccured = false; do { errorOccured = false; r << jobId << "\t" << KernalTypeToStr (config->KernalType ()) << "\t" << EncodingMethodToStr (config->EncodingMethod ()) << "\t" << CompressionMethodStr (compMethod) << "\t" << config->C_Param () << "\t" << config->Gamma () << "\t" << orderingNum << "\t" << numExamplesToKeep << "\t" << Accuracy () << "%" << "\t" << SupportVectors () << "\t" << trainTime << "\t" << testTime << endl; r.flush (); if (r.fail ()) { r.clear (); errorOccured = true; #ifdef WIN32 Sleep (30000); #else sleep (30); #endif } } while (errorOccured); } /* ReportResults */
/** * Extracts current file from ZIP file to directory pointed in <code>directory</code> parameter. * * @param zipFile pointer to opened ZIP file. * @param directory directory where current file from ZIP should be extracted. * @throws IOException throws exception if the extraction of the current file fails from ZIP * file or creating new file to disk failed. */ void ZipSerialize::extract(const string &file, ostream &os) const { DEBUG("ZipSerializePrivate::extract(%s)", file.c_str()); if(file[file.size()-1] == '/') return; int unzResult = unzLocateFile(d->open, file.c_str(), 1); if(unzResult != UNZ_OK) THROW("Failed to locate file inside ZIP container. ZLib error: %d", unzResult); unzResult = unzOpenCurrentFile(d->open); if(unzResult != UNZ_OK) THROW("Failed to open file inside ZIP container. ZLib error: %d", unzResult); int currentStreamSize = 0; char buf[10240]; while((unzResult = unzReadCurrentFile(d->open, buf, 10240)) > UNZ_EOF) { os.write(buf, unzResult); currentStreamSize += unzResult; if(os.fail()) { unzCloseCurrentFile(d->open); THROW("Failed to write file '%s' data to stream. Stream size: %d", file.c_str(), currentStreamSize); } } if(unzResult < UNZ_EOF) { unzCloseCurrentFile(d->open); THROW("Failed to read bytes from current file inside ZIP container. ZLib error: %d", unzResult); } unzResult = unzCloseCurrentFile(d->open); if(unzResult != UNZ_OK) THROW("Failed to close current file inside ZIP container. ZLib error: %d", unzResult); }
MStatus CVData::writeASCII ( ostream& out ) { out << _intData << " " << _doubleData << " "; return out.fail() ? MS::kFailure : MS::kSuccess; }
static int ah_put(ostream &os, AHRecord const &rec0) { // write header+data to an ostream AHRecord rec(rec0); // XXX for const'ness // write header ********************************* int status=AH_SUCCESS, ndata, dtype; { char hbuf[HEADER_SIZE]; XDR xdrs; xdrmem_create(&xdrs, hbuf, HEADER_SIZE, XDR_ENCODE); if ( ! xdr_Header(&xdrs, &rec, ndata, dtype)) // sets ndata, dtype status = AH_ERROR; if (status != AH_SUCCESS) return AH_ERROR; os.write(hbuf, HEADER_SIZE); if (os.fail()) return AH_ERROR; xdr_destroy(&xdrs); } // write data samples *************************** XDR xdrs; int bufsize = buflen(ndata, dtype); // write data to an ostream vector<char> dbuf(bufsize+100); char *buf = &dbuf[0]; xdrmem_create(&xdrs, buf, bufsize, XDR_ENCODE); int n = ndata; switch (dtype) { case AH_DATATYPE_FLOAT: { # ifdef IEEE_INTEL char *b2 = (char*) xdrs.x_private; # endif Array *arr = rec.data(); if (arr==0) cerr << "THIS MUST NEVER HAPPEN: arr==0\n"; float *f = (float*)(arr->data()); # ifdef IEEE_SPARC assert(sizeof(float)==4); memcpy((void*) xdrs.x_private, (void*)f, n*sizeof(float)); # else while (n--) { # ifdef IEEE_INTEL char *b1 = (char*)(++f); *(b2++) = *(--b1); *(b2++) = *(--b1); *(b2++) = *(--b1); *(b2++) = *(--b1); # else if ( ! xdr_float(&xdrs, f++)) { cerr << "error while reading data" << endl; status = AH_ERROR; break; } # endif } # endif } break; case AH_DATATYPE_COMPLEX: /* { float re, im; Complex *c = (Complex*) rec.xdata; for (i=0; i<n; i++) { re = real(c[i]); im = imag(c[i]); if ( ! xdr_float(&xdrs, &re) || ! xdr_float(&xdrs, &im)) { ah_error(ahERR_IO_WR, "error while writing data"); status = AH_ERROR; break; } } } */ break; default: cerr << "ah_error_illegal_data_type YY" << endl; break; } xdr_destroy(&xdrs); os.write(buf, bufsize); if (os.fail()) status = AH_ERROR; return status; }
MStatus blindDoubleData::writeBinary( ostream& out ) { out.write( (char*) &fValue, sizeof( fValue)); return out.fail() ? MS::kFailure : MS::kSuccess; }
template<> int GATreeGenome<int>::write(ostream & os) const { os << " node parent child next prev\n"; WriteNode(os, (GANode<int> *) rt); return os.fail() ? 1 : 0; }