GM6000 Digital Heater Controller Branch: main
SDX-1330
Guid.h
Go to the documentation of this file.
1#ifndef Cpl_Type_Guid_h_
2#define Cpl_Type_Guid_h_
3/*-----------------------------------------------------------------------------
4* This file is part of the Colony.Core Project. The Colony.Core Project is an
5* open source project with a BSD type of licensing agreement. See the license
6* agreement (license.txt) in the top/ directory or on the Internet at
7* http://integerfox.com/colony.core/license.txt
8*
9* Copyright (c) 2014-2022 John T. Taylor
10*
11* Redistributions of the source code must retain the above copyright notice.
12*----------------------------------------------------------------------------*/
13/** @file */
14
15#include "Cpl/Text/String.h"
16#include "Cpl/Text/FString.h"
17#include <stdint.h>
18
19
20/// The number of binary bytes in a GUID
21#define CPL_TYPE_GUID_BINARY_LENGTH 16
22
23/** Maximum string length (not including the null terminator) for a formatted
24 GUI string WITHOUT leading/trailing brackets
25 */
26#define CPL_TYPE_GUID_MAX_FORMATTED_LENGTH 36
27
28 /** Maximum string length (not including the null terminator) for a formatted
29 GUI string WITH leading/trailing brackets
30 */
31#define CPL_TYPE_GUID_MAX_FORMATTED_WITH_BRACES_LENGTH 38
32
33
34///
35namespace Cpl {
36///
37namespace Type {
38
39/// Convenience typedef for a GUID String
41
42
43/** This structure defines a type for a 16 Byte GUID/UUID.
44 See https://en.wikipedia.org/wiki/Universally_unique_identifier for additional
45 details.
46 */
47
48struct Guid_T
49{
50public:
51 /// Value as single memory block, and/or internal structure
52 union
53 {
54 uint8_t block[CPL_TYPE_GUID_BINARY_LENGTH]; //!< GUID value as single block of memory
55 struct
56 {
57 uint8_t time_low[4]; //!< Low 32 bits of the time
58 uint8_t time_mid[2]; //!< Middle 16 bits of the time
59 uint8_t time_hi_version[2]; //!< Version (4bits) and high 12 bits of time
60 uint8_t clock_seq_hi_lo[2]; //!< Variant (1-3 bits), Clock sequence (13-15 bits)
61 uint8_t node[6]; //!< Node ID (48 bits)
62 };
63 };
64
65
66public:
67 /// Comparison
68 bool operator ==( const Guid_T other ) const;
69
70public:
71 /** This method converts the in binary format to a text string in
72 8-4-4-4-12 format.
73
74 The minimum memory required for the formatted output string is 36 bytes
75 or 38 bytes when including braces.
76
77 Returns true if conversion was successful; else false is returned (e.g.
78 insufficient memory in formattedOutput).
79 */
80 bool toString( Cpl::Text::String& formattedOutput, bool withBraces=false );
81
82 /** This method sets the GUID's value from a text representation of GUID in
83 8-4-4-4-12 format.
84
85 If the 1st character of 'stringGuid' is a leading '{', there must be a
86 trailing '}'
87
88 The 'stringGuid' should never contain any whitespace.
89
90 Returns true if conversion was successful; else false is returned (e.g.
91 incorrect/invalid formatting).
92 */
93 bool fromString( const char* stringGuid );
94
95};
96
97}; // end namespaces
98};
99#endif // end header latch
100
#define CPL_TYPE_GUID_BINARY_LENGTH
The number of binary bytes in a GUID.
Definition Guid.h:21
This template class represents a NULL terminated string of a specific length.
Definition FString.h:38
This abstract class defines the operations that can be before on a NULL terminated string.
Definition String.h:40
Cpl::Text::FString< CPL_TYPE_GUID_MAX_FORMATTED_LENGTH > GuidString_T
Convenience typedef for a GUID String.
Definition Guid.h:40
The 'Cpl' namespace is the root name space for the Colony.
Definition Api16.h:20
This structure defines a type for a 16 Byte GUID/UUID.
Definition Guid.h:49
bool toString(Cpl::Text::String &formattedOutput, bool withBraces=false)
This method converts the in binary format to a text string in 8-4-4-4-12 format.
bool fromString(const char *stringGuid)
This method sets the GUID's value from a text representation of GUID in 8-4-4-4-12 format.
bool operator==(const Guid_T other) const
Comparison.