void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind) override { auto *File = CI.getFileManager().getFile(Filename); assert(File && "missing file for loaded module?"); // Only rewrite each module file once. if (!Rewritten.insert(File).second) return; serialization::ModuleFile *MF = CI.getModuleManager()->getModuleManager().lookup(File); assert(File && "missing module file for loaded module?"); // Not interested in PCH / preambles. if (!MF->isModule()) return; auto OS = Out.lock(); assert(OS && "loaded module file after finishing rewrite action?"); (*OS) << "#pragma clang module build "; if (isValidIdentifier(MF->ModuleName)) (*OS) << MF->ModuleName; else { (*OS) << '"'; OS->write_escaped(MF->ModuleName); (*OS) << '"'; } (*OS) << '\n'; // Rewrite the contents of the module in a separate compiler instance. CompilerInstance Instance(CI.getPCHContainerOperations(), &CI.getPreprocessor().getPCMCache()); Instance.setInvocation( std::make_shared<CompilerInvocation>(CI.getInvocation())); Instance.createDiagnostics( new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()), /*ShouldOwnClient=*/true); Instance.getFrontendOpts().DisableFree = false; Instance.getFrontendOpts().Inputs.clear(); Instance.getFrontendOpts().Inputs.emplace_back( Filename, InputKind(InputKind::Unknown, InputKind::Precompiled)); Instance.getFrontendOpts().ModuleFiles.clear(); Instance.getFrontendOpts().ModuleMapFiles.clear(); // Don't recursively rewrite imports. We handle them all at the top level. Instance.getPreprocessorOutputOpts().RewriteImports = false; llvm::CrashRecoveryContext().RunSafelyOnThread([&]() { RewriteIncludesAction Action; Action.OutputStream = OS; Instance.ExecuteAction(Action); }); (*OS) << "#pragma clang module endbuild /*" << MF->ModuleName << "*/\n"; }
int main() { static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), ""); static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), ""); static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), ""); { const std::weak_ptr<A> pA(std::shared_ptr<A>(new A)); assert(pA.use_count() == 0); assert(B::count == 0); assert(A::count == 0); { std::weak_ptr<B> pB(pA); assert(B::count == 0); assert(A::count == 0); assert(pB.use_count() == 0); assert(pA.use_count() == 0); } assert(pA.use_count() == 0); assert(B::count == 0); assert(A::count == 0); } assert(B::count == 0); assert(A::count == 0); { std::weak_ptr<A> pA; assert(pA.use_count() == 0); assert(B::count == 0); assert(A::count == 0); { std::weak_ptr<B> pB(pA); assert(B::count == 0); assert(A::count == 0); assert(pB.use_count() == 0); assert(pA.use_count() == 0); } assert(pA.use_count() == 0); assert(B::count == 0); assert(A::count == 0); } assert(B::count == 0); assert(A::count == 0); }
void initialize(std::weak_ptr<scoped_signal_mask>& sigmask_wptr) { static std::mutex mutex_; std::lock_guard<std::mutex> lk(mutex_); sigmask_sptr_ = sigmask_wptr.lock(); if (!sigmask_sptr_) { signal_set sigset{ SignalNumber... }; sigmask_sptr_ = std::make_shared<scoped_signal_mask>(sigset); sigmask_wptr = sigmask_sptr_; } }
static std::shared_ptr<UDTSession> getUDTSession(void) { //TODO needs a lock std::shared_ptr<UDTSession> sess = UDTWeakSession.lock(); if (not sess) { sess.reset(new UDTSession()); UDTWeakSession = sess; } return sess; }
void GenericAudioMixer::setSourceGain(std::weak_ptr<ISource> source, float gain) { auto s = source.lock(); if(s) { auto hash = std::hash<std::shared_ptr<ISource>>()(s); m_inGain[hash] = std::max(0.f, std::min(1.f, gain)); } }
void log_gl_error(const gl_error& error) { std::shared_ptr<context> current_locked_context = current_context.lock(); if (current_locked_context && current_locked_context->state().error() == GL_NO_ERROR) { current_locked_context->state().error() = error.error_code(); } log_message(GL_DEBUG_SOURCE_API_KHR, GL_DEBUG_TYPE_ERROR_KHR, error.error_code(), GL_DEBUG_SEVERITY_HIGH_KHR, format("%s: %s", error.error_code_description().c_str(), error.error_msg().c_str())); }
//------------------------------------------// // Texture2DAssetLoader::StartupLoader //------------------------------------------// bool Texture2DAssetLoader::StartupLoader(std::weak_ptr<class Renderer> renderer) { if (renderer.lock() == nullptr) { //Fail something return false; } mWeakRenderer = renderer; return true; }
static void av_qsv_log_callback(void *ptr, int level, const char *fmt, va_list vl) { if (auto pQSVLog = g_pQSVLog.lock()) { const int qsv_log_level = log_level_av2rgy(level); if (qsv_log_level >= pQSVLog->getLogLevel() && pQSVLog->logFileAvail()) { char mes[4096]; av_log_format_line(ptr, level, fmt, vl, mes, sizeof(mes), &print_prefix); pQSVLog->write_log(qsv_log_level, char_to_tstring(mes, CP_UTF8).c_str(), true); } } av_log_default_callback(ptr, level, fmt, vl); }
void ConstraintComponent::setAssociatedNode(std::weak_ptr<kitsune::scenegraph::Node> AssociatedNode) { auto associated = AssociatedNode.lock(); if (!associated) return; associatedNodeComponentAddedListener = associated->addComponentAddedEvent(std::bind(&ConstraintComponent::onNodeAddComponent, this, std::placeholders::_1)); associatedNodeComponentRemovedListener = associated->addComponentRemovedEvent(std::bind(&ConstraintComponent::onNodeRemoveComponent, this, std::placeholders::_1)); createConstraint(); }
void memory_pool::return_to_pool(const std::weak_ptr<memory_pool> &self_weak, std::uint8_t *ptr) { std::shared_ptr<memory_pool> self = self_weak.lock(); if (self) self->return_to_pool(ptr); else { log_debug("dropping memory because the pool has been freed"); delete[] ptr; } }
void Renderable2DBox::Render(std::weak_ptr<const RendererBase> renderer) const { std::shared_ptr<const RendererBase> rendererShared = renderer.lock(); if (rendererShared != nullptr) { rendererShared->DrawColoredLine(m_Points[0], m_Points[2], m_Color); rendererShared->DrawColoredLine(m_Points[2], m_Points[3], m_Color); rendererShared->DrawColoredLine(m_Points[3], m_Points[1], m_Color); rendererShared->DrawColoredLine(m_Points[1], m_Points[0], m_Color); } }
std::shared_ptr<std::vector<std::string>> StrBlobPtr::check( std::size_t i, const std::string &msg) const { auto ret = wptr.lock(); if (!ret) { throw std::runtime_error("unbound StrBlobPtr"); } if (i >= ret->size()) { throw std::out_of_range(msg); } return ret; }
// STATIC: void PhysicsEntityContainer::Add(std::weak_ptr<PhysicsEntity> newObject) { // Was this initalized if(!PhysicsEntityContainer::verifyInstantiation()) return; // Check if the pointer is empty if(newObject.expired()) return; // Add it PhysicsEntityContainer::_instance->_listOfContainedObjects.push_front(newObject); }
std::experimental::optional<T> get(std::weak_ptr<handle<T>> handle_wp) { auto hid_sp = handle_wp.lock(); if (!hid_sp) { return std::experimental::optional<T>{}; } handle<T>* hid = hid_sp.get(); if(handle_map[hid->index] != hid_sp){ return std::experimental::optional<T>{}; } return std::experimental::make_optional(container[hid->index]); }
std::shared_ptr<std::vector<std::string>> check(size_type index, string const& message) const { auto blob_ptr = blob_.lock(); if (!blob_ptr) throw std::runtime_error("unbounded shared_ptr"); if (index >= blob_ptr->size()) throw std::out_of_range(message); return blob_ptr; }
nCursesProgressWindow::nCursesProgressWindow(std::weak_ptr<Window> parentWnd){ LOG("Progress window constructor : ", this); if(auto spTmp = parentWnd.lock()){ parentWindow = parentWnd; posx = spTmp->getRows()-1; posy = spTmp->getColumns() - width; file_size = dynamic_cast<nCursesDisplayWindow*>(&*spTmp)->file_size; nCursesWhnd = ::newwin(height, width, posx, posy); ::box(nCursesWhnd, 0, 0); }else throw miniReader::Exception::miniRuntimeException( __FILE__, ":", __LINE__, "Error creating object", this); }
static std::shared_ptr<RawCtx> GetResource(const char * resourceName) { rh_rawpak_ctx _ctx = NULL; if( rh_rawpak_open_ctx(handle,resourceName, &_ctx) != 0) throw LookupException( resourceName ); std::shared_ptr<RawCtx> ctx = std::shared_ptr<RawCtx>(wthis.lock(), _ctx); return ctx; }
int GetPlayerList(const Data& data, std::weak_ptr<CPlayer> player) { if (!SendCheck(player)) { return -1; } PBS2CGetPlayerListRes res; res.set_getplayerlistresult(0); PlayerManager::GetInstance().PlayerList2PB(res); player.lock()->GetSocket().lock()->SendBuff((int)TypeS2CGetPlayerListRes, res); return 0; }
void ms::SurfaceStack::destroy_surface(std::weak_ptr<ms::Surface> const& surface) { { std::lock_guard<std::mutex> lg(guard); auto const p = std::find(surfaces.begin(), surfaces.end(), surface.lock()); if (p != surfaces.end()) surfaces.erase(p); // else; TODO error logging } emit_change_notification(); }
std::function<void(folly::dynamic)> makeCallback( std::weak_ptr<Instance> instance, const folly::dynamic& callbackId) { if (!callbackId.isInt()) { throw std::invalid_argument("Expected callback(s) as final argument"); } auto id = callbackId.getInt(); return [winstance = std::move(instance), id](folly::dynamic args) { if (auto instance = winstance.lock()) { instance->callJSCallback(id, std::move(args)); } }; }
void model::move_creature (const std::weak_ptr<creature>& c, int x, int y) { std::shared_ptr<creature> csp(c.lock()); if (!csp) { std::cerr << "Invalid creature for movement." << std::endl; throw invalid_parameter(); } map_.move_creature(csp, x, y); }
void MAVConnTCPServer::client_closed(std::weak_ptr<MAVConnTCPClient> weak_instp) { if (auto instp = weak_instp.lock()) { bool locked = mutex.try_lock(); logInform(PFXd "Client connection closed, id: %p, address: %s", conn_id, instp.get(), to_string_ss(instp->server_ep).c_str()); client_list.remove(instp); if (locked) mutex.unlock(); } }
std::weak_ptr<vertex> go (char c) { std::weak_ptr<vertex> next; auto itr = children.find(c); if (itr != children.end()) { next = itr->second; } else { if (parent.lock().get() == NULL) { next = root; } else next = get_link().lock()->go(c); } return next; }
void CloudResource::onCloudProvResponseSafetyCb(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode, ESCloudResourceCb cb, std::weak_ptr<CloudResource> this_ptr) { OIC_LOG(DEBUG, ES_CLOUD_RES_TAG, "onCloudProvResponseSafetyCb"); std::shared_ptr<CloudResource> Ptr = this_ptr.lock(); if(Ptr) { cb(headerOptions, rep, eCode); } }
KeyFrameAnimationState::KeyFrameAnimationState(std::weak_ptr<KeyFrameAnimated> animatable, AnimationUpdatedCallback refresh_animation_state): animatable_(animatable), refresh_animation_state_(refresh_animation_state) { auto anim = animatable_.lock(); on_animation_added_ = anim->signal_animation_added().connect( [this](KeyFrameAnimated* animatable, const std::string& name) { if(animatable->animation_count() == 1) { play_animation(name); } } ); }
std::shared_ptr<CAnimTreeNode> CMetaTransPhaseTrans::VGetTransitionTree(const std::weak_ptr<CAnimTreeNode>& a, const std::weak_ptr<CAnimTreeNode>& b, const CAnimSysContext& animSys) const { std::shared_ptr<CAnimTreeNode> nA = a.lock(); CAnimTreeEffectiveContribution cA = nA->GetContributionOfHighestInfluence(); std::shared_ptr<CAnimTreeNode> nB = b.lock(); CAnimTreeEffectiveContribution cB = nB->GetContributionOfHighestInfluence(); float y2A = cA.GetSteadyStateAnimInfo().GetDuration() / cB.GetSteadyStateAnimInfo().GetDuration(); float y1B = cB.GetSteadyStateAnimInfo().GetDuration() / cA.GetSteadyStateAnimInfo().GetDuration(); nB->VSetPhase(zeus::clamp(0.f, 1.f - cA.GetTimeRemaining() / cA.GetSteadyStateAnimInfo().GetDuration(), 1.f)); auto tsA = std::make_shared<CAnimTreeTimeScale>( a, std::make_unique<CLinearAnimationTimeScale>(CCharAnimTime{}, 1.f, x4_transDur, y2A), x4_transDur, CAnimTreeTimeScale::CreatePrimitiveName(a, 1.f, x4_transDur, y2A)); auto tsB = std::make_shared<CAnimTreeTimeScale>( b, std::make_unique<CLinearAnimationTimeScale>(CCharAnimTime{}, y1B, x4_transDur, 1.f), x4_transDur, CAnimTreeTimeScale::CreatePrimitiveName(b, y1B, x4_transDur, 1.f)); return std::make_shared<CAnimTreeTransition>( xc_, tsA, tsB, x4_transDur, xd_runA, x10_flags, CAnimTreeTransition::CreatePrimitiveName(tsA, tsB, x4_transDur.GetSeconds())); }
int GetHeroInfo(const Data& data, std::weak_ptr<CPlayer> player) { if (!SendCheck(player)) { return -1; } PBC2SGetHeroInfoReq req; req.ParseFromArray(data.buffer, data.bufferLength); std::weak_ptr<CHero> p = player.lock()->GetHeroData().GetHeroPack().GetHero(req.heroindex()); if (p.expired()) { return -1; } PBS2CGetHeroInfoRes res; p.lock()->HeroInfo2PB(*res.mutable_heroinfo()); res.set_getheroinforesult(0); player.lock()->GetSocket().lock()->SendBuff((int)TypeS2CGetHeroInfoRes, res); return 0; }
int LoginRegister(const Data& data, std::weak_ptr<CPlayer> player) { if(player.expired()) { return -1; } std::shared_ptr<CPlayer> playerPtr = player.lock(); if (playerPtr->GetSocket().expired()) { return -1; } PBC2SLoginRegisterReq req; req.ParseFromArray(data.buffer, data.bufferLength); PBS2CLoginRegisterRes res; if (DBServer::GetInstance().LoginRegister(req.username().c_str(), req.password().c_str(), res) != 0) { return -1; } player.lock()->GetSocket().lock()->SendBuff((int)TypeS2CLoginRegisterRes, res); return 0; }
void LocationsMgr::new_location( Location::ptr nloc , std::weak_ptr<Location> oloc_w ) { auto oloc = oloc_w.lock(); if( oloc ) nloc->swap_connection( *oloc ); locations[ nloc->connection ] = nloc; nloc->on_location_request( std::bind( &LocationsMgr::new_location, this, std::placeholders::_1 , std::weak_ptr<Location>(nloc) ) ); }
int DeleteUser(const Data& data, std::weak_ptr<CPlayer> player) { if (!SendCheck(player)) { return -1; } PBC2SDeleteUserReq req; req.ParseFromArray(data.buffer, data.bufferLength); PBS2CDeleteUserRes res; if (DBServer::GetInstance().DeleteUser(player.lock()->GetPlayerID(), res) != 0) { return -1; } player.lock()->GetSocket().lock()->SendBuff((int)TypeS2CDeleteUserRes, res); if (res.deleteuserresult() == 1) { player.lock()->GetSocket().lock()->SetPlayer(std::weak_ptr<CPlayer>()); PlayerManager::GetInstance().RemovePlayer(player.lock()->GetPlayerID()); } return 0; }