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


C++ weak_ptr类代码示例

本文整理汇总了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, &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: 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

示例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);
      };
    };
开发者ID:ahmadyan,项目名称:ReaK,代码行数:18,代码来源:pose_2D.hpp


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