Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
uuid.h
Go to the documentation of this file.00001 00004 /* 00005 * Copyright © 2001, 2002 Sofus Mortensen 00006 * 00007 * This material is provided "as is", with absolutely no warranty 00008 * expressed or implied. Any use is at your own risk. Permission to 00009 * use or copy this software for any purpose is hereby granted without 00010 * fee, provided the above notices are retained on all copies. 00011 * Permission to modify the code and to distribute modified code is 00012 * granted, provided the above notices are retained, and a notice that 00013 * the code was modified is included with the above copyright notice. 00014 * 00015 * This header is part of comet. 00016 * http://www.lambdasoft.dk/comet 00017 */ 00018 00019 #ifndef COMET_UUID_H 00020 #define COMET_UUID_H 00021 00022 #include <comet/config.h> 00023 #include <comet/uuid_fwd.h> 00024 #include <comet/bstr.h> 00025 00026 #pragma comment( lib, "Rpcrt4" ) 00027 00028 namespace comet { 00029 00030 template<typename C> 00031 void uuid_t::copy_to_str(C s[36]) const throw() 00032 { 00033 const unsigned char *p = reinterpret_cast<const unsigned char*>(this); 00034 00035 for (int i=0; i<20; ++i) 00036 { 00037 int j = uuid_table()[i]; 00038 if (j >= 0) 00039 { 00040 const unsigned char byt = p[j]; 00041 *s = hex_table()[byt >> 4]; 00042 ++s; 00043 *s = hex_table()[byt & 0xf]; 00044 } 00045 else *s = L'-'; 00046 ++s; 00047 } 00048 } 00049 00050 template<typename C> 00051 bool uuid_t::init_from_str(const C s[], size_t len) throw() 00052 { 00053 unsigned char *p = reinterpret_cast<unsigned char*>(this); 00054 00055 bool has_brace; 00056 switch (len) 00057 { 00058 default: return false; 00059 case 36: has_brace = false; break; 00060 case 38: 00061 if (*s != C('{')) 00062 return false; 00063 has_brace = true; 00064 ++s; 00065 break; 00066 } 00067 00068 int i; 00069 for (i=0; i<20; ++i) 00070 { 00071 int j = uuid_table()[i]; 00072 if (j >= 0) 00073 { 00074 int a = parse_nibble(*s); 00075 ++s; 00076 int b = parse_nibble(*s); 00077 p[j] = unsigned char(a << 4 | b); 00078 } 00079 else if (*s != C('-')) 00080 return false; 00081 ++s; 00082 } 00083 return (! has_brace) || (*s == C('}')); 00084 } 00085 00086 } 00087 00088 #endif