本文整理汇总了C++中weak_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ weak_ptr类的具体用法?C++ weak_ptr怎么用?C++ weak_ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了weak_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, µ) == 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;
}
示例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");
}
}
示例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());
}
}
示例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();
}
}
示例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);
}
示例6: MakeStrongPtr
shared_ptr<Type> MakeStrongPtr(weak_ptr<Type> pWeakPtr)
{
if (!pWeakPtr.expired())
return shared_ptr<Type>(pWeakPtr);
else
return shared_ptr<Type>();
}
示例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);
}
示例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;
}
示例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();
}
}
}
示例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 );
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例14: 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;
};
示例15: isParentPose
/**
* Returns true if P is part of the parent chain from this pose.
*/
bool isParentPose(const shared_ptr< const self >& P) const {
if(Parent.expired()) {
if(P)
return true;
else
return false;
} else {
if(P)
return false;
else if(P == Parent.lock())
return true;
else
return Parent.lock()->isParentPose(P);
};
};