//UUID是University Unique Identifier的缩写,它是一个128位的数字(16字节),不需要有一个中央认证机构就可以创建全国唯一的标示符。别名:GUID
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <assert.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
using namespace boost::uuids;
using namespace std;
int main()
{
uuid u;
std::fill_n(u.begin(), u.size(), 0xab);
cout<<u<<endl;
std::memset(u.data, 0, 16);
cout<<u<<endl;
//字符串生成器对象
string_generator sgen;
uuid u0 = sgen("01-23456789abcdef0123456789abcdef");
cout<<u0<<endl;
//构造名字生成器;名字生成器name_generator使用基于名字的SHA1摘要算法,它需要先指定一个基准UUID,然后使用字符串名字派生出基于这个UUID的一系列UUID,名字生成器的典型的应用场景是为一个组织内的所有成员创建UUID标识,只有基准UUID不变,那么相同的名字总会产生相同的UUID。
uuid www_xxx_com = string_generator()("{0123456789abcdef0123456789abcdef}");
name_generator ngen(www_xxx_com);//构造名字生成器
uuid u1 = ngen("mario");//为名字mario生成UUID
cout<<u1<<endl;
uuid u2 = ngen("link");//为名字link生成uuid
cout<<u2<<endl;
uuid u3 = name_generator(www_xxx_com)("kk"); //为名字kk生成uuid
cout<<u3<<endl;
random_generator rgen;//随机生成器
uuid u4 = rgen();//生成一个随机的UUID
cout<<"random:"<<u4<<endl;
system("pause");
return 0;
}
boost uuid
最新推荐文章于 2024-08-20 17:40:54 发布