Files
wnmj-normal/Servers/服务器组件/网站网关服务器/IDAllocator.h
2026-03-03 13:56:44 +08:00

33 lines
517 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#ifndef __IDALLOCATOR_H__
#define __IDALLOCATOR_H__
#include <map>
using namespace std;
// ID分配器ID是从0开始分配的。
#define INVALID_ID 0xFFFF
class IDAllocator
{
public:
IDAllocator(unsigned short max);
virtual ~IDAllocator(void);
// 重设最大ID,谨慎使用
void resetMaxID(unsigned short max);
// 分配一个ID
unsigned short allocateID();
// 回收一个ID
bool recycleID(unsigned short id);
private:
unsigned short m_max; // 最大数值
map<unsigned short,unsigned short> m_idMap;
};
#endif