• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ weak_ptr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GetGlobalDisplay

static CDisplayPtr GetGlobalDisplay()
{
  static weak_ptr<CDisplay> display_global;

  CDisplayPtr display(display_global.lock());
  if(display)
  {
    if(display->lost())
    {
      CLog::Log(LOGERROR, "VAAPI - vaapi display is in lost state");
      display.reset();
    }    
    return display;
  }

  VADisplay disp;
  disp = vaGetDisplayGLX(g_Windowing.GetDisplay());

  int major_version, minor_version;
  VAStatus res = vaInitialize(disp, &major_version, &minor_version);

  CLog::Log(LOGDEBUG, "VAAPI - initialize version %d.%d", major_version, minor_version);

  if(res != VA_STATUS_SUCCESS)
  {
    CLog::Log(LOGERROR, "VAAPI - unable to initialize display %d - %s", res, vaErrorStr(res));
    return display;
  }

  const char* vendor = vaQueryVendorString(disp);
  CLog::Log(LOGDEBUG, "VAAPI - vendor: %s", vendor);

  bool deinterlace = true;
  int major, minor, micro;
  bool support_4k = true;
  if(sscanf(vendor,  "Intel i965 driver - %d.%d.%d", &major, &minor, &micro) == 3)
  {
    /* older version will crash and burn */
    if(compare_version(major, minor, micro, 1, 0, 17) < 0)
    {
      CLog::Log(LOGDEBUG, "VAAPI - deinterlace not support on this intel driver version");
      deinterlace = false;
    }
    // do the same check for 4K decoding: version < 1.2.0 (stable) and 1.0.21 (staging)
    // cannot decode 4K and will crash the GPU
    if((compare_version(major, minor, micro, 1, 2, 0) < 0) && (compare_version(major, minor, micro, 1, 0, 21) < 0))
    {
      support_4k = false;
    }
  }

  display = CDisplayPtr(new CDisplay(disp, deinterlace));
  display->support_4k(support_4k);
  display_global = display;
  return display;
}
开发者ID:Albinoman887,项目名称:xbmc,代码行数:56,代码来源:VAAPI.cpp


示例2: SquareSetCheck

//check if it's the right place to set square if so ,set it
void Tetris::SquareSetCheck(const TETRIS_TYPE t_type,weak_ptr<Square> t_wsquare)
{
	if(!t_wsquare.expired()){
		shared_ptr<Square> t_ssquare = t_wsquare.lock();
		if(t_ssquare->ConflictCheck(t_type) == true)
		{
			t_ssquare->SetSquare(t_type);
		}
	}else{
		LogWriter::me->WriteLog("square expired in SquareSetCheck");
	}
}
开发者ID:qqqqzift,项目名称:Tetris_Clover,代码行数:13,代码来源:tetris.cpp


示例3: alphabeticalG3DLast

static bool __cdecl alphabeticalG3DLast(weak_ptr<Texture> const& elem1, weak_ptr<Texture> const& elem2) {
    const shared_ptr<Texture>& elem1Locked = elem1.lock();
    const shared_ptr<Texture>& elem2Locked = elem2.lock();

    if (isNull(elem1Locked)) {
        return true;
    } else if (isNull(elem2Locked)) {
        return false;
    } else {
        return alphabeticalIgnoringCaseG3DLastLessThan(elem1Locked->name(), elem2Locked->name());
    }
}
开发者ID:jackpoz,项目名称:G3D-backup,代码行数:12,代码来源:TextureBrowserWindow.cpp


示例4: alphabeticalTextureLT

static bool __cdecl alphabeticalTextureLT(weak_ptr<Texture> const& elem1, weak_ptr<Texture> const& elem2) {
    const shared_ptr<Texture>& elem1Locked = elem1.lock();
    const shared_ptr<Texture>& elem2Locked = elem2.lock();

    if (isNull(elem1Locked)) {
        return true;
    } else if (isNull(elem2Locked)) {
        return false;
    } else {
        return elem1Locked->name() < elem2Locked->name();
    }
}
开发者ID:jackpoz,项目名称:G3D-backup,代码行数:12,代码来源:TextureBrowserWindow.cpp


示例5: updatePhysics

