42 lines
896 B
C++
42 lines
896 B
C++
#ifndef UUID_H
|
||
#define UUID_H
|
||
|
||
#include <string>
|
||
|
||
/**
|
||
* UUID工具类
|
||
* 用于生成符合RFC 4122标准的UUID v4
|
||
*/
|
||
class UUID {
|
||
public:
|
||
/**
|
||
* 生成一个新的UUID字符串
|
||
* 格式: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||
* 例如: 550e8400-e29b-41d4-a716-446655440000
|
||
*/
|
||
static std::string generate();
|
||
|
||
/**
|
||
* 生成一个简短的UUID(无连字符)
|
||
* 格式: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||
*/
|
||
static std::string generateShort();
|
||
|
||
/**
|
||
* 检查UUID格式是否有效
|
||
*/
|
||
static bool isValid(const std::string& uuid);
|
||
|
||
/**
|
||
* 将标准UUID转换为简短的UUID(移除连字符)
|
||
*/
|
||
static std::string toShort(const std::string& uuid);
|
||
|
||
/**
|
||
* 将简短UUID转换为标准UUID(添加连字符)
|
||
*/
|
||
static std::string fromShort(const std::string& shortUuid);
|
||
};
|
||
|
||
#endif // UUID_H
|