forked from balloonwj/flamingo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I8c9a2717688959de2ec6855bb79b367ffc07f0f5
- Loading branch information
zhangyuanlong
committed
Apr 1, 2020
1 parent
941d3ab
commit aca7036
Showing
4 changed files
with
131 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,43 @@ | ||
/** | ||
* 全局唯一的UUID生成工具类,Windows上实际使用的是GUID, UUIDGenerator.cpp | ||
* zhangyl 20190710 | ||
*/ | ||
|
||
#include "UUIDGenerator.h" | ||
|
||
|
||
#ifdef WIN32 | ||
|
||
#include <combaseapi.h> | ||
|
||
std::string UUIDGenerator::generate() | ||
{ | ||
GUID guid; | ||
CoCreateGuid(&guid); | ||
char cBuffer[64] = { 0 }; | ||
sprintf_s(cBuffer, sizeof(cBuffer), | ||
"X-X-X-XX-XXXXXX", | ||
guid.Data1, guid.Data2, | ||
guid.Data3, guid.Data4[0], | ||
guid.Data4[1], guid.Data4[2], | ||
guid.Data4[3], guid.Data4[4], | ||
guid.Data4[5], guid.Data4[6], | ||
guid.Data4[7]); | ||
return std::string(cBuffer, 36); | ||
} | ||
|
||
#else | ||
|
||
#include <uuid.h> | ||
|
||
std::string UUIDGenerator::generate() | ||
{ | ||
uuid_t uuid; | ||
char str[40] = { 0 }; | ||
|
||
uuid_generate(uuid); | ||
uuid_unparse(uuid, str); | ||
return std::string(str, 36); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,26 @@ | ||
/** | ||
* 全局唯一的UUID生成工具类,Windows上实际使用的是GUID, UUIDGenerator.h | ||
* zhangyl 20190710 | ||
*/ | ||
|
||
#ifndef __UUID_GENERATOR_H__ | ||
#define __UUID_GENERATOR_H__ | ||
|
||
#include <string> | ||
|
||
class UUIDGenerator final | ||
{ | ||
private: | ||
UUIDGenerator() = delete; | ||
~UUIDGenerator() = delete; | ||
|
||
UUIDGenerator(const UUIDGenerator& rhs) = delete; | ||
UUIDGenerator& operator =(const UUIDGenerator& rhs) = delete; | ||
|
||
public: | ||
static std::string generate(); | ||
|
||
}; | ||
|
||
#endif //!__UUID_GENERATOR_H__ | ||
|
Oops, something went wrong.