bool Solver::write_samples() { try { DataWriter dw; dw.writeAll(gyro::SAMPLE_FILE); cout << endl << "Samples are successfully written" << endl; } catch (ios_base::failure& ) { msg = "(ios_base::failure)"; return FAILED; } catch (exception& e) { msg = string("(") + e.what() + string(")"); return FAILED; } return SUCCESS; }
bool QueryReader::readOne(UInt8 type, DataWriter& writer) { const UInt8* cur = packet.current(); const UInt8* end = cur+packet.available(); if (type==OBJECT) { // OBJECT writer.beginObject(); do { cur = packet.current(); writer.writePropertyName(_property.c_str()); writeValue(valueType(), writer); // next! while (cur<end && *cur != '&') cur++; packet.next(cur-packet.current() + (*cur=='&')); _type = END; } while (cur<end && (_type=followingType())==OBJECT); writer.endObject(); return true; } writeValue(type, writer); // next! while (cur<end && *cur != '&') cur++; packet.next(cur-packet.current() + (*cur=='&')); _type = END; return true; }
void GeodesicProvider::write(DataWriter &writer) const { writer.write(this->m_source_vertices); writer.write(this->m_target_vertices); writer.write(this->m_algorithm_option); writer.write(this->m_subdivision_level); writer.write(this->m_geodesics); }
void SamplingProvider::write(DataWriter &writer) const { writer.write(this->m_sampling_radius); writer.write(this->m_curvatures); writer.write(this->m_barycentric_areas); writer.write(this->m_geodesics); writer.write(this->m_samples); }
void Observer::saveMap(DataWriter& writer, const std::map<const PlayerId*, CardSet>& map){ writer.write(static_cast<unsigned int>(map.size())); for (std::map<const decore::PlayerId*, decore::CardSet>::const_iterator it = map.begin(); it != map.end(); ++it) { writer.write(mPlayers.index(it->first)); writer.write(it->second.begin(), it->second.end()); } }
void Observer::saveRoundData(DataWriter& writer, const RoundData& roundData){ writer.write(static_cast<unsigned int>(roundData.mPlayers.size())); for(PlayerIds::const_iterator it = roundData.mPlayers.begin(); it != roundData.mPlayers.end(); ++it) { writer.write(mPlayers.index(*it)); } saveMap(writer, roundData.mDroppedCards); saveMap(writer, roundData.mPickedUpCards); }
void Struct_CP_Table::writeStruct(DataWriter &data) const { data.put16(constants.size(), "size"); data.pad16(); foreach (QSharedPointer<Struct_CP> cp, constants) data.putAddress(cp, "constant"); }
bool ClientSocket::connect(const char* host,const char* nick) { hostent* serv = gethostbyname(host); if (!serv) { cout<<"gethostbyname failed\n"; exit(16); } sockaddr_in addr; #ifdef WIN32 int sockfd = socket(PF_INET, SOCK_STREAM, 0); #else int sockfd = socket(AF_INET, SOCK_STREAM, 0); #endif #ifdef WIN32 if (sockfd==INVALID_SOCKET) { cout<<"binding socket failed "<<WSAGetLastError()<<endl; exit(15); } #endif memset(&addr,0,sizeof(addr)); addr.sin_family = AF_INET; #ifdef WIN32 addr.sin_addr.s_addr = ((struct in_addr *)(serv->h_addr))->s_addr; // memcpy(serv->h_addr, &addr.sin_addr.s_addr, serv->h_length); #else bcopy(serv->h_addr, &addr.sin_addr.s_addr, serv->h_length); #endif addr.sin_port = htons(SERVER_PORT); if (::connect(sockfd, (sockaddr*)&addr, sizeof(addr))<0) { perror("Connecting failed"); #ifdef WIN32 cout<<"connect error: "<<WSAGetLastError()<<'\n'; #endif return 0; } #ifndef WIN32 fcntl(sockfd, F_SETFL, O_NONBLOCK); #else unsigned long x=1; ioctlsocket(sockfd, FIONBIO, &x); char flag=1; if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag))<0) { perror("setsockopt TCP_NODELAY"); exit(16); } #endif conn.fd = sockfd; DataWriter w; w.writeByte(CLI_NAME); char buf[33]={}; strncpy(buf,nick,31); w.write(buf,32); conn.write(w); return 1; }
void GameEvent::Save(DataWriter &out) const { out.Write("event"); out.BeginChild(); { if(date) out.Write("date", date.Day(), date.Month(), date.Year()); conditionsToApply.Save(out); for(const System *system : systemsToUnvisit) if(system && !system->Name().empty()) out.Write("unvisit", system->Name()); for(const Planet *planet : planetsToUnvisit) if(planet && !planet->Name().empty()) out.Write("unvisit planet", planet->Name()); for(const System *system : systemsToVisit) if(system && !system->Name().empty()) out.Write("visit", system->Name()); for(const Planet *planet : planetsToVisit) if(planet && !planet->Name().empty()) out.Write("visit planet", planet->Name()); for(const DataNode &change : changes) out.Write(change); } out.EndChild(); }
void Personality::Save(DataWriter &out) const { out.Write("personality"); out.BeginChild(); { out.Write("confusion", confusionMultiplier); for(const auto &it : TOKEN) if(flags & it.second) out.Write(it.first); } out.EndChild(); }
void LOADERDECL Pos_ReadDirect() { static_assert(N <= 3, "N > 3 is not sane!"); auto const scale = posScale; DataWriter dst; DataReader src; for (int i = 0; i < 3; ++i) dst.Write(i<N ? PosScale(src.Read<T>(), scale) : 0.f); LOG_VTX(); }
void LOADERDECL TexCoord_ReadDirect() { auto const scale = tcScale[tcIndex]; DataWriter dst; DataReader src; for (int i = 0; i != N; ++i) dst.Write(TCScale(src.Read<T>(), scale)); LOG_TEX<N>(); ++tcIndex; }
void ConditionSet::Save(DataWriter &out) const { for(const Entry &entry : entries) out.Write(entry.name, entry.op, entry.value); for(const ConditionSet &child : children) { out.Write(child.isOr ? "or" : "and"); out.BeginChild(); { child.Save(out); } out.EndChild(); } }
virtual void run(const dds::domain::DomainParticipant& dp, const dds::topic::Topic<T>& topic, const Params& params) { dds::pub::qos::PublisherQos pqos = dp.default_publisher_qos() << Partition("ishapes"); dds::pub::Publisher pub(dp, pqos); dds::pub::qos::DataWriterQos dwqos = pub.default_datawriter_qos() << Durability::Transient() << Reliability::Reliable(); dds::pub::DataWriter<T> dw(pub, topic, dwqos); const uint32_t period = params.period; const uint32_t samples = params.samples; uint32_t sleep_time = period * 1000; srand(clock()); const uint32_t x0 = 10; const uint32_t y0 = 10; const uint32_t r = 200; const uint32_t dx = 5; const uint32_t dy = 7; // AnyDataWriter work just fine... AnyDataWriter adw = dw; DataWriter<ShapeType> xdw = adw.get<ShapeType>(); std::cout << "Topic Name = " << xdw.topic().name() << "\tType Name = " << xdw.topic().type_name() << std::endl; // ShapeType s = {params.color, x0, y0, params.shape_size}; ShapeType s = {params.color.c_str(), x0 , y0, params.shape_size}; std::cout << ">> Writing Data..."; std::flush(std::cout); for (uint32_t i = 0; i < samples; ++i) { // Regular write dw.write(s); // Stream write dw << s; s.x = (s.x + dx) % r; s.y = (s.y + dy) % r; exampleSleepMilliseconds(sleep_time); // period is in ms } }
void LOADERDECL Pos_ReadIndex() { static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!"); static_assert(N <= 3, "N > 3 is not sane!"); auto const index = DataRead<I>(); auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_POSITION] + (index * arraystrides[ARRAY_POSITION])); auto const scale = posScale; DataWriter dst; for (int i = 0; i < 3; ++i) dst.Write(i<N ? PosScale(Common::FromBigEndian(data[i]), scale) : 0.f); LOG_VTX(); }
void LOADERDECL TexCoord_ReadIndex() { static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!"); auto const index = DataRead<I>(); auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex] + (index * g_main_cp_state.array_strides[ARRAY_TEXCOORD0 + tcIndex])); auto const scale = tcScale[tcIndex]; DataWriter dst; for (int i = 0; i != N; ++i) dst.Write(TCScale(Common::FromBigEndian(data[i]), scale)); LOG_TEX<N>(); ++tcIndex; }
void Material_Medium::WriteData(DataWriter& writer) const { Material::WriteData(writer); MaterialValueGraph graph(List<const MaterialValue*>(Albedo.Get())); writer.WriteDataStructure(graph, "Albedo"); }
void Material_Dielectric::WriteData(DataWriter& writer) const { Material::WriteData(writer); MaterialValueGraph graph(List<const MaterialValue*>(IndexOfRefraction.Get())); writer.WriteDataStructure(graph, "IndexOfRefraction"); }
bool SimpleReadWriter::writeHeader( const ReaderContext& context, bool sorted, int argc, const char **argv, const char *version, const char *rgLine, bool omitSQLines) { char* buffer; size_t size; size_t used; char *localBuffer = NULL; writer->inHeader(true); if (! writer->getBuffer(&buffer, &size)) { return false; } char *writerBuffer = buffer; size_t writerBufferSize = size; while (!format->writeHeader(context, buffer, size, &used, sorted, argc, argv, version, rgLine, omitSQLines)) { delete[] localBuffer; size = 2 * size; localBuffer = new char[size]; buffer = localBuffer; } if (NULL == localBuffer) { _ASSERT(writerBuffer == buffer); writer->advance((unsigned)used, 0); writer->nextBatch(); } else { size_t bytesRemainingToWrite = used; size_t bytesWritten = 0; while (bytesRemainingToWrite > 0) { size_t bytesToWrite = __min(bytesRemainingToWrite, writerBufferSize); memcpy(writerBuffer, localBuffer + bytesWritten, bytesToWrite); writer->advance(bytesToWrite); writer->nextBatch(); if (!writer->getBuffer(&writerBuffer, &writerBufferSize)) { return false; } bytesWritten += bytesToWrite; bytesRemainingToWrite -= bytesToWrite; } delete[] localBuffer; } writer->inHeader(false); return true; }
void Struct_Class::writeStruct(DataWriter &data) const { data.putAddress(constantPoolTable, "constantPoolTable"); data.putAddress(fieldPoolTable, "fieldPoolTable"); data.putAddress(methodPoolTable, "methodPoolTable"); data.put16(inheritedStaticDataSize + ownStaticDataSize, "staticDataSize"); data.put16(inheritedInstanceDataSize + ownInstanceDataSize, "instanceDataSize"); data.put16(staticDataHandle, "staticDataHandle"); data.pad16(); }
// Write account information to a saved game file. void Account::Save(DataWriter &out) const { out.Write("account"); out.BeginChild(); { out.Write("credits", credits); if(salariesOwed) out.Write("salaries", salariesOwed); out.Write("score", creditScore); out.Write("history"); out.BeginChild(); { for(int64_t worth : history) out.Write(worth); } out.EndChild(); for(const Mortgage &mortgage : mortgages) mortgage.Save(out); } out.EndChild(); }
void PartawareProvider::write(DataWriter &writer) const { writer.write(this->m_cmc_rays_count); writer.write(this->m_cmc_rays_theta); writer.write(this->m_vsi_rays_count); writer.write(this->m_geodestic_weight); writer.write(this->m_angular_weight); writer.write(this->m_vsi_weight); writer.write(this->m_graph); }
void GeomLoader::loadMaterial(const std::string& filename, DataWriter& dataWriter) { std::ifstream matFile(filename); if (!matFile.is_open()) return; Json::Value root; Json::Reader reader; bool parsingSuccessful = reader.parse(matFile, root); matFile.close(); if (!parsingSuccessful) return; for (size_t i = 0; i < root.size(); i++) { Data::Material mat; mat.diffuseMapFilename = root[i]["diffuseMap"].asString(); mat.normalMapFilename = root[i]["normalMap"].asString(); mat.specularMapFilename = root[i]["specularMap"].asString(); if (i < dataWriter.getMeshesRef().size()) { dataWriter.getMeshesRef()[i].material = mat; } } }
void QueryReader::writeValue(UInt8 type, DataWriter& writer) { switch (type) { case STRING: writer.writeString(_value.data(),_value.size()); break; case NUMBER: writer.writeNumber(_number); break; case BOOLEAN: writer.writeBoolean(_number != 0); break; case DATE: writer.writeDate(_date); break; default: writer.writeNull(); break; } }
void Observer::save(DataWriter& writer) { writer.write(mGameCards.begin(), mGameCards.end()); writer.write(mGameCardsCount); writer.write(mTrumpSuit); writer.write(static_cast<unsigned int>(mPlayers.size())); for (PlayerIds::const_iterator it = mPlayers.begin(); it != mPlayers.end(); ++it) { unsigned int playerIndex = mPlayers.index(*it); writer.write(playerIndex); writer.write(mPlayersCards.at(*it)); } writer.write(static_cast<unsigned int>(mRoundsData.size())); for (std::vector<const RoundData*>::const_iterator it = mRoundsData.begin(); it != mRoundsData.end(); ++it) { saveRoundData(writer, **it); } writer.write(mCurrentRoundIndex); // save if mCurrentRoundData exist writer.write(static_cast<bool>(mCurrentRoundData)); if (mCurrentRoundData) { saveRoundData(writer, *mCurrentRoundData); } }
void Galaxy::Save(DataWriter &file) const { if(name.isEmpty()) file.Write("galaxy"); else file.Write("galaxy", name); file.BeginChild(); { file.Write("pos", position.x(), position.y()); file.Write("sprite", sprite); for(const DataNode &node : unparsed) file.Write(node); } file.EndChild(); }
void ClientSocket::sendState() { Unit* p = g.player; DataWriter w; w.writeByte(CLI_STATE); w.writeInt(p->movex); w.writeInt(p->movey); w.writeDouble(p->d); w.writeByte(p->shooting); w.writeInt(g.weapon); conn.write(w); }
int main() { cout << "starting test" << endl; DataWriter myWriter; writerData myData; myData.partsdir = "/home/kevin/parts"; myData.donedir = "/home/kevin/done"; myData.filestr = "test"; calibrationData myCalibration; myCalibration.numSensors = 0; cout << "Configuring" << endl; myWriter.configure(myData,myCalibration); cout << "Opening" << endl; myWriter.openFile(); // Get current time: cout << "Timestamping" << endl; timeval theTime; gettimeofday(&theTime, NULL); myWriter.writeTimeStamp(theTime); cout << "writing" << endl; double hey = 1.123213231; myWriter.writeData(hey); cout << "sleeping 5" << endl; cout << "closing" << endl; myWriter.closeFile(); cout << endl; //DataWriter::parseFile("/home/kevin/done/test_1319919419.dat"); cout << endl; cout << endl; return 0; }
void GzipWriterFilterSupplier::onClosing( DataWriterSupplier* supplier) { if (bamFormat) { closing = true; DataWriter* writer = supplier->getWriter(); // write empty block as BAM end of file marker static _uint8 eof[] = { 0x1f, 0x8b, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x06, 0x00, 0x42, 0x43, 0x02, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; char* buffer; size_t bytes; if (! (writer->getBuffer(&buffer, &bytes) && bytes >= sizeof(eof))) { WriteErrorMessage("no space to write eof marker\n"); soft_exit(1); } memcpy(buffer, eof, sizeof(eof)); writer->advance(sizeof(eof)); // add final translation for last empty block writer->nextBatch(); char* ignore; pair<_uint64,_uint64> last; size_t used; writer->getBatch(-1, &ignore, NULL, &used, (size_t*) &last.second, NULL, (size_t*) &last.first); last.second += used; translation.push_back(last); writer->close(); delete writer; } // sort translations std::sort(translation.begin(), translation.end(), translationComparator); }
void Connection::write(DataWriter& w) { write(w.data(), w.len()); }