change log updated
[public/netxms.git] / include / uuid.h
CommitLineData
f3d12ff6
VK
1/*
2 * Public include file for the UUID library
3 *
4 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU
8 * Library General Public License.
9 * %End-Header%
10 */
11
12#ifndef _UUID_H_
13#define _UUID_H_
14
95b6a1b6
VK
15#define UUID_LENGTH 16
16
3071f10a 17#if !HAVE_UUID_T
f3d12ff6 18#undef uuid_t
de4af576 19typedef unsigned char uuid_t[UUID_LENGTH];
3071f10a 20#endif
f3d12ff6
VK
21
22/* UUID Variant definitions */
95b6a1b6
VK
23#define UUID_VARIANT_NCS 0
24#define UUID_VARIANT_DCE 1
25#define UUID_VARIANT_MICROSOFT 2
26#define UUID_VARIANT_OTHER 3
f3d12ff6 27
999945fa
VK
28void LIBNETXMS_EXPORTABLE _uuid_clear(uuid_t uu);
29int LIBNETXMS_EXPORTABLE _uuid_compare(const uuid_t uu1, const uuid_t uu2);
30void LIBNETXMS_EXPORTABLE _uuid_generate(uuid_t out);
31bool LIBNETXMS_EXPORTABLE _uuid_is_null(const uuid_t uu);
32int LIBNETXMS_EXPORTABLE _uuid_parse(const TCHAR *in, uuid_t uu);
33TCHAR LIBNETXMS_EXPORTABLE *_uuid_to_string(const uuid_t uu, TCHAR *out);
0d402aa8
VK
34#ifdef UNICODE
35char LIBNETXMS_EXPORTABLE *_uuid_to_stringA(const uuid_t uu, char *out);
36#else
37#define _uuid_to_stringA _uuid_to_string
38#endif
f3d12ff6 39
de4af576
VK
40#ifdef __cplusplus
41
42/**
43 * Wrapper class for UUID
44 * Lower case used to avoid conflict with UUID struct defined in Windows headers
45 */
46class LIBNETXMS_EXPORTABLE uuid
47{
48private:
49 uuid_t m_value;
50
51public:
999945fa 52 uuid() { _uuid_clear(m_value); }
de4af576
VK
53 uuid(const uuid_t v) { memcpy(m_value, v, UUID_LENGTH); }
54
999945fa
VK
55 int compare(const uuid& u) const { return _uuid_compare(m_value, u.m_value); }
56 bool equals(const uuid& u) const { return _uuid_compare(m_value, u.m_value) == 0; }
de4af576 57 const uuid_t& getValue() const { return m_value; }
999945fa
VK
58 bool isNull() const { return _uuid_is_null(m_value); }
59 TCHAR *toString(TCHAR *buffer) const { return _uuid_to_string(m_value, buffer); }
60 String toString() const { TCHAR buffer[64]; return String(_uuid_to_string(m_value, buffer)); }
0d402aa8 61 char *toStringA(char *buffer) const { return _uuid_to_stringA(m_value, buffer); }
e9ef47dd 62 json_t *toJson() const { char buffer[64]; return json_string(toStringA(buffer)); }
de4af576
VK
63
64 /**
65 * Generate new UUID
66 */
67 static uuid generate()
68 {
69 uuid_t u;
999945fa 70 _uuid_generate(u);
de4af576
VK
71 return uuid(u);
72 }
73
74 /**
75 * Parse string into UUID. Returns NULL UUID on error.
76 */
77 static uuid parse(const TCHAR *s)
78 {
79 uuid_t u;
999945fa 80 if (_uuid_parse(s, u) != 0)
de4af576
VK
81 return NULL_UUID;
82 return uuid(u);
83 }
84
85 static const uuid NULL_UUID;
86};
87
88#endif
89
f3d12ff6 90#endif