本文整理汇总了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_;
}
}
示例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));
}
}
示例3:
//------------------------------------------//
// Texture2DAssetLoader::StartupLoader
//------------------------------------------//
bool Texture2DAssetLoader::StartupLoader(std::weak_ptr<class Renderer> renderer)
{
if (renderer.lock() == nullptr)
{
//Fail something
return false;
}
mWeakRenderer = renderer;
return true;
}
示例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();
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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]);
}
示例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);
}
示例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;
}
示例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();
}
示例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));
}
};
}
示例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);
}
示例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";
}
示例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;
}