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


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

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


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

示例1: is_root

 bool is_root() const noexcept
 {
     if (node.expired()) {
         return false;
     }
     return bool{std::dynamic_pointer_cast<node::inu>(node.lock())};
 }
开发者ID:rhysd,项目名称:Dachs,代码行数:7,代码来源:ast_fwd.hpp

示例2: exit

Listener::Listener(const std::weak_ptr<Manager>& manager){
    LOG_ENTER_FUNC("");

    std::string host;
    if(manager.expired()){
        //todo: notify main thread to eventHandler error.
        exit(1);
    }
    this->manager = manager.lock();
    log("3333333333333 this->manager.use_count:",this->manager.use_count());
    std::string tmp;
    int port;
    if(this->manager->getConfig("port", tmp)){
        port = boost::lexical_cast<int>(tmp);
    }
    int backlog;
    if(this->manager->getConfig("backlog", tmp)){
        backlog = boost::lexical_cast<int>(tmp);
    }
    if(this->manager->getConfig("host", tmp)){
        host = tmp;
    }
    this->serverSocket = std::make_shared<ServerSocket>(port, host, backlog);
    LOG_LEAVE_FUNC("");
}
开发者ID:ongonginging,项目名称:service,代码行数:25,代码来源:Listener.cpp

示例3: vRemoveListener

void EventDispatcher::vRemoveListener(const EventType & eType, const std::weak_ptr<void> & eListener)
{
	//If the eListener is dead or there is no eType in the listener list, simply return.
	if (eListener.expired() || pimpl->m_ListenerCallbackLists.find(eType) == pimpl->m_ListenerCallbackLists.end())
		return;

	//If it's dispatching, we should cache this operation and call it after the dispatch.
	if (pimpl->m_IsDispatchingQueue){
		pimpl->m_CachedOperations.emplace_back([this, eType, eListener](){vRemoveListener(eType, eListener); });
		return;
	}

	//Prepare for traversing the listener list.
	const auto strongListener = eListener.lock();
	auto & listenerListOfType = pimpl->m_ListenerCallbackLists[eType];

	//Traverse the listener list to see if there is an listener to be removed.
	//Don't use for(xx:yy) because there is at most one listener to remove from the list. Once we find it, we can simply remove it and return.
	for (auto listenerIter = listenerListOfType.begin(); listenerIter != listenerListOfType.end(); ++listenerIter){
		//If the current listener is dead, ignore it.
		if (listenerIter->first.expired())
			continue;

		//If the current listener "equals" eListener, remove it from the list.
		if (listenerIter->first.lock() == strongListener){
			listenerListOfType.erase(listenerIter);
			return;
		}
	}
}
开发者ID:bontey,项目名称:BabyWars,代码行数:30,代码来源:EventDispatcher.cpp

示例4:

void touchmind::model::node::NodeModel::RemoveLink(const std::weak_ptr<touchmind::model::link::LinkModel> &link)
{
    m_links.erase(std::remove_if(std::begin(m_links), std::end(m_links),
    [&](std::weak_ptr<touchmind::model::link::LinkModel> e) {
        return !link.expired() && !e.expired() && link.lock()->GetLinkId() == e.lock()->GetLinkId();
    }), std::end(m_links));
}
开发者ID:HTshandou,项目名称:TouchMind,代码行数:7,代码来源:NodeModel.cpp

示例5: create

 /** Creates either a client or server lobby protocol as a singleton. */
 template<typename singleton> static std::shared_ptr<singleton> create()
 {
     assert(m_lobby.expired());
     auto ret = std::make_shared<singleton>();
     m_lobby = ret;
     return std::dynamic_pointer_cast<singleton>(ret);
 }   // create
开发者ID:toymak3r,项目名称:Beyond-The-Mirror---Weird-Rancing-Game,代码行数:8,代码来源:lobby_protocol.hpp

示例6: getSquaredDistance

	// STATIC:
	float PhysicsEntityContainer::getSquaredDistance(std::weak_ptr<PhysicsEntity> e1, 
													 std::weak_ptr<PhysicsEntity> e2)
	{
		// Abort if null pointers
		if(e1.expired() || e2.expired()) return 0;

		// Set the difference between positions in each dimension
		float deltaX = e1._Get()->GetTransform()._Get()->GetPosition().x
			- e2._Get()->GetTransform()._Get()->GetPosition().x;
		float deltaY = e1._Get()->GetTransform()._Get()->GetPosition().y
			- e2._Get()->GetTransform()._Get()->GetPosition().y;
		float deltaZ = e1._Get()->GetTransform()._Get()->GetPosition().z
			- e2._Get()->GetTransform()._Get()->GetPosition().z;

		// Squared distance formula (doesn't use square root)
		return deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ;
	}
开发者ID:JISyed,项目名称:HedronSpace,代码行数:18,代码来源:PhysicsEntityContainer.cpp

示例7: Destroy

	void GameObject::Destroy(std::weak_ptr<GameObject> &obj)
	{
		if(!obj.expired())
		{
			obj.lock()->Delete();
			obj.reset();
		}
	}
开发者ID:JCGit,项目名称:Galaxy3D,代码行数:8,代码来源:GameObject.cpp

示例8: exit

Dispatcher::Dispatcher(const std::weak_ptr<Manager>& manager){
    LOG_ENTER_FUNC("constructor");
    if(manager.expired()){
        exit(1);
    }
    this->manager = manager.lock();
    log("manager.use_count()", this->manager.use_count());
    LOG_LEAVE_FUNC("constructor");
}
开发者ID:ongonginging,项目名称:service,代码行数:9,代码来源:Dispatcher.cpp

示例9: addBenchmark

void Benchmark::addBenchmark(std::weak_ptr<Benchmark> benchmark)
{
    std::lock_guard<std::recursive_mutex> lock(_benchmarkLock);
    if(benchmark.expired())
        return;

    benchmark.lock()->_parent = this;
    _benchmarks.push_back(benchmark);
}
开发者ID:viviwu,项目名称:MindTree,代码行数:9,代码来源:benchmark.cpp

示例10: SavePlayer2DB

void SavePlayer2DB(std::weak_ptr<CPlayer> player)
{
    if (!player.expired()&&player.lock()->GetPlayerID()!=0)
    {
        DBPlayer oldPlayerData;
        player.lock()->Player2DB(oldPlayerData);
        DBServer::GetInstance().SavePlayerData(oldPlayerData);
    }
}
开发者ID:zmxaini10250,项目名称:GameServer,代码行数:9,代码来源:Process.cpp

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

示例12: logic_error

void LibUSB::DeviceImpl::setParentDevice( std::weak_ptr<Device> pParentDevice )
{

	if (pParentDevice.expired())
	{
		throw std::logic_error("LibUSB::DeviceImpl::setParentDevice() - new parent device pointer is expired.");
	}

	m_ParentDevice = pParentDevice;
}
开发者ID:MartinBspheroid,项目名称:Libusbpp,代码行数:10,代码来源:deviceimpl.cpp

示例13: CreateUser

int CreateUser(const Data& data, std::weak_ptr<CPlayer> player)
{
    if(player.expired())
    {
        return -1;
    }
    std::shared_ptr<CPlayer> playerPtr = player.lock();
    if (playerPtr->GetSocket().expired())
    {
        return -1;
    }
    if (!playerPtr->GetSocket().lock()->GetPlayer().expired())
    {
        PBS2CCreateUserRes res;
        res.set_createuserresult(-1);
        player.lock()->GetSocket().lock()->SendBuff((int)TypeS2CCreateUserRes, res);
        return 0;
    }

    PBC2SCreateUserReq req;
    req.ParseFromArray(data.buffer, data.bufferLength);

    PBS2CCreateUserRes res;
    if (DBServer::GetInstance().CreateUser(player.lock()->GetSocket().lock()->GetLoginID(), req.playername().c_str(), res) != 0)
    {
        return -1;
    }
    DBPlayer playerData;
    if (DBServer::GetInstance().GetPlayerData(playerPtr->GetSocket().lock()->GetLoginID(), playerData) == 0)
    {
        std::weak_ptr<CTCPClientSocket> socket = player.lock()->GetSocket();
        std::weak_ptr<CPlayer> newPlayer = socket.lock()->GetPlayer();
        if (newPlayer.expired())
        {
            newPlayer = PlayerManager::GetInstance().CreatePlayer(playerData.playerid(), socket);
            if (newPlayer.expired())
            {
                return -1;
            }
            newPlayer.lock()->DB2Player(playerData);
            newPlayer.lock()->SetSocket(socket);
            socket.lock()->SetPlayer(newPlayer);
        }
        else
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }
    player.lock()->GetSocket().lock()->SendBuff((int)TypeS2CCreateUserRes, res);
    return 0;
}
开发者ID:zmxaini10250,项目名称:GameServer,代码行数:55,代码来源:Process.cpp

示例14: LoginCheck

int LoginCheck(const Data& data, std::weak_ptr<CPlayer> player)
{
    if(player.expired())
    {
        return -1;
    }
    std::shared_ptr<CPlayer> playerPtr = player.lock();
    if (playerPtr->GetSocket().expired())
    {
        return -1;
    }

    PBC2SLoginCheckReq req;
    req.ParseFromArray(data.buffer, data.bufferLength);

    PBS2CLoginCheckRes res;
    if (DBServer::GetInstance().LoginCheck(req.username().c_str(), req.password().c_str(), res) != 0)
    {
        return -1;
    }
    if (res.logincheckresult() > 0)
    {
        player.lock()->GetSocket().lock()->SetLoginID(res.logincheckresult());
        DBPlayer playerData;
        if (DBServer::GetInstance().GetPlayerData(res.logincheckresult(), playerData) == 0)
        {
            std::weak_ptr<CTCPClientSocket> socket = player.lock()->GetSocket();
            std::weak_ptr<CPlayer> newPlayer = socket.lock()->GetPlayer();
            if (!newPlayer.expired())
            {
                DBPlayer oldPlayerData;
                player.lock()->Player2DB(oldPlayerData);
                DBServer::GetInstance().SavePlayerData(oldPlayerData);
                socket.lock()->SetPlayer(std::weak_ptr<CPlayer>());
                PlayerManager::GetInstance().RemovePlayer(player.lock()->GetPlayerID());
            }
            newPlayer = PlayerManager::GetInstance().CreatePlayer(playerData.playerid(), socket);
            if (newPlayer.expired())
            {
                return -1;
            }
            newPlayer.lock()->DB2Player(playerData);
            newPlayer.lock()->SetSocket(socket);
            socket.lock()->SetPlayer(newPlayer);
        }

    }
    else
    {
        player.lock()->GetSocket().lock()->SetPlayer(std::weak_ptr<CPlayer>());
    }
    player.lock()->GetSocket().lock()->SendBuff((int)TypeS2CLoginCheckRes, res);

    return 0;
}
开发者ID:zmxaini10250,项目名称:GameServer,代码行数:55,代码来源:Process.cpp

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


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