用 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);

用 boost::multi_index 管理玩家的更多相关文章

  1. boost::multi_index 提供一种千人在线即时排行榜的设计思路

    原文地址: http://www.limerence2017.com/2019/06/23/cpp01/ 做游戏或金融后台开发,经常会遇到设计开发排行榜的需求.比如玩家的充值排行,战力排行等等.而这种 ...

  2. boost multi_index

    /** boost 多索引容器的一般使用 这里使用google 的gmock 库来验证对boost 多索引模板的使用,并验证. 这里是手敲的,可能会有一些字符敲错的情况,编译错误的放,修改一下,同时链 ...

  3. 使用boost::multi_index高速构建排行榜

    使用boost::multi_index高速构建排行榜 前几天在boost的maillist上看到boost::multi_index将要支持ranked_index(邮件内容见附件2),这实乃我等苦 ...

  4. boost::multi_index 多索引容器

    #include "stdafx.h" #include <string> #include <boost/multi_index_container.hpp&g ...

  5. boost multi_index 插入返回值

    boost multi_index 对象插入函数emplace() 的返回值,是一个std::pair<iterator, bool>该pair 的first 是一个插入成功的位置,第二个 ...

  6. boost multi_index简单了解

    #include <string> #include <iostream> #include <boost/multi_index_container.hpp> # ...

  7. boost:进程管理

    概述 Boost.Process提供了一个灵活的C++ 进程管理框架.它允许C++ developer可以像Java和.Net程序developer那样管理进程.它还提供了管理当前执行进程上下文.创建 ...

  8. BOOST内存管理-intrusive_ptr

    参考链接https://blog.csdn.net/harbinzju/article/details/6754646 intrusive_ptr 是shared_ptr的插入式版本.与shared_ ...

  9. boost asio 异步实现tcp通讯

    ---恢复内容开始--- asioboost   目录(?)[-] 一前言 二实现思路 通讯包数据结构 连接对象 连接管理器 服务器端的实现 对象串行化   一.前言 boost asio可算是一个简 ...

随机推荐

  1. ubuntu安装fat32和exfat文件系统支持

    vftp(fat32) apt install -y dosfstools exfat apt install -y exfat-fuse exfat-utils

  2. Centos 7安装MYSQL

    1.下载RPM源 直接使用yum命令下载mysql来进行安装是不能成功的,安装过程会有问题,这里需要使用rpm命令来先进下载.下载路径为: http://dev.mysql.com/get/mysql ...

  3. Hadoop — MapReduce原理解析

    1. 概述 Mapreduce是一个分布式运算程序的编程框架,是用户开发"基于hadoop的数据分析应用"的核心框架: Mapreduce核心功能是将用户编写的业务逻辑代码和自带默 ...

  4. 纯CSS菜单样式,及其Shadow DOM,Json接口 实现

    先声明,要看懂这篇博客要求你具备少量基础CSS知识, 当然如果你只是要用的话就随便了,不用了解任何知识 完整项目github链接:https://github.com/git-Code-Shelf/M ...

  5. MySQL数据库优化的八种方式

    引言: 关于数据库优化,网上有不少资料和方法,但是不少质量参差不齐,有些总结的不够到位,内容冗杂 偶尔发现了这篇文章,总结得很经典,文章流量也很大,所以拿到自己的总结文集中,积累优质文章,提升个人能力 ...

  6. java异常拾遗

    概述 当方法内部发生一项错误时,该方法会创建一个对象传递给运行时系统(runtime system),这个对象被称为异常对象,包含错误的类型.发生位置,程序状态等一系列信息. 当一个方法抛出异常时,运 ...

  7. Android Studio突然不显示logcat日志

    参考文章:http://blog.csdn.net/victor_e_n_01185/article/details/52818809 有时候,AS出现没有log的情况.一般您换了模拟器,或者使用真机 ...

  8. rbac 概念

    1 权限管理 1.1 什么是权限管理 分享牛原创,分享牛系列.基本上涉及到用户参与的系统都要进行权限管理,权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户 ...

  9. 27 自定义View 和案例

    有时安卓提供的View不满足我们的需求时可以创建一个类继承View或其子类重写方法 如 package com.qf.sxy.day28_customview.view; import android ...

  10. 详解EBS接口开发之应收INVOICE导入

    (一)应收INVOICE常用标准表简介 1.1   常用标准表 如下表中列出了与应收INVOICE导入相关的表和说明: 表名 说明 其他信息 RA_BATCH_SOURCES_ALL AR事务处理来源 ...