void VRPhysicsManager::updatePhysics( weak_ptr<VRThread>  wthread) {
    if (dynamicsWorld == 0) return;
    long long dt,t0,t1,t2,t3;
    auto thread = wthread.lock();
    if (thread == 0) return;
    t0 = thread->t_last;
    t1 = getTime();
    thread->t_last = t1;
    dt = t1-t0;

    {
        MLock lock(mtx);
        prepareObjects();
        for (auto f : updateFktsPre) (*f)(0);
        dynamicsWorld->stepSimulation(1e-6*dt, 30);
        for (auto f : updateFktsPost) (*f)(0);
    }

    t2 = getTime();
    dt = t2-t1;

    //sleep up to 500 fps
    if (dt < PHYSICS_THREAD_TIMESTEP_MS * 1000) this_thread::sleep_for(chrono::microseconds(PHYSICS_THREAD_TIMESTEP_MS * 1000 -dt));
    t3 = getTime();

    MLock lock(mtx);
    fps = 1e6/(t3-t1);

}
开发者ID:flair2005,项目名称:polyvr,代码行数:29,代码来源:VRPhysicsManager.cpp


示例6: MakeStrongPtr

shared_ptr<Type> MakeStrongPtr(weak_ptr<Type> pWeakPtr)
{
    if (!pWeakPtr.expired())
        return shared_ptr<Type>(pWeakPtr);
    else
        return shared_ptr<Type>();
}
开发者ID:Ostkaka,项目名称:ANT,代码行数:7,代码来源:templates.hpp


示例7: Init

void PropertyList::Init(weak_ptr<Leaf> leaf, wxListCtrl* ctrList)
{
    mLeaf.reset();
    mCtrList = 0;

    if (
        (leaf.expired()) ||
        (ctrList == 0)
        )
        {
            return;
        }

    mLeaf = leaf;
    mCtrList = ctrList;

    shared_ptr<Property> property = wxGetApp().GetProperty();
    if (property.get() != 0)
        {
            property->GetClassList(mLeaf.lock(), mClassList);
        }

    mCtrList->ClearAll();
    mCtrList->InsertColumn(0, _T("name"), wxLIST_FORMAT_LEFT, 120);
    mCtrList->InsertColumn(1, _T("value"), wxLIST_FORMAT_LEFT, 600);
}
开发者ID:BerlinUnited,项目名称:SimSpark-SPL,代码行数:26,代码来源:propertylist.cpp


示例8: DelTermSession

uint32_t BusinessPool::DelTermSession(weak_ptr<TermSession> ts)
{
    shared_ptr<TermSession> sp_ts(ts.lock());
    if (!sp_ts) {
        logger_.Warn("[删除终端会话]******对应的终端会话不存在******");
        return 0;
    }

    CASession *cs = sp_ts->ca_session_;

    if (cs == NULL) {
        logger_.Warn("[删除终端会话]******对应的CA会话不存在******");
        return 0;
    }

    cs->Remove(sp_ts->Id());
    logger_.Warn("[删除终端会话][CAId:" SFMT64U "][TSId:0x" SFMT64X "]", cs->Id(), sp_ts->Id());

    CASessionMgr *cs_mgr = pool_relation_ca_session_mgr_[getIdByTermSessionId(sp_ts->Id())];
    cs_mgr->DetachTermSessionInfo(sp_ts->Id());

    uint32_t ret = cs->termCnt();

    //if no terminal session in ca session,
    // remove ca session.
    if (cs->termCnt() == 0) {
        logger_.Warn("[删除终端会话][CAId:" SFMT64U "][TSId:0x" SFMT64X "],CA会话中无终端,删除CA会话", cs->Id(), sp_ts->Id());
        CASessionMgr *cs_mgr = pool_relation_ca_session_mgr_[getIdByTermSessionId(sp_ts->Id())];
        cs_mgr->Detach(cs->Id());
        cs_mgr->Destory(cs);    
    }

    return ret;
}
开发者ID:yangxingya,项目名称:gehua,代码行数:34,代码来源:businesspool.cpp


示例9: SquareCtrl

//read input key to move square
void Tetris::SquareCtrl(const TETRIS_TYPE t_type,weak_ptr<Square> t_wsquare)
{
	if(!t_wsquare.expired()){
		shared_ptr<Square> t_ssquare = t_wsquare.lock();
		KeyboardUpdate();
		//down button is pressed
		if(((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_UP))|| 
			((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_DOWN))||
			((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_RIGHT))||
			((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_LEFT))
			){
			t_ssquare->Move(kGODOWN,t_type);
		}
		//left button is pressed
		else if(((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_UP))|| 
			((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_DOWN))||
			((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_LEFT))||
			((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_RIGHT))
			){
			t_ssquare->Move(kGOLEFT,t_type);
		}
		//right button is pressed
		else if(((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_UP))|| 
			((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_DOWN))||
			((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_LEFT))||
			((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_RIGHT))
			){	
			t_ssquare->Move(kGORIGHT,t_type);
		}
		else if(((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_UP))|| 
			((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_DOWN))||
			((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_LEFT))||
			((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_RIGHT))
			){
			t_ssquare->Turn(t_type);
		}else if(KeyboardGet(KEY_INPUT_SPACE ) > 0){
			CtrlBoardChangine(t_type);
		}
		else if (KeyboardGet(KEY_INPUT_Z) == 1){
			SpeedUp();
		}
		else if (KeyboardGet(KEY_INPUT_X) == 1){
			SpeedDown();
		}

	}
}
开发者ID:qqqqzift,项目名称:Tetris_Clover,代码行数:48,代码来源:tetris.cpp


