Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
UUID.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef UID_INCLUDE_ONCE
33 #define UID_INCLUDE_ONCE
34 
35 #include <vlCore/checks.hpp>
36 #include <string>
37 #include <string.h>
38 
39 namespace vl
40 {
41  class Random;
42 
45  {
46  public:
48  UUID();
49 
51  void generateVersion4(const Random& random);
52 
54  bool fromString(const char* guid_str);
55 
59  void fillString(char* guid_str, bool zero_terminate = true) const;
60 
62  void toStdString(std::string& guid_str) const;
63 
65  std::string toStdString() const;
66 
67  bool operator==(const UUID& other) const
68  {
69  return memcmp(this, &other, sizeof(*this)) == 0;
70  }
71 
72  bool operator!=(const UUID& other) const
73  {
74  return memcmp(this, &other, sizeof(*this)) != 0;
75  }
76 
77  bool operator<(const UUID& other) const
78  {
79  return memcmp(this, &other, sizeof(*this)) < 0;
80  }
81 
82  public:
83  unsigned int mTimeLow;
84  unsigned short mTimeMid;
85  unsigned short mTimeHiAndVersion;
86  unsigned char mClockSeqHiAndReserved;
87  unsigned char mClockSeqLow;
88  unsigned char mNode[6];
89  };
90 // ----------------------------------------------------------------------------
91  VL_COMPILE_TIME_CHECK(sizeof(UUID) == 16)
92 // ----------------------------------------------------------------------------
93 }
94 
95 // ----------------------------------------------------------------------------
96 
97 #endif
unsigned short mTimeMid
Definition: UUID.hpp:84
unsigned short mTimeHiAndVersion
Definition: UUID.hpp:85
unsigned char mClockSeqLow
Definition: UUID.hpp:87
bool operator==(const UUID &other) const
Definition: UUID.hpp:67
VLCORE_EXPORT real random(real min, real max)
Returns a random number N between &#39;min&#39; and &#39;max&#39; (included) with 53 bits of randomness generated usi...
Definition: math_utils.cpp:44
Visualization Library main namespace.
unsigned char mClockSeqHiAndReserved
Definition: UUID.hpp:86
VL_COMPILE_TIME_CHECK(sizeof(i8) *8==8)
Simple implementation of a 16 bytes Universally Unique ID based on http://www.ietf.org/rfc/rfc4122.txt.
Definition: UUID.hpp:44
unsigned int mTimeLow
Definition: UUID.hpp:83
bool operator<(const UUID &other) const
Definition: UUID.hpp:77
Cryptographic random number generator.
Definition: Random.hpp:41
bool operator!=(const UUID &other) const
Definition: UUID.hpp:72