void DownloadOperation::onDownloadDataReply() { if (isTerminating()) { gotoNext(); return ; } UINT32 bufferSize = 1024 * 8; try { DataOutputStream dos(m_fos); dos.writeFully(m_replyBuffer->getDownloadBuffer(), m_replyBuffer->getDownloadBufferSize()); } catch (IOException &ioEx) { notifyFailedToDownload(ioEx.getMessage()); gotoNext(); return ; } m_totalBytesCopied += m_replyBuffer->getDownloadBufferSize(); if (m_copyListener != NULL) { m_copyListener->dataChunkCopied(m_totalBytesCopied, m_totalBytesToCopy); } bool compression = m_replyBuffer->isCompressionSupported(); m_sender->sendDownloadDataRequest(bufferSize, compression); }
void PrintDotFile::printDotFile(MethodDesc& mh, ::std::ostream& fos) { dotstream dos(fos); os = &dos; printDotHeader(mh); printDotBody(); printDotEnd(); }
void WayJoin2Mapper::_flushNodes() { // this map should only contain nodes. assert(_nodeMap->getWays().size() == 0); if (_nodeMap->getNodeMap().size() > 0) { LOG_INFO("Flushing nodes. " << _nodeMap->getNodeMap().size()); _key->elementType = NodesType; _key->id = rand(); stringstream ss(stringstream::out); pp::DataOutputStream dos(ss); dos.writeByte(PbfData); PbfWriter writer; // RHEL calls this ambiguous. const shared_ptr<const OsmMap>& co = _nodeMap; writer.writePb(co, &ss); _context->emit(_keyStr, ss.str()); _nodeMap->clear(); } else { LOG_INFO("No nodes to flush."); } }
void PuzzleWin::loadPic(std::list<sf::Sprite*> &_spr) { DIR* dir; struct dirent *ent; struct stat st; std::string dos("./Ressources/Game/Puzzle/Pic/"); std::string name; std::string fullName; sf::Texture* pic; sf::Sprite* spr; int x = 25; int y = 50; int litX = getWindow().getSize().x / 4; int litY = getWindow().getSize().y / 2; Button *next; this->setType(GAME); dir = opendir("./Ressources/Game/Puzzle/Pic"); if (dir != NULL) { while ((ent = readdir(dir)) != NULL) { name = ent->d_name; fullName = dos + name; if (name[0] != '.' && stat(fullName.c_str(), &st) != -1) if ((st.st_mode & S_IFDIR) == false) if (name.rfind('.') != std::string::npos && name.substr(name.rfind('.')).compare(".jpg") == 0) { pic = new sf::Texture; if (pic->loadFromFile(fullName) == true) { next = new Button(x, y, x + 175, y + 175, name); if (x == 25 && y == 50) { this->setPic(next->getContent()); next->setTarget(true); } addButton(next); this->setType(MENU); next->setWin(this); next->DrawContent(getWindow()); spr = new sf::Sprite; spr->setTexture(*pic); spr->setPosition(x, y+50); spr->setScale(0.2f, 0.25f); getWindow().draw(*spr); _spr.push_front(spr); x += 150 + 50; if (x >= getWindow().getSize().x) { x = 0; y += 300; } } } } } }
ArrayXd operator()(Array En) { auto const scale = 1 / (broadening * sqrt(2 * constant::pi)); auto const constant = -0.5f / pow(broadening, 2); // DOS(E) = 1 / (broadening * sqrt(2pi)) * sum(exp(-0.5 * (En-E)^2 / broadening^2)) ArrayXd dos(target_energies.size()); transform(target_energies, dos, [&](float E) { auto gaussian = exp((En - E).square() * constant); return scale * sum(gaussian); }); return dos; }
int main() { int unidad = DETECT, modo,i,Vert,Horiz,Boton; MOUSE mouse; void uno(MOUSE &),dos(MOUSE &); void tres(MOUSE &),cuatro(MOUSE &),cinco(MOUSE &); void EscribirMenu(MOUSE &); mouse.Inicializar(); initgraph (&unidad,&modo,"c:\\bc\\bgi"); if (graphresult() != 0) { cout << "Error al tratar de pasar al modo grafico\n"; getch(); return 1; } mouse.Mostrar(); EscribirMenu(mouse); Boton = 0; while (Boton != DERECHO) { Boton = mouse.Estado(&Vert, &Horiz); if (Boton == IZQUIERDO) { if (Horiz >= 50 && Horiz <= 59) { uno(mouse); EscribirMenu(mouse); } else if (Horiz >= 60 && Horiz <= 69) { dos(mouse); EscribirMenu(mouse); } else if (Horiz >= 70 && Horiz <= 79) { tres(mouse); EscribirMenu(mouse); } else if (Horiz >= 80 && Horiz <= 89) { cuatro(mouse); EscribirMenu(mouse); } else if (Horiz >= 90 && Horiz <= 99) { cinco(mouse); EscribirMenu(mouse); } mouse.LibBotones(); } } closegraph(); return 0; }
// Write an 8bit value to a packet void BufferedSocket::Write8(wxInt8 val) { if (!send_buf->IsOk()) { wxLogDebug(_T("Write8: End of buffer reached!")); return; } wxDataOutputStream dos(*send_buf); dos.BigEndianOrdered(BigEndian); dos.Write8(val); return; }
void LoggingHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { bool reauth = true; if (request.hasCredentials()) { std::string cred; std::string scheme; try { Poco::Net::HTTPBasicCredentials cred(request); std::string user = cred.getUsername(); std::istringstream istr(cred.getPassword(), std::ios::binary); Poco::MD5Engine md5; Poco::DigestOutputStream dos(md5); Poco::StreamCopier::copyStream(istr, dos); dos.close(); std::string pwd = Poco::DigestEngine::digestToHex(md5.digest()); reauth = (pwd != _pwdHash || _user != user); } catch (...) { reauth = true; } } if (reauth) { response.requireAuthentication(TITLE); response.send(); return; } Poco::Net::HTMLForm form(request); std::string offsetStr; Poco::Net::NameValueCollection::ConstIterator it = form.find(OFFSET); if (it != form.end()) offsetStr = it->second; int offset(0); Poco::NumberParser::tryParse(offsetStr, offset); std::string numEntriesStr; it = form.find(NUMENTRIES); if (it != form.end()) numEntriesStr = it->second; int numEntries = DEFAULT_NUMENTRIES; Poco::NumberParser::tryParse(numEntriesStr, numEntries); std::vector<Poco::Message> messages; _channel.getMessages(messages, offset, numEntries); displayMessages(messages, offset, numEntries, _channel.getCurrentSize(), response); }
// Write a null terminated string bool BufferedSocket::WriteString(const wxString &str) { if (!CanWrite((size_t)str.Length())) { wxLogDebug(_T("WriteString: End of buffer reached!")); m_BadWrite = true; return false; } wxDataOutputStream dos(*m_SendBufferHandler); dos.BigEndianOrdered(BigEndian); dos << str.c_str(); return true; }
// Write a boolean value bool BufferedSocket::WriteBool(const bool &val) { if (!CanWrite(1)) { wxLogDebug(_T("WriteBool: End of buffer reached!")); m_BadWrite = true; return false; } wxDataOutputStream dos(*m_SendBufferHandler); dos.BigEndianOrdered(BigEndian); dos.Write8((val ? 1 : 0)); return true; }
// Write an unsigned 16bit value bool BufferedSocket::Write16(const wxUint16 &val) { if (!CanWrite(2)) { wxLogDebug(_T("Write16: End of buffer reached!")); m_BadWrite = true; return false; } wxDataOutputStream dos(*m_SendBufferHandler); dos.BigEndianOrdered(BigEndian); dos.Write16(val); return true; }
void operator()(std::pair<Poco::DigestEngine*, std::string>& item) { Poco::DigestOutputStream dos(*item.first); m_getter.Get(m_uri.getPath(), dos); dos.close(); std::string digestStr(Poco::DigestEngine::digestToHex(item.first->digest())); Poco::URI digestUri("http://poco.roundsquare.net/downloads/test."+item.second); HTTPGetter digestgetter(digestUri.getHost(), digestUri.getPort()); std::stringstream ss; digestgetter.Get(digestUri.getPath(), ss); m_msg.Message(Poco::format(" %s: %s [%s]" , Poco::toUpper((4 == item.second.length()) ? item.second:(" "+item.second)) , digestStr , std::string((0 == ss.str().compare(digestStr)) ? "OK":"NG")) ); delete item.first; item.first = NULL; }
TestDigestEngine(ScopedLogMessage& msg, const Poco::URI& uri, const char* passphrase=kPassphrase) : TestDigestEngineBase() { CreateDigestEngine(passphrase); Poco::DigestOutputStream dos(*m_pDigestEngine); std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri)); Poco::StreamCopier::copyStream(*pStr.get(), dos); dos.close(); std::string digestStr(Poco::DigestEngine::digestToHex(m_pDigestEngine->digest())); Poco::URI digestUri("http://poco.roundsquare.net/downloads/test."+digestName[N]); std::auto_ptr<std::istream> pStrDigest(Poco::URIStreamOpener::defaultOpener().open(digestUri)); std::stringstream ss; Poco::StreamCopier::copyStream(*pStrDigest.get(), ss); msg.Message(Poco::format(" %s: %s [%s]" , Poco::toUpper((4 == digestName[N].length()) ? digestName[N]:(" "+digestName[N])) , digestStr , std::string((0 == ss.str().compare(digestStr)) ? "OK":"NG")) ); }
void SecondOrderAssocReaction::AddReactionTerms(qdMatrix *CollOptr, molMapType &isomermap, const double rMeanOmega) { // Get densities of states of the adduct for detailed balance. vector<double> pdtDOS; m_pdt1->getDOS().getGrainDensityOfStates(pdtDOS) ; // Locate isomers in system matrix. const int pdtLoc = isomermap[m_pdt1] ; const int jj = (*m_sourceMap)[get_pseudoIsomer()] ; // Get equilibrium constant. const qd_real Keq = qd_real(calcEquilibriumConstant()) ; // Get Boltzmann distribution for detailed balance. vector<double> adductPopFrac ; // Population fraction of the adduct const int pShiftedGrains(m_pdt1->getColl().reservoirShift()); m_pdt1->getColl().normalizedGrnBoltzmannDistribution(adductPopFrac) ; qd_real DissRateCoeff(0.0), qdMeanOmega(rMeanOmega) ; const int pdtRxnOptPos(pdtLoc - pShiftedGrains); const int colloptrsize = m_pdt1->getColl().get_colloptrsize() + pShiftedGrains ; const int reverseThreshE = get_EffGrnRvsThreshold(); const int fluxStartIdx = get_fluxFirstNonZeroIdx(); // Note: reverseThreshE will always be greater than pShiftedGrains here. // In following factors 2.0 and 4.0 appear. These arise from the the Taylor // expansion of the non-linear term about the the equilibrium point. for ( int i = reverseThreshE, j = fluxStartIdx; i < colloptrsize; ++i, ++j) { int ii(pdtRxnOptPos + i) ; int kk (i - pShiftedGrains); qd_real Flux(m_GrainFlux[j]), dos(pdtDOS[i]), addPop(adductPopFrac[kk]) ; (*CollOptr)[ii][ii] -= qdMeanOmega * Flux / dos ; // Loss of the adduct to the source (*CollOptr)[jj][ii] = qdMeanOmega * Flux * qd_real(2.0) * sqrt(Keq*addPop)/dos ; // Reactive gain of the source (*CollOptr)[ii][jj] = (*CollOptr)[jj][ii] ; // Reactive gain (symmetrization) DissRateCoeff += Flux * addPop / dos; } (*CollOptr)[jj][jj] -= qd_real(4.0) * qdMeanOmega * DissRateCoeff * Keq ; // Loss of the source from detailed balance. }
signed char* PbfInputSplit::writeFields(size_t* len) const { stringstream sout(stringstream::out); DataOutputStream dos(sout); dos.writeLong(_start); dos.writeLong(_length); dos.writeString(_path); dos.writeString(_locations); dos.writeInt(_headers.size()); for (size_t i = 0; i < _headers.size(); i++) { dos.writeLong(_headers.at(i)); } sout.flush(); *len = sout.str().length(); signed char* result = new signed char[*len]; memcpy(result, sout.str().data(), *len); return result; }
void DownloadOperation::onDownloadDataReply(DataInputStream *input) { if (isTerminating()) { gotoNext(); return ; } UINT32 bufferSize = 1024*64; try { DataOutputStream dos(m_fos); if (!m_replyBuffer->getDownloadBuffer().empty()) { dos.writeFully(&m_replyBuffer->getDownloadBuffer().front(), m_replyBuffer->getDownloadBufferSize()); } } catch (IOException &ioEx) { notifyFailedToDownload(ioEx.getMessage()); gotoNext(); return ; } // // Notify that we receive some data // m_totalBytesCopied += m_replyBuffer->getDownloadBufferSize(); if (m_copyListener != NULL) { m_copyListener->dataChunkCopied(m_totalBytesCopied, m_totalBytesToCopy); } // // Send next download data request // bool compression = m_replyBuffer->isCompressionSupported(); m_sender->sendDownloadDataRequest(bufferSize, compression); }
void WayJoin2Mapper::mapOsmMap(shared_ptr<OsmMap> m) { // The first byte on the value says if it is a PBF/WayJoin1Reducer::Value PbfWriter writer; // Remove all non-roads. m->removeWays(TagFilter(Filter::FilterMatches, "highway", "")); _key->elementType = NodesType; // Go through all the nodes const OsmMap::NodeMap& nm = m->getNodeMap(); for (OsmMap::NodeMap::const_iterator it = nm.constBegin(); it != nm.constEnd(); ++it) { // add this node onto a map. Since the nodes aren't very important at this stage we'll just // ship a bunch at a time in one big record. _emitNode(it.value()); } _key->elementType = WayType; // Go through all the ways const WayMap& wm = m->getWays(); for (WayMap::const_iterator it = wm.begin(); it != wm.end(); ++it) { const shared_ptr<const Way>& w = it->second; _key->id = w->getId(); stringstream ss(stringstream::out); pp::DataOutputStream dos(ss); //LOG_INFO("Writing way: " << _key->id); dos.writeByte(PbfData); writer.writePb(w, &ss); // Emit the way _context->emit(_keyStr, ss.str()); } }