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


C++ weak_ptr::lock方法代码示例

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


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

示例1: add

void EventHandler::add(std::weak_ptr<EventHandled> handler)
{
   auto fd_ptr = handler.lock();

   for (auto fd : fd_ptr->pollfds())
   {
      struct epoll_event event{};
      event.events = fd.events;
      event.data.fd = fd.fd;

      cb_map[event.data.fd] = [this, handler]() {
         if (auto tmp = handler.lock())
            tmp->handle(*this);
      };

      if (epoll_ctl(epfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0)
         throw std::runtime_error("Failed to add epoll fd to list.\n");
   }
}
开发者ID:Themaister,项目名称:umusd,代码行数:19,代码来源:eventhandler.cpp

示例2: get

 /** Returns the singleton client or server lobby protocol. */
 template<class T> static std::shared_ptr<T> get()
 {
     if (std::shared_ptr<LobbyProtocol> lp = m_lobby.lock())
     {
         std::shared_ptr<T> new_type = std::dynamic_pointer_cast<T>(lp);
         if (new_type)
             return new_type;
     }
     return nullptr;
 }   // get
开发者ID:toymak3r,项目名称:Beyond-The-Mirror---Weird-Rancing-Game,代码行数:11,代码来源:lobby_protocol.hpp

示例3: handleWriteTimeout

void Connection::handleWriteTimeout(std::weak_ptr<Connection> weak, const boost::system::error_code& error)
{
	if(error == boost::asio::error::operation_aborted || weak.expired())
		return;

	if(std::shared_ptr<Connection> connection = weak.lock())
	{
		connection->onWriteTimeout();
	}
}
开发者ID:novasdream,项目名称:tyano-core,代码行数:10,代码来源:connection.cpp

示例4: runtime_error

std::shared_ptr<vector<string>> ConstStrBlobPtr::check(
    std::size_t pos, const string& msg) const {
    // test to see whether the vector pointed by the weak_ptr is still around
    auto ptr = dataptr.lock();
    if(!ptr)
        throw std::runtime_error("unbound ConstStrBlobPtr");
    if(pos >= ptr->size())
        throw std::out_of_range(msg);
    return ptr;
}
开发者ID:Horizon-Blue,项目名称:playground,代码行数:10,代码来源:13.26.cpp

示例5: 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:LegalizeAdulthood,项目名称:clang,代码行数:55,代码来源:FrontendActions.cpp

示例6:

//------------------------------------------//
// 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

示例7: runtime_error

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

示例8: av_qsv_log_callback

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

示例9: 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

示例10: f

/* Notes *
    * std::weak_ptr *
    expired - checks whether the referenced object was already deleted
    lock    - creates a shared_ptr that manages the referenced object 

    * std::unique_ptr * ,using this instead of auto_ptr considering:
    1 - operators supported(==, !=, < ...),so they can be used/stored in STL
        which uses/relies on a lot of these operations
    2 - array supported, can point to an array
*/
void f()
{
    if ( !wp.expired()) {
        auto spt = wp.lock();
        std::cout << *spt << "\n";
        std::cout << wp.use_count() << "\n";
    }
    else {
        std::cout << "wp is expired\n";
    }
}
开发者ID:valefor,项目名称:PL,代码行数:21,代码来源:SmartPointer.cpp

示例11: 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

示例12: log_gl_error

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

示例13:

 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

示例14:

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

示例15: 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


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