Logo
~Sockets~
~Examples~
~Contact~


Uid Class Reference
[Utilities]

Generate 128-bit globally unique identifier. More...

#include <Uid.h>

List of all members.


Public Member Functions

 Uid ()
 Uid (const std::string &)
 Uid (const unsigned char *)
 ~Uid ()
std::string GetUid ()
const unsigned char * GetBuf ()

Private Member Functions

 Uid (const Uid &)
Uidoperator= (const Uid &)

Private Attributes

unsigned char m_bufuid [16]

Detailed Description

Generate 128-bit globally unique identifier.

Definition at line 44 of file Uid.h.


Constructor & Destructor Documentation

Uid::Uid (  ) 

Definition at line 60 of file Uid.cpp.

References m_bufuid.

00061 {
00062 #if defined(_WIN32) || defined(__CYGWIN__)
00063         GUID randomGuid;
00064         // create random GUID
00065         randomGuid = GUID_NULL;
00066         ::CoCreateGuid(&randomGuid);
00067         if (randomGuid == GUID_NULL)
00068         {
00069                 fprintf(stderr,"Couldn't create a random GUID\n");
00070                 return;
00071         }
00072         memcpy(m_bufuid, &randomGuid, 16);
00073 #elif defined __FreeBSD__
00074         uuid_t uid; // uuid_t is a struct
00075         uuid_create(&uid, NULL);
00076         memcpy(m_bufuid, &uid, 16);
00077 #else
00078         uuid_t uid; // uuid_t is defined as unsigned char[16]
00079         uuid_generate(uid);
00080         memcpy(m_bufuid, uid, 16);
00081 #endif
00082 }

Uid::Uid ( const std::string &   ) 

Definition at line 85 of file Uid.cpp.

References m_bufuid.

00086 {
00087         unsigned uid[16];
00088         sscanf(uidstr.c_str(),"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
00089                 &uid[0],&uid[1],&uid[2],&uid[3],
00090                 &uid[4],&uid[5],&uid[6],&uid[7],
00091                 &uid[8],&uid[9],&uid[10],&uid[11],
00092                 &uid[12],&uid[13],&uid[14],&uid[15]);
00093         for (int i = 0; i < 16; i++)
00094                 m_bufuid[i] = (unsigned char)uid[i];
00095 }

Uid::Uid ( const unsigned char *   ) 

Definition at line 98 of file Uid.cpp.

References m_bufuid.

00099 {
00100         memcpy(m_bufuid, buf, 16);
00101 }

Uid::~Uid (  ) 

Definition at line 104 of file Uid.cpp.

00105 {
00106 }

Uid::Uid ( const Uid  )  [inline, private]

Definition at line 56 of file Uid.h.

00056 {}


Member Function Documentation

std::string Uid::GetUid (  ) 

Definition at line 109 of file Uid.cpp.

References m_bufuid.

Referenced by MinderHandler::GenerateID().

00110 {
00111         std::string tmp;
00112         char slask[100]; // Uid::GetUid temporary
00113 
00114         sprintf(slask,"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
00115                 m_bufuid[0],m_bufuid[1],m_bufuid[2],m_bufuid[3],
00116                 m_bufuid[4],m_bufuid[5],m_bufuid[6],m_bufuid[7],
00117                 m_bufuid[8],m_bufuid[9],m_bufuid[10],m_bufuid[11],
00118                 m_bufuid[12],m_bufuid[13],m_bufuid[14],m_bufuid[15]);
00119         tmp = slask;
00120         return tmp;
00121 }

const unsigned char * Uid::GetBuf (  ) 

Definition at line 124 of file Uid.cpp.

References m_bufuid.

Referenced by MinionSocket::OnLine(), MinionSocket::OnVerifiedLine(), MinionSocket::SendHello(), and MinderHandler::SendMessage().

00125 { 
00126         return m_bufuid; 
00127 }

Uid& Uid::operator= ( const Uid  )  [inline, private]

Definition at line 57 of file Uid.h.

00057 { return *this; }


Member Data Documentation

unsigned char Uid::m_bufuid[16] [private]

Definition at line 58 of file Uid.h.

Referenced by GetBuf(), GetUid(), and Uid().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4