示例10: load

void load( Archive& archive, int mode, const char* name, weak_ptr<Type>& object )
{
    SWEET_ASSERT( mode == MODE_REFERENCE );
    SWEET_ASSERT( object.lock() == ptr<Type>() );

    ObjectGuard<Archive> guard( archive, name, 0, MODE_REFERENCE );
    archive.reference( archive.get_address(), reinterpret_cast<void**>(&object), &resolver<weak_ptr<Type> >::resolve );
}
开发者ID:cwbaker,项目名称:sweet_persist,代码行数:8,代码来源:ptr.hpp


示例11: Add

void TimeOutTimer::Add(weak_ptr<TermSession> ts)
{
	shared_ptr<TermSession> sp_ts(ts.lock());
	if (sp_ts) {
		MutexLock lock(mutex_);
		termsession_list_[sp_ts->Id()] = sp_ts;
	}
}
开发者ID:yangxingya,项目名称:gehua,代码行数:8,代码来源:timeouttimer.cpp


示例12: Reflect

void DirectusMaterial::Reflect(weak_ptr<GameObject> gameobject)
{
    m_inspectedMaterial = weak_ptr<Material>();

    // Catch the evil case
    if (gameobject.expired())
    {
        this->hide();
        return;
    }

    MeshRenderer* meshRenderer = gameobject.lock()->GetComponent<MeshRenderer>().lock().get();
    if (!meshRenderer)
    {
        this->hide();
        return;
    }



    m_inspectedMaterial = meshRenderer->GetMaterial();
    if (m_inspectedMaterial.expired())
    {
        this->hide();
        return;
    }

    // Do the actual reflection
    ReflectName();
    ReflectShader();
    ReflectAlbedo();
    ReflectRoughness();
    ReflectMetallic();
    ReflectNormal();
    ReflectHeight();
    ReflectOcclusion();
    ReflectEmission();
    ReflectMask();
    ReflectTiling();
    ReflectOffset();

    SetPropertiesVisible(m_inspectedMaterial.lock()->IsEditable() ? true : false);

    // Make this widget visible
    this->show();
}
开发者ID:PanosK92,项目名称:Directus3D,代码行数:46,代码来源:DirectusMaterial.cpp


示例13: useResource

void useResource(weak_ptr<Simple>& weakSimple)
{
	auto resource = weakSimple.lock();
	if (resource) {
		cout << "Resource still alive." << endl;
	} else {
		cout << "Resource has been freed!" << endl;
	}
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:9,代码来源:weak_ptr.cpp


示例14: decrease

 static void decrease(weak_ptr<Battalion>& battalion, Soldier *soldier)
 {
   shared_ptr<Battalion> sp = battalion.lock();
   if (sp)
   {
     cout << soldier->getName() << "已经壮烈牺牲了!" << endl;
     sp->reduce();
   }
 }
开发者ID:chenshuchao,项目名称:practice,代码行数:9,代码来源:weak_callback.cpp


示例15: operator

	/**
	 * Extracts the next timestamp from a Timer.
	 *
	 * Note: Caller must hold l_Mutex.
	 *
	 * @param wtimer Weak pointer to the timer.
	 * @returns The next timestamp
	 */
	double operator()(const weak_ptr<Timer>& wtimer)
	{
		Timer::Ptr timer = wtimer.lock();

		if (!timer)
			return 0;

		return timer->m_Next;
	}
开发者ID:CSRedRat,项目名称:icinga2,代码行数:17,代码来源:timer.cpp


示例16:

void
AccessStrategy::afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, weak_ptr<fib::Entry> fibWeak,
                                FaceId inFace, FaceId firstOutFace)
{
  shared_ptr<pit::Entry> pitEntry = pitWeak.lock();
  BOOST_ASSERT(pitEntry != nullptr);
  // pitEntry can't become nullptr, because RTO timer should be cancelled upon pitEntry destruction

  shared_ptr<fib::Entry> fibEntry = fibWeak.lock();
  if (fibEntry == nullptr) {
    NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace << " fib-gone");
    return;
  }

  NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace <<
                " multicast-except " << inFace << ',' << firstOutFace);
  this->multicast(pitEntry, fibEntry, {inFace, firstOutFace});
}
开发者ID:bombomstory,项目名称:NFD,代码行数:18,代码来源:access-strategy.cpp


