function DBDropColumn moved to libnxdb from nxdbmgr
[public/netxms.git] / include / uuid.h
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
15 #define UUID_LENGTH 16
16
17 #if !HAVE_UUID_T
18 #undef uuid_t
19 typedef unsigned char uuid_t[UUID_LENGTH];
20 #endif
21
22 /* UUID Variant definitions */
23 #define UUID_VARIANT_NCS 0
24 #define UUID_VARIANT_DCE 1
25 #define UUID_VARIANT_MICROSOFT 2
26 #define UUID_VARIANT_OTHER 3
27
28 void LIBNETXMS_EXPORTABLE _uuid_clear(uuid_t uu);
29 int LIBNETXMS_EXPORTABLE _uuid_compare(const uuid_t uu1, const uuid_t uu2);
30 void LIBNETXMS_EXPORTABLE _uuid_generate(uuid_t out);
31 bool LIBNETXMS_EXPORTABLE _uuid_is_null(const uuid_t uu);
32 int LIBNETXMS_EXPORTABLE _uuid_parse(const TCHAR *in, uuid_t uu);
33 TCHAR LIBNETXMS_EXPORTABLE *_uuid_to_string(const uuid_t uu, TCHAR *out);
34 #ifdef UNICODE
35 char LIBNETXMS_EXPORTABLE *_uuid_to_stringA(const uuid_t uu, char *out);
36 #else
37 #define _uuid_to_stringA _uuid_to_string
38 #endif
39
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 */
46 class LIBNETXMS_EXPORTABLE uuid
47 {
48 private:
49 uuid_t m_value;
50
51 public:
52 uuid() { _uuid_clear(m_value); }
53 uuid(const uuid_t v) { memcpy(m_value, v, UUID_LENGTH); }
54
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; }
57 const uuid_t& getValue() const { return m_value; }
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)); }
61 char *toStringA(char *buffer) const { return _uuid_to_stringA(m_value, buffer); }
62 json_t *toJson() const { char buffer[64]; return json_string(toStringA(buffer)); }
63
64 /**
65 * Generate new UUID
66 */
67 static uuid generate()
68 {
69 uuid_t u;
70 _uuid_generate(u);
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;
80 if (_uuid_parse(s, u) != 0)
81 return NULL_UUID;
82 return uuid(u);
83 }
84
85 static const uuid NULL_UUID;
86 };
87
88 #endif
89
90 #endif