当前位置: 首页>>代码示例>>C++>>正文


C++ std::weak_ptr类代码示例

本文整理汇总了C++中std::weak_ptr的典型用法代码示例。如果您正苦于以下问题:C++ weak_ptr类的具体用法?C++ weak_ptr怎么用?C++ weak_ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了weak_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initialize

	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_;
		}
	}
开发者ID:seto1221,项目名称:slib,代码行数:11,代码来源:shared_scoped_signal_mask.hpp

示例2:

 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));
         
     }
 }
开发者ID:amitkumar3968,项目名称:VideoCore,代码行数:11,代码来源:GenericAudioMixer.cpp

示例3:

//------------------------------------------//
// Texture2DAssetLoader::StartupLoader				
//------------------------------------------//
bool Texture2DAssetLoader::StartupLoader(std::weak_ptr<class Renderer> renderer)
{
	if (renderer.lock() == nullptr)
	{
		//Fail something
		return false;
	}

	mWeakRenderer = renderer;
	return true;
}
开发者ID:TaintedGear,项目名称:GameFramework,代码行数:14,代码来源:Texture2DAssetLoader.cpp

示例4: setAssociatedNode

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();
}
开发者ID:shirayukikitsune,项目名称:SceneGraph,代码行数:11,代码来源:ConstraintComponent.cpp

示例5: return_to_pool

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;
    }
}
开发者ID:rtobar,项目名称:spead2,代码行数:11,代码来源:common_memory_pool.cpp

示例6:

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);
	}
}
开发者ID:joisbp22,项目名称:DemoProject,代码行数:11,代码来源:Renderable2DBox.cpp

示例7: Add

	// 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);
	}
开发者ID:JISyed,项目名称:HedronSpace,代码行数:12,代码来源:PhysicsEntityContainer.cpp

示例8: get

 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]);
 }
开发者ID:BreezeEngine,项目名称:breezecpp.old,代码行数:12,代码来源:handlvec.hpp

示例9: LOG

 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);
 }
开发者ID:0xBaca,项目名称:MiniReader,代码行数:12,代码来源:Windows.cpp

示例10: GetPlayerList

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;
}
开发者ID:zmxaini10250,项目名称:GameServer,代码行数:12,代码来源:Process.cpp

示例11: lg

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();
}
开发者ID:TomasMM,项目名称:emir,代码行数:13,代码来源:surface_stack.cpp

示例12: makeCallback

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));
    }
  };
}
开发者ID:Sihak,项目名称:react-native-pipay,代码行数:13,代码来源:CxxNativeModule.cpp

示例13: invalid_parameter

	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);
	}
开发者ID:rollingthunder,项目名称:ki2-biosim,代码行数:13,代码来源:model.cpp

示例14: visitModuleFile

  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";
  }
开发者ID:2trill2spill,项目名称:freebsd,代码行数:55,代码来源:FrontendActions.cpp

示例15: getUDTSession

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;
}
开发者ID:hailynch,项目名称:pothos,代码行数:11,代码来源:SocketEndpoint.cpp


注:本文中的std::weak_ptr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。