示例17: threadMain

	/**
	 * The entry point of the thread that handles the client connection.
	 */
	void threadMain(const weak_ptr<Client> self) {
		vector<string> args;
		try {
			while (!this_thread::interruption_requested()) {
				try {
					if (!channel.read(args)) {
						// Client closed connection.
						break;
					}
				} catch (const SystemException &e) {
					P_TRACE(2, "Exception in ApplicationPoolServer client thread during "
						"reading of a message: " << e.what());
					break;
				}

				P_TRACE(4, "Client " << this << ": received message: " <<
					toString(args));
				
				if (args[0] == "get" && args.size() == 7) {
					processGet(args);
				} else if (args[0] == "close" && args.size() == 2) {
					processClose(args);
				} else if (args[0] == "clear" && args.size() == 1) {
					processClear(args);
				} else if (args[0] == "setMaxIdleTime" && args.size() == 2) {
					processSetMaxIdleTime(args);
				} else if (args[0] == "setMax" && args.size() == 2) {
					processSetMax(args);
				} else if (args[0] == "getActive" && args.size() == 1) {
					processGetActive(args);
				} else if (args[0] == "getCount" && args.size() == 1) {
					processGetCount(args);
				} else if (args[0] == "setMaxPerApp" && args.size() == 2) {
					processSetMaxPerApp(atoi(args[1]));
				} else if (args[0] == "getSpawnServerPid" && args.size() == 1) {
					processGetSpawnServerPid(args);
				} else {
					processUnknownMessage(args);
					break;
				}
				args.clear();
			}
		} catch (const boost::thread_interrupted &) {
			P_TRACE(2, "Client thread " << this << " interrupted.");
		} catch (const exception &e) {
			P_TRACE(2, "Uncaught exception in ApplicationPoolServer client thread:\n"
				<< "   message: " << toString(args) << "\n"
				<< "   exception: " << e.what());
		}
		
		mutex::scoped_lock l(server.lock);
		ClientPtr myself(self.lock());
		if (myself != NULL) {
			server.clients.erase(myself);
		}
	}
开发者ID:NeilW,项目名称:deb-passenger,代码行数:59,代码来源:ApplicationPoolServerExecutable.cpp


示例18: SetParent

void kinematicFrame::SetParent(weak_ptr<Leaf> parent)
{
    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();
    if (spark.get() == 0)
        {
            return;
        }

    if (parent.expired())
    {
        mParent = Leaf::CachedPath<zeitgeist::Leaf>();
    } else
    {
        std::string path = parent.lock()->GetFullPath();
        mParent.SetKey(Core::CacheKey(spark->GetCore()->GetRoot(), path));
    }

    UpdateCached();
}
开发者ID:GiorgosMethe,项目名称:SimSpark-SPL,代码行数:19,代码来源:kinematicframe.cpp


示例19: getroot

weak_ptr<TTrieNode> TStaticTemplateMatcher::suf_link_move(weak_ptr<TTrieNode> node) {
	if (node.lock()->suf_link_.lock())
		return node.lock()->suf_link_;
	weak_ptr<TTrieNode> prev = node.lock()->parentnode_;
	while (prev.lock() != getroot() && !suf_link_move(prev).lock()->isEdge(node.lock()->parentsymbol_))
		prev = suf_link_move(prev);
	node.lock()->suf_link_ = moveto(suf_link_move(prev),node.lock()->parentsymbol_);
	return node.lock()->suf_link_;
}
开发者ID:Beanin,项目名称:TextDictionaryMatcher-,代码行数:9,代码来源:StaticMatcher.cpp


示例20: getGlobalPose

 /**
  * Returns this 2D pose relative to the global (null) coordinate system.
  */
 self getGlobalPose() const {
   if(!Parent.expired()) {
     self result = Parent.lock()->getGlobalPose();
     result.Position += result.Rotation * Position;
     result.Rotation *= Rotation;
     return result;
   } else
     return *this;
 };
开发者ID:ahmadyan,项目名称:ReaK,代码行数:12,代码来源:pose_2D.hpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ webSocket类代码示例发布时间:2022-05-31
下一篇:
C++ wcstring_list_t类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap