首页 > 其他分享 >用 boost::multi_index 管理玩家

用 boost::multi_index 管理玩家

时间:2023-06-15 23:08:10浏览次数:36  
标签:index multi const hashed typedef unique boost


用 boost::multi_index 管理玩家

(金庆的专栏)

网游服务器上的玩家集合需要多种索引:如用ID查找,角色名查找, 用登录时分配的会话ID查找。
用boost::multi_index进行玩家的管理,可在该容器上建立多种索引。

class Player
{
public:
    const PlayerId & GetId() const;
    const std::string & GetName() const;
    const SessionId & GetSessionId() const;
    ...
};

typedef boost::shared_ptr<Player> PlayerPtr;

struct tagName {};

typedef boost::multi_index::multi_index_container
<
    PlayerPtr,
    index_by
    <
        hashed_unique
        <
            tag<PlayerId>,
            member<Player, PlayerId, &Player::GetId>
        >,  // hashed_unique
        
        hashed_unique
        <
            tag<tagName>,
            member<Player, std::string, &Player::GetName>
        >,  // hashed_unique
        
        hashed_unique
        <
            tag<SessionId>,
            member<Player, SessionId, &Player::GetSessionId>
        >  // hashed_unique
    >  // index_by
> PlayerSet;

typedef PlayerSet::index<PlayerId>::type PlayerSetById;
typedef PlayerSet::index<tagName>::type PlayerSetByName;
typedef PlayerSet::index<SessionId>::type PlayerSetBySessionId;




使用如:

PlayerSet setPlayers;
PlayerSetById & rSet = setPlayers.get<PlayerId>();
PlayerSetById::const_iterator itr = rSet.find(id);






标签:index,multi,const,hashed,typedef,unique,boost
From: https://blog.51cto.com/u_16162321/6495464

相关文章

  • boost::this_thread::sleep_for()死锁
    boost::this_thread::sleep_for()会死锁(金庆的专栏)发现睡眠1ms很容易死锁。boost::this_thread::sleep_for(boost::chrono::milliseconds(1)).Boost1.54.0以下代码很可能重现死锁:#include"stdafx.h"#include<iostream>#include<boost/thread.......
  • MinGw编译Boost
    MinGw编译Boost(金庆的专栏)在MinGwShell中运行bootstrap.sh失败Jinq@jinqing-pc/d/src/boost_1_52_0$bootstrap.shtoolset=gccBuildingBoost.Buildenginewithtoolsetgcc...FailedtobuildBoost.BuildbuildengineConsult'bootstrap.log......
  • 用boost::bind构造boost::coroutine
    classTestCoro{...typedefboost::coroutines::coroutione<void()>Coro; voidCoroFun(Coro::caller_type&ca);Corom_coro;};TestCoro::TestCoro(){m_coro=Coro(boost::bind(&TestCoro::CoroFun,this,_1));}可......
  • DBeaver Ultimate Edtion 23.1 Multilingual (macOS, Linux, Windows) - 通用数据库工
    DBeaverUltimateEdtion23.1Multilingual(macOS,Linux,Windows)-通用数据库工具,现已集成ChatGPTOnetoolforalldatasources请访问原文链接:https://sysin.org/blog/dbeaver-23/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org通用数据库工具DBeaver是......
  • XGBoost超参数调优指南
    本文将详细解释XGBoost中十个最常用超参数的介绍,功能和值范围,及如何使用Optuna进行超参数调优。对于XGBoost来说,默认的超参数是可以正常运行的,但是如果你想获得最佳的效果,那么就需要自行调整一些超参数来匹配你的数据,以下参数对于XGBoost非常重要:etanum_boost_roundmax_dep......
  • 利用Theano理解深度学习——Multilayer Perceptron
    一、多层感知机MLP1、MLP概述对于含有单个隐含层的多层感知机(single-hidden-layerMulti-LayerPerceptron,MLP),可以将其看成是一个特殊的Logistic回归分类器,这个特殊的Logistic回归分类器首先通过一个非线性变换(non-lineartransformation)对样本的输入进行非线性变换,然后将变......
  • 浅谈MultipartFile中transferTo方法的坑 服务器上面使用相对路径 file.transferTo(fil
    浅谈MultipartFile中transferTo方法的坑服务器上面使用相对路径file.transferTo(filePath.getAbsoluteFile())而不是file.transferTo(filePath.getPath())绝对路径,实际生产配置服务器里面的一个文件夹。比如配置服务器文件夹前缀为/downfile/excelfile原文链接:https://ww......
  • Multi-gate Mixture-of-Experts(MMoE)
    1.概述在工业界经常会面对多个学习目标的场景,如在推荐系统中,除了要给用户推荐刚兴趣的物品之外,一些细化的指标,包括点击率,转化率,浏览时长等等,都会作为评判推荐系统效果好坏的重要指标,不同的是在不同的场景下对不同指标的要求不一样而已。在面对这种多任务的场景,最简单最直接的方法......
  • boost库之字符串处理
    一、Boost.StringAlgorithmsBoost字符算法库Boost.StringAlgorithms提供了很多字符串操作函数,字符串的类型可以是std::string,std::wstring,或者是任何模板类std::basic_string的实例。这些函数分类别在不同的头文件定义,例如大小写转函数定义在文件boost/algorithm/string/case_c......
  • 2021百度之星- 复赛 Add or Multiply 1 第二类斯特林数计数
    AddorMultiply1本质上这个题目中乘法和加法没有任何区别因为加法乘法均满足交换律不妨考虑乘法最后分成了k块每块内部没有顺序但是块之间有顺序有顺序共有m个乘法操作这样的方案数是\(s(m,k)k!\)这个时候要求k-1个空隙必须有加法但是开头和结尾可以有也可以没有这个......