My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Core.h"

NAMESPACE_UPP

//#BLITZ_APPROVE

INITBLOCK {
Value::Register<Uuid>("Uuid");
}

void Uuid::Serialize(Stream& s) {
int version = 0;
s / version % a % b %c % d;
}

void Uuid::Jsonize(JsonIO& jio)
{
String h;
if(jio.IsStoring()) {
h = Format(*this);
jio.Set(h);
}
else
*this = ScanUuid((String)jio.Get());
}

Uuid Uuid::Create() {
Uuid ud;
ud.a = Random();
ud.b = Random();
ud.c = Random();
ud.d = Random();
return ud;
}

String Format(const Uuid& id) {
return Sprintf("%08X%08X%08X%08X", id.a, id.b, id.c, id.d);
}

String FormatWithDashes(const Uuid& id) {
return Sprintf("%08X-%04X-%04X-%04X-%04X%08X", id.a, (id.b & 0xFFFF0000) >> 16, id.b & 0x0000FFFF,
(id.c & 0xFFFF0000) >> 16, id.c & 0x0000FFFF, id.d);
}


dword scanX(const char *s)
{
dword r = 0;
for(int i = 0; i < 8; i++) {
r = (r << 4) | (*s >= '0' && *s <= '9' ? *s - '0' :
*s >= 'A' && *s <= 'F' ? 10 + *s - 'A' :
*s >= 'a' && *s <= 'f' ? 10 + *s - 'a' : 0);
s++;
}
return r;
}

Uuid ScanUuid(const char *s)
{
Uuid id;
String xu;
while(*s) {
if(IsXDigit(*s))
xu.Cat(*s);
s++;
}
if(xu.GetCount() < 32)
return Null;
id.a = scanX(~xu);
id.b = scanX(~xu + 8);
id.c = scanX(~xu + 16);
id.d = scanX(~xu + 24);
return id;
}

void Uuid::Xmlize(XmlIO& xio)
{
String h;
if(xio.IsStoring())
h = Format(*this);
xio.Attr("value", h);
if(xio.IsLoading())
*this = ScanUuid(h);
}

String Uuid::ToString() const
{
return Format(*this);
}

String Uuid::ToStringWithDashes() const
{
return FormatWithDashes(*this);
}

String Dump(const Uuid& id) {
return "UUID: " + Format(id);
}

struct UuidValueGenClass : ValueGen
{
virtual Value Get() {
return Format(Uuid::Create());
}
};

ValueGen& UuidValueGen()
{
return Single<UuidValueGenClass>();
}

END_UPP_NAMESPACE

Change log

r4950 by cxl on May 14, 2012   Diff
Draw: Font, Drawing, Painting, Image now
support Xmlize and Jsonize
Go to: 
Project members, sign in to write a code review

Older revisions

r4654 by cxl on Mar 3, 2012   Diff
Core: Jsonize finished
r4651 by cxl on Mar 3, 2012   Diff
Core: Value support for Xmlize,
Jasonize
r4495 by cxl on Jan 30, 2012   Diff
Core: new Value reintegrated for
conditional compilation (SVO_VALUE
flag)
All revisions of this file

File info

Size: 1866 bytes, 112 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting