void ProgressMeter::receiveLocalizations(const EngineResult& er) { if ( er.forImage+1*camera::frame > max ) { max = er.forImage+1*camera::frame; DEBUG("Progress at " << max); if ( length.is_initialized() ) { boost::units::quantity<camera::time,float> diff = (max - first); DEBUG("Diff is " << diff); float ratio = diff / *length; DEBUG("Ratio is " << ratio << " at progress " << progress()); progress.setValue( std::min( round(ratio / 0.01), 99.0 ) * 0.01 ); } else { progress.setValue( (er.forImage / (10*camera::frame)) % 100 / 100.0 ); } } }
NetworkImagingRemoteHandler(vrpn_ConnectionPtr const &conn, std::string const &deviceName, boost::optional<OSVR_ChannelCount> sensor, common::InterfaceList &ifaces) : m_dev(common::createClientDevice(deviceName, conn)), m_interfaces(ifaces), m_all(!sensor.is_initialized()), m_sensor(sensor) { auto imaging = common::ImagingComponent::create(); m_dev->addComponent(imaging); imaging->registerImageHandler( [&](common::ImageData const &data, util::time::TimeValue const ×tamp) { m_handleImage(data, timestamp); }); OSVR_DEV_VERBOSE("Constructed an ImagingHandler for " << deviceName); }
/** * This method evaluates the path at a given time and returns the target * position and velocity of the robot. * * @param t Time (in seconds) since the robot started the path. Throws an * exception if t<0 * @return A MotionInstant containing the position and velocity at the given * time if @t is within the range of the path. If @t is not within the * time range of this path, this method returns boost::none. */ virtual boost::optional<RobotInstant> evaluate( RJ::Seconds t) const override { if (!path) { return boost::none; } boost::optional<RobotInstant> instant = path->evaluate(t); if (!angleFunction) { return instant; } else { if (instant) { instant->angle = angleFunction->operator()(instant->motion); return instant; } else { return boost::none; } } }
osmium::Box parse_osmium_t::parse_bbox(const boost::optional<std::string> &bbox) { double minx, maxx, miny, maxy; int n = sscanf(bbox->c_str(), "%lf,%lf,%lf,%lf", &minx, &miny, &maxx, &maxy); if (n != 4) throw std::runtime_error("Bounding box must be specified like: minlon,minlat,maxlon,maxlat\n"); if (maxx <= minx) throw std::runtime_error("Bounding box failed due to maxlon <= minlon\n"); if (maxy <= miny) throw std::runtime_error("Bounding box failed due to maxlat <= minlat\n"); fprintf(stderr, "Applying Bounding box: %f,%f to %f,%f\n", minx, miny, maxx, maxy); return osmium::Box(minx, miny, maxx, maxy); }
void CClient::installNewBattleInterface(std::shared_ptr<CBattleGameInterface> battleInterface, boost::optional<PlayerColor> color, bool needCallback) { boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim); PlayerColor colorUsed = color.get_value_or(PlayerColor::UNFLAGGABLE); if(!color) privilegedBattleEventReceivers.push_back(battleInterface); battleints[colorUsed] = battleInterface; if(needCallback) { logGlobal->trace("\tInitializing the battle interface for player %s", *color); auto cbc = std::make_shared<CBattleCallback>(color, this); battleCallbacks[colorUsed] = cbc; battleInterface->init(cbc); } }
void CClient::installNewPlayerInterface(std::shared_ptr<CGameInterface> gameInterface, boost::optional<PlayerColor> color, bool battlecb) { boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim); PlayerColor colorUsed = color.get_value_or(PlayerColor::UNFLAGGABLE); if(!color) privilegedGameEventReceivers.push_back(gameInterface); playerint[colorUsed] = gameInterface; logGlobal->trace("\tInitializing the interface for player %s", colorUsed); auto cb = std::make_shared<CCallback>(gs, color, this); callbacks[colorUsed] = cb; battleCallbacks[colorUsed] = cb; gameInterface->init(cb); installNewBattleInterface(gameInterface, color, battlecb); }
Transaction::pointer Transaction::transactionFromSQL ( boost::optional<std::uint64_t> const& ledgerSeq, boost::optional<std::string> const& status, Blob const& rawTxn, Validate validate) { std::uint32_t const inLedger = rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or (0)); SerialIter it (makeSlice(rawTxn)); auto txn = std::make_shared<STTx> (it); std::string reason; auto tr = std::make_shared<Transaction> (txn, validate, reason); tr->setStatus (sqlTransactionStatus (status)); tr->setLedger (inLedger); return tr; }
/** * Add a new entry in the Link Responde Pool. * * @param user MIH source identifier. * @param tid The transaction identifier. * @param link_scan_rsp_list The link scan response list. * @param link_ac_result The link action result */ void link_response_pool::add(mih::octet_string user, uint16 tid, boost::optional<mih::link_scan_rsp_list> link_scan_rsp_list, mih::link_ac_result link_ac_result) { pending_link_response p; p.user.assign(user); p.tid = tid; action ac; if(link_scan_rsp_list.is_initialized()) { ac.link_scan_rsp_list = link_scan_rsp_list; } ac.link_ac_result = link_ac_result; p.response = ac; boost::mutex::scoped_lock lock(_mutex); _cpool.push_back(p); }
bool PeopleDefinition_Impl::setPeopleperSpaceFloorArea(boost::optional<double> peopleperSpaceFloorArea) { bool result = false; if (peopleperSpaceFloorArea) { result = setDouble(OS_People_DefinitionFields::PeopleperSpaceFloorArea,peopleperSpaceFloorArea.get()); if (result) { result = setString(OS_People_DefinitionFields::NumberofPeopleCalculationMethod, "People/Area"); OS_ASSERT(result); result = setString(OS_People_DefinitionFields::NumberofPeople, ""); OS_ASSERT(result); result = setString(OS_People_DefinitionFields::SpaceFloorAreaperPerson, ""); OS_ASSERT(result); } } else { if (istringEqual("People/Area", this->numberofPeopleCalculationMethod())){ result = setDouble(OS_People_DefinitionFields::PeopleperSpaceFloorArea, 0.0); } } return result; }
bool PeopleDefinition_Impl::setSpaceFloorAreaperPerson(boost::optional<double> spaceFloorAreaperPerson) { bool result(false); if (spaceFloorAreaperPerson) { result = setDouble(OS_People_DefinitionFields::SpaceFloorAreaperPerson,spaceFloorAreaperPerson.get()); if (result) { result = setString(OS_People_DefinitionFields::NumberofPeopleCalculationMethod, "Area/Person"); OS_ASSERT(result); result = setString(OS_People_DefinitionFields::NumberofPeople, ""); OS_ASSERT(result); result = setString(OS_People_DefinitionFields::PeopleperSpaceFloorArea, ""); OS_ASSERT(result); } } else { if (istringEqual("Area/Person", this->numberofPeopleCalculationMethod())){ result = setDouble(OS_People_DefinitionFields::SpaceFloorAreaperPerson, 0.0); } } return result; }
void CommitChunkMigrationRequest::appendAsCommand( BSONObjBuilder* builder, const NamespaceString& nss, const ShardId& fromShard, const ShardId& toShard, const ChunkType& migratedChunkType, const boost::optional<ChunkType>& controlChunkType) { invariant(builder->asTempObj().isEmpty()); invariant(nss.isValid()); builder->append(kConfigSvrCommitChunkMigration, nss.ns()); builder->append(kFromShard, fromShard.toString()); builder->append(kToShard, toShard.toString()); builder->append(kMigratedChunk, migratedChunkType.toBSON()); if (controlChunkType) { builder->append(kControlChunk, controlChunkType->toBSON()); } }
std::unique_ptr<AbstractJacobianAssembler> createJacobianAssembler( boost::optional<BaseLib::ConfigTree> const& config) { if (!config) return std::unique_ptr<AbstractJacobianAssembler>( new AnalyticalJacobianAssembler); //! \ogs_file_param{process__jacobian_assembler__type} auto const type = config->peekConfigParameter<std::string>("type"); if (type == "Analytical") { config->ignoreConfigParameter("type"); return std::unique_ptr<AbstractJacobianAssembler>( new AnalyticalJacobianAssembler); } else if (type == "CentralDifferences") { return createCentralDifferencesJacobianAssembler(*config); } OGS_FATAL("Unknown Jacobian assembler type: `%s'.", type.c_str()); }
void display_template_info(const Glib::RefPtr<Gst::PadTemplate> &tpl, const Glib::RefPtr<Gtk::TreeStore> &model, const Gtk::TreeModelColumn<Glib::ustring> &col_name, const Gtk::TreeModelColumn<Glib::ustring> &col_value, boost::optional<const Gtk::TreeModel::Row&> parent_row) { Gtk::TreeRow row; if (parent_row) { row = APPEND_SUB_ROW(_("Template"), tpl->get_name_template(), parent_row.get()); } else { row = *(model->append()); row[col_name] = _("Template"); row[col_value] = tpl->get_name_template(); } APPEND_SUB_ROW(_("Presence"), get_presence_str(tpl->get_presence()), row); APPEND_SUB_ROW(_("Direction"), get_direction_str(tpl->get_direction()), row); row = APPEND_SUB_ROW("Caps", "", row); display_caps(tpl->get_caps(), model, col_name, col_value, row); }
void dataFrameTest(IOBuf* body, uint32_t dataLen, boost::optional<uint8_t> padLen) { uint32_t frameLen = uint32_t(dataLen); if (padLen) { frameLen += 1 + padLen.get(); } if (frameLen > kMaxFramePayloadLength) { EXPECT_DEATH_NO_CORE(writeData(queue_, body->clone(), 1, padLen, false), ".*"); } else { writeData(queue_, body->clone(), 1, padLen, false); FrameHeader outHeader; std::unique_ptr<IOBuf> outBuf; parse(&parseData, outHeader, outBuf); EXPECT_EQ(outBuf->moveToFbString(), body->moveToFbString()); } queue_.move(); // reset everything }
Vector OrientedPlane3DirectionPrior::evaluateError(const OrientedPlane3& plane, boost::optional<Matrix&> H) const { if (H) { Matrix H_p; Unit3 n_hat_p = measured_p_.normal(); Unit3 n_hat_q = plane.normal(); Vector e = n_hat_p.error(n_hat_q, H_p); H->resize(2, 3); H->block<2, 2>(0, 0) << H_p; H->block<2, 1>(0, 2) << Matrix::Zero(2, 1); return e; } else { Unit3 n_hat_p = measured_p_.normal(); Unit3 n_hat_q = plane.normal(); Vector e = n_hat_p.error(n_hat_q); return e; } }
void load( Archive & ar, boost::optional< T > & t, const unsigned int /*version*/ ){ bool tflag; ar >> boost::serialization::make_nvp("initialized", tflag); if (tflag){ boost::serialization::item_version_type item_version(0); boost::archive::library_version_type library_version( ar.get_library_version() ); if(boost::archive::library_version_type(3) < library_version){ // item_version is handled as an attribute so it doesnt need an NVP ar >> BOOST_SERIALIZATION_NVP(item_version); } detail::stack_construct<Archive, T> aux(ar, item_version); ar >> boost::serialization::make_nvp("value", aux.reference()); t.reset(aux.reference()); }
void load( Archive & ar, boost::optional< T > & t, const unsigned int version ){ bool tflag; ar >> boost::serialization::make_nvp("initialized", tflag); if(! tflag){ t.reset(); return; } if(0 == version){ boost::serialization::item_version_type item_version(0); boost::archive::library_version_type library_version( ar.get_library_version() ); if(boost::archive::library_version_type(3) < library_version){ ar >> BOOST_SERIALIZATION_NVP(item_version); }
StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& query, const BSONObj& sort, boost::optional<long long> limit, const OID& epoch) { // Query to retrieve the chunks. Query fullQuery(query); fullQuery.sort(sort); try { DBDirectClient client(opCtx); std::string chunkMetadataNs = ChunkType::ShardNSPrefix + nss.ns(); std::unique_ptr<DBClientCursor> cursor = client.query(chunkMetadataNs, fullQuery, limit.get_value_or(0)); if (!cursor) { return {ErrorCodes::OperationFailed, str::stream() << "Failed to establish a cursor for reading " << chunkMetadataNs << " from local storage"}; } std::vector<ChunkType> chunks; while (cursor->more()) { BSONObj document = cursor->nextSafe().getOwned(); auto statusWithChunk = ChunkType::fromShardBSON(document, epoch); if (!statusWithChunk.isOK()) { return {statusWithChunk.getStatus().code(), str::stream() << "Failed to parse chunk '" << document.toString() << "' due to " << statusWithChunk.getStatus().reason()}; } chunks.push_back(std::move(statusWithChunk.getValue())); } return chunks; } catch (const DBException& ex) { return ex.toStatus(); } }
// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// void TextureManager::UpdateTextureFilters(boost::optional<TextureFilterMode> oldMode) { #ifdef GLEW_EXT_texture_filter_anisotropic GLfloat aniLevelVal(0.0f); if(m_currTexFilterMode == eAnisotropic) { aniLevelVal = InterpolateFloat(m_anisotropicLinearLevel, 0.0f, m_maxAnisotropicValue); } #endif GF_CLEAR_GL_ERROR(); for(ElementMap::iterator i = m_elementsMap.begin(), end = m_elementsMap.end(); i != end; ++i) { GLenum currTarget(((*i).second).m_glTarget); if(currTarget != GL_TEXTURE_RECTANGLE) { Bind(((*i).second).m_id, currTarget); glTexParameteri(currTarget, GL_TEXTURE_MIN_FILTER, m_currMinFilter); GF_CHECK_GL_ERROR_TRC("TextureManager::UpdateTextureFilters(): "); glTexParameteri(currTarget, GL_TEXTURE_MAG_FILTER, m_currMagFilter); GF_CHECK_GL_ERROR_TRC("TextureManager::UpdateTextureFilters(): "); #ifdef GLEW_EXT_texture_filter_anisotropic if(m_currTexFilterMode == eAnisotropic) { glTexParameterf(currTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniLevelVal); GF_CHECK_GL_ERROR_TRC("TextureManager::UpdateTextureFilters(): "); } else if(oldMode.is_initialized() && *oldMode == eAnisotropic) { // Turn down ani level if we are switching away from it. glTexParameterf(currTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, 0.0f); GF_CHECK_GL_ERROR_TRC("TextureManager::UpdateTextureFilters(): "); } #endif } } }
bool CDocumentItemCollection::AddItem(CDocumentItemPtr item, boost::optional<size_t> position) { bool result = true; if (position) { size_t pos = position.get(); if (pos > m_items.size()) { result = false; } else { m_items.emplace(m_items.begin() + pos, item); } } else { m_items.emplace_back(item); } return result; }
inline bool interpret_argument_value( cstring source, boost::optional<std::list<T> >& res, int ) { BOOST_RT_PARAM_TRACE( "In interpret_argument_value<std::list<T>>" ); res = std::list<T>(); while( !source.is_empty() ) { // !! should we use token_iterator cstring::iterator single_value_end = std::find( source.begin(), source.end(), BOOST_RT_PARAM_LITERAL( ',' ) ); boost::optional<T> value; interpret_argument_value( cstring( source.begin(), single_value_end ), value, 0 ); res->push_back( *value ); source.trim_left( single_value_end + 1 ); } return true; }
std::pair<std::size_t, std::size_t> binary::range(int begin, boost::optional<int> end_) { int n = get_length(); if (begin < 0) begin = n + begin; int end = end_.get_value_or(n); if (end < 0) end = n + end; if (begin > n) begin = n; if (end > n) end = n; if (end < begin) end = begin; return std::pair<std::size_t, std::size_t>(begin, end); }
size_t dedup_methods_helper( const Scope& scope, const std::vector<DexMethod*>& to_dedup, std::vector<DexMethod*>& replacements, boost::optional<std::unordered_map<DexMethod*, MethodOrderedSet>>& new_to_old) { if (to_dedup.size() <= 1) { replacements = to_dedup; return 0; } size_t dedup_count = 0; auto grouped_methods = group_identical_methods(to_dedup); std::unordered_map<DexMethod*, DexMethod*> duplicates_to_replacement; for (auto& group : grouped_methods) { auto replacement = *group.begin(); for (auto m : group) { duplicates_to_replacement[m] = replacement; // Update dedup map if (new_to_old == boost::none) { continue; } if (new_to_old->count(m) > 0) { auto orig_old_list = new_to_old->at(m); new_to_old->erase(m); for (auto orig_old : orig_old_list) { new_to_old.get()[replacement].insert(orig_old); } } new_to_old.get()[replacement].insert(m); } if (new_to_old != boost::none) { new_to_old.get()[replacement].insert(replacement); } replacements.push_back(replacement); if (group.size() > 1) { dedup_count += group.size() - 1; TRACE(METH_DEDUP, 9, "dedup: group %d replacement %s\n", group.size(), SHOW(replacement)); } } method_reference::update_call_refs_simple(scope, duplicates_to_replacement); return dedup_count; }
void save( Archive & ar, const boost::optional< T > & t, const unsigned int /*version*/ ){ // It is an inherent limitation to the serialization of optional.hpp // that the underlying type must be either a pointer or must have a // default constructor. It's possible that this could change sometime // in the future, but for now, one will have to work around it. This can // be done by serialization the optional<T> as optional<T *> #if ! defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) BOOST_STATIC_ASSERT( boost::serialization::detail::is_default_constructible<T>::value || boost::is_pointer<T>::value ); #endif const bool tflag = t.is_initialized(); ar << boost::serialization::make_nvp("initialized", tflag); if (tflag){ ar << boost::serialization::make_nvp("value", *t); } }
bool InternalMassDefinition_Impl::setSurfaceAreaperPerson(boost::optional<double> surfaceAreaperPerson) { bool result = true; if (surfaceAreaperPerson) { if (*surfaceAreaperPerson < 0){ result = false; }else{ result = setString(OS_InternalMass_DefinitionFields::DesignLevelCalculationMethod, "SurfaceArea/Person"); OS_ASSERT(result); result = setString(OS_InternalMass_DefinitionFields::SurfaceArea, ""); OS_ASSERT(result); result = setString(OS_InternalMass_DefinitionFields::SurfaceAreaperSpaceFloorArea, ""); OS_ASSERT(result); result = setDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperPerson, surfaceAreaperPerson.get()); OS_ASSERT(result); } } else { if (istringEqual("SurfaceArea/Person", this->designLevelCalculationMethod())){ result = setDouble(OS_InternalMass_DefinitionFields::SurfaceAreaperPerson, 0.0); } } return result; }
typename command::response readresponse() { while( true ) { if( !readpacket() ) { COMMA_THROW( comma::exception, "expected command response, got end of stream" ); } switch( m_header->type() ) { case header::scan_type: case header::fault_type: // cannot throw yet, since need to get response first break; case header::response_type: { unsigned int id = reinterpret_cast< const commands::response_header* >( m_payload )->id() & 0x3fff; if( int( id ) != *m_commandId ) { COMMA_THROW( comma::exception, "expected response to command 0x" << std::hex << *m_commandId << ", got 0x" << id << std::dec ); } m_commandId.reset(); return *( reinterpret_cast< typename command::response* >( m_payload ) ); } default: COMMA_THROW( comma::exception, "expected command response, got packet of unknown type (0x" << std::hex << m_header->type() << std::dec ); } } }
bool ElectricEquipmentDefinition_Impl::setWattsperPerson(boost::optional<double> wattsperPerson) { bool result = true; if (wattsperPerson) { if (*wattsperPerson < 0){ result = false; }else{ result = setString(OS_ElectricEquipment_DefinitionFields::DesignLevelCalculationMethod, "Watts/Person"); OS_ASSERT(result); result = setString(OS_ElectricEquipment_DefinitionFields::DesignLevel, ""); OS_ASSERT(result); result = setString(OS_ElectricEquipment_DefinitionFields::WattsperSpaceFloorArea, ""); OS_ASSERT(result); result = setDouble(OS_ElectricEquipment_DefinitionFields::WattsperPerson, wattsperPerson.get()); OS_ASSERT(result); } } else { if (istringEqual("Watts/Person", this->designLevelCalculationMethod())){ result = setDouble(OS_ElectricEquipment_DefinitionFields::WattsperPerson, 0.0); } } return result; }
bool LightsDefinition_Impl::setWattsperSpaceFloorArea(boost::optional<double> wattsperSpaceFloorArea) { bool result = true; if (wattsperSpaceFloorArea) { if (*wattsperSpaceFloorArea < 0){ result = false; }else{ result = setString(OS_Lights_DefinitionFields::DesignLevelCalculationMethod, "Watts/Area"); OS_ASSERT(result); result = setString(OS_Lights_DefinitionFields::LightingLevel, ""); OS_ASSERT(result); result = setDouble(OS_Lights_DefinitionFields::WattsperSpaceFloorArea, wattsperSpaceFloorArea.get()); OS_ASSERT(result); result = setString(OS_Lights_DefinitionFields::WattsperPerson, ""); OS_ASSERT(result); } } else { if (istringEqual("Watts/Area", this->designLevelCalculationMethod())){ result = setDouble(OS_Lights_DefinitionFields::WattsperSpaceFloorArea, 0.0); } } return result; }
void save( Archive & ar, const boost::optional< T > & t, const unsigned int /*version*/ ){ const bool tflag = t.is_initialized(); ar << boost::serialization::make_nvp("initialized", tflag); if (tflag){ const boost::serialization::item_version_type item_version(version< T >::value); #if 0 const boost::archive::library_version_type library_version( ar.get_library_version() }; if(boost::archive::library_version_type(3) < library_version){ ar << BOOST_SERIALIZATION_NVP(item_version); } #else ar << BOOST_SERIALIZATION_NVP(item_version); #endif ar << boost::serialization::make_nvp("value", *t); } }
bool HotWaterEquipmentDefinition_Impl::setDesignLevel(boost::optional<double> designLevel) { bool result = true; if (designLevel) { if (*designLevel < 0){ result = false; }else{ result = setString(OS_HotWaterEquipment_DefinitionFields::DesignLevelCalculationMethod, "EquipmentLevel"); OS_ASSERT(result); result = setDouble(OS_HotWaterEquipment_DefinitionFields::DesignLevel, designLevel.get()); OS_ASSERT(result); result = setString(OS_HotWaterEquipment_DefinitionFields::WattsperSpaceFloorArea, ""); OS_ASSERT(result); result = setString(OS_HotWaterEquipment_DefinitionFields::WattsperPerson, ""); OS_ASSERT(result); } } else { if (istringEqual("EquipmentLevel", this->designLevelCalculationMethod())){ result = setDouble(OS_HotWaterEquipment_DefinitionFields::DesignLevel, 0.0); } } return result; }