Skip to content
Snippets Groups Projects
Commit 14818fc3 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Make UUID work in Windows.

parent 945271d7
No related branches found
No related tags found
No related merge requests found
Pipeline #9534 passed
#ifndef _FTL_UUID_HPP_
#define _FTL_UUID_HPP_
#ifndef WIN32
#include <uuid/uuid.h>
#else
#include <Rpc.h>
#endif
#include <memory>
#include <string>
#include <functional>
......@@ -13,25 +18,35 @@ namespace ftl {
*/
class UUID {
public:
UUID() { uuid_generate(uuid_); };
UUID(int u) { memset(uuid_,u,16); };
UUID(const UUID &u) { memcpy(uuid_,u.uuid_,16); }
UUID() {
#ifdef WIN32
::UuidCreate(&uuid_);
#else
uuid_generate(uuid_);
#endif
};
UUID(int u) { memset(&uuid_,u,16); };
UUID(const UUID &u) { memcpy(&uuid_,&u.uuid_,16); }
bool operator==(const UUID &u) const { return memcmp(uuid_,u.uuid_,16) == 0; }
bool operator!=(const UUID &u) const { return memcmp(uuid_,u.uuid_,16) != 0; }
bool operator==(const UUID &u) const { return memcmp(&uuid_,&u.uuid_,16) == 0; }
bool operator!=(const UUID &u) const { return memcmp(&uuid_,&u.uuid_,16) != 0; }
/**
* Get a raw data string.
*/
std::string str() const { return std::string((char*)uuid_,16); };
const unsigned char *raw() const { return &uuid_[0]; }
std::string str() const { return std::string((char*)&uuid_,16); };
const unsigned char *raw() const { return (const unsigned char*)&uuid_; }
/**
* Get a pretty string.
*/
std::string to_string() const {
char b[37];
#ifdef WIN32
UuidToString(&uuid_, (RPC_CSTR*)b);
#else
uuid_unparse(uuid_, b);
#endif
return std::string(b);
}
......@@ -39,7 +54,11 @@ namespace ftl {
MSGPACK_DEFINE(uuid_);
private:
#ifdef WIN32
_GUID uuid_;
#else
unsigned char uuid_[16];
#endif
};
};
......
......@@ -5,7 +5,9 @@
#include <memory>
#include <iostream>
#ifndef WIN32
#include <sys/select.h>
#endif
using ftl::net::Dispatcher;
using ftl::net::Protocol;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment