]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/uuid/uuid.html
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / uuid / uuid.html
CommitLineData
7c673cae
FG
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
4<title>Uuid Library</title>
5<style type="text/css">
6 pre { margin: 1em; padding: 1em; border: 1px solid #ddd; }
7</style>
8</head>
9<body>
10<h1><img src="../../boost.png" alt="Boost" WIDTH="277" HEIGHT="86">Uuid</h1>
11
12<h2><a name="Contents">Contents</a></h2>
13
14<ol>
15 <li><a href="#Introduction">Introduction</a></li>
16 <li><a href="#Configuration">Configuration</a></li>
17 <li><a href="#Examples">Examples</a></li>
18 <ul>
19 <li><a href="#Tagging">Tagging</a></li>
20 <li><a href="#POD Efficiencies">POD Efficiencies</a></li>
21 <li><a href="#Byte Extraction">Byte Extraction</a></li>
22 </ul
23 <li><a href="#Reference">Reference</a></li>
24 <ul>
25 <li><a href="#boost/uuid/uuid.hpp">boost/uuid/uuid.hpp</a></li>
26 <ul>
27 <li><a href="#Synopsis">Synopsis</a></li>
28 <li><a href="#Size">Size</a></li>
29 <li><a href="#Iteration">Iteration</a></li>
30 <li><a href="#Nil">Nil uuid</a></li>
31 <li><a href="#Variant">Variant</a></li>
32 <li><a href="#Version">Version</a></li>
33 <li><a href="#Swap">Swap</a></li>
34 <li><a href="#Operators">Operators</a></li>
35 <li><a href="#Hash">Hash</a></li>
36 </ul>
37 <li><a href="#boost/uuid/uuid_generators.hpp">boost/uuid/uuid_generators.hpp</a></li>
38 <ul>
39 <li><a href="#Synopsis_generators">Synopsis</a></li>
40 </ul>
41 <li><a href="#boost/uuid/nil_generator.hpp">boost/uuid/nil_generator.hpp</a></li>
42 <ul>
43 <li><a href="#Synopsis_nil_generator">Synopsis</a></li>
44 <li><a href="#Nil Generator">Nil Generator</a></li>
45 </ul>
46 <li><a href="#boost/uuid/string_generator.hpp">boost/uuid/string_generator.hpp</a></li>
47 <ul>
48 <li><a href="#Synopsis_string_generator">Synopsis</a></li>
49 <li><a href="#String Generator">String Generator</a></li>
50 </ul>
51 <li><a href="#boost/uuid/name_generator.hpp">boost/uuid/name_generator.hpp</a></li>
52 <ul>
53 <li><a href="#Synopsis_name_generator">Synopsis</a></li>
54 <li><a href="#Name Generator">Name Generator</a></li>
55 </ul>
56 <li><a href="#boost/uuid/random_generator.hpp">boost/uuid/random_generator.hpp</a></li>
57 <ul>
58 <li><a href="#Synopsis_random_generator">Synopsis</a></li>
59 <li><a href="#Random Generator">Random Generator</a></li>
60 </ul>
61 <li><a href="#boost/uuid/uuid_io.hpp">boost/uuid/uuid_io.hpp</a></li>
62 <ul>
63 <li><a href="#Synopsis_io">Synopsis</a></li>
64 <li><a href="#Stream_operators">Stream Operators</a></li>
65 <li><a href="#to_string">To String</a></li>
66 </ul>
67 <li><a href="#boost/uuid/uuid_serialize.hpp">boost/uuid/uuid_serialize.hpp</a></li>
68 <ul>
69 <li><a href="#Synopsis_serialize">Synopsis</a></li>
70 <li><a href="#Serialization">Serialization</a></li>
71 </ul>
72 </ul>
73 <li><a href="#Design notes">Design notes</a></li>
74 <li><a href="#History and Acknowledgements">History and Acknowledgements</a></li>
75</ol>
76
77<h2><a name="Introduction">Introduction</a></h2>
78<p>
79A UUID, or Universally unique identifier, is intended to uniquely identify
80information in a distributed environment without significant central
81coordination. It can be used to tag objects with very short lifetimes, or
82to reliably identify very persistent objects across a network.
83<p>
84UUIDs have many applications. Some examples follow: Databases may use UUIDs
85to identify rows or records in order to ensure that they are unique across
86different databases, or for publication/subscription services. Network messages
87may be identified with a UUID to ensure that different parts of a message are put
88back together again. Distributed computing may use UUIDs to identify a remote
89procedure call. Transactions and classes involved in serialization may be
90identified by UUIDs. Microsoft's component object model (COM) uses UUIDs to
91distinguish different software component interfaces. UUIDs are inserted into
92documents from Microsoft Office programs. UUIDs identify audio or
93video streams in the Advanced Systems Format (ASF). UUIDs are also a basis
94for OIDs (object identifiers), and URNs (uniform resource name).
95
96<p>
97An attractive feature of UUIDs when compared to alternatives is their relative
98small size, of 128-bits, or 16-bytes. Another is that the creation of UUIDs
99does not require a centralized authority.
100
101<p>When UUIDs are generated by one of the defined
102mechanisms, they are either guaranteed to be unique, different from all other
103generated UUIDs (that is, it has never been generated before and it will
104never be generated again), or it is extremely likely to be unique (depending
105on the mechanism).
106
107<h2><a name="Configuration">Configuration</a></h2>
108
109<p>
110The library does not require building or any special configuration to be used.
111However, there are a few options that can be enabled by defining macros prior to
112including library headers. These macros are summarized in the following table.
113
114<p>
115<table border="1">
116<tr>
117<th>Macro</th><th>Description</th>
118</tr>
119<tr>
120<td><tt>BOOST_UUID_NO_SIMD</tt></td><td>If defined, disables any optimizations for <a href="http://en.wikipedia.org/wiki/SIMD">SIMD</a>-enabled processors. Generic versions of algorithms will be used instead. This may result in suboptimal performance. By default, optimized algorithms are used, when the library is able to detect the availability of SIMD extensions at compile time.</td>
121</tr>
122<tr>
123<td><tt>BOOST_UUID_USE_SSE2</tt></td><td>If defined, enables optimizations for <a href="http://en.wikipedia.org/wiki/SSE2">SSE2</a> exstensions available in modern x86 processors.</td>
124</tr>
125<tr>
126<td><tt>BOOST_UUID_USE_SSE3</tt></td><td>If defined, enables optimizations for <a href="http://en.wikipedia.org/wiki/SSE3">SSE3</a> exstensions available in modern x86 processors.</td>
127</tr>
128<tr>
129<td><tt>BOOST_UUID_USE_SSE41</tt></td><td>If defined, enables optimizations for <a href="http://en.wikipedia.org/wiki/SSE4#SSE4.1">SSE4.1</a> exstensions available in modern x86 processors.</td>
130</tr>
131</table>
132
133<p>
134By default the library attempts to detect the availability of SIMD extensions in the target CPU at compile time and automatically defines the appropriate macros if succeeded. The <tt>BOOST_UUID_USE_SSE*</tt> macros can be defined by users, if auto-detection fails and it is known that the target CPU will have the extension. Do not enable these extensions unless you're certain that they will always be available on any machine that will run your program. The library performs no run time checks, so if an extension is missing, the program will likely crash. Note that enabling more advanced extensions implies that more basic ones are also available.
135
136<h2><a name="Examples">Examples</a></h2>
137<h3><a name="Tagging">Tagging</a></h3>
138<pre>
139// example of tagging an object with a uuid
140// see <a href="./test/test_tagging.cpp"><tt>boost/libs/uuid/test/test_tagging.cpp</tt></a>
141
142#include &lt;<a href="./../../boost/uuid/uuid.hpp"><tt>boost/uuid/uuid.hpp</tt></a>&gt;
143#include &lt;<a href="./../../boost/uuid/uuid_generators.hpp"><tt>boost/uuid/uuid_generators.hpp</tt></a>&gt;
144
145class object
146{
147public:
148 object()
149 : tag(boost::uuids::random_generator()())
150 , state(0)
151 {}
152
153 explicit object(int state)
154 : tag(boost::uuids::random_generator()())
155 , state(state)
156 {}
157
158 object(object const&amp; rhs)
159 : tag(rhs.tag)
160 , state(rhs.state)
161 {}
162
163 bool operator==(object const&amp; rhs) const {
164 return tag == rhs.tag;
165 }
166
167 object&amp; operator=(object const&amp; rhs) {
168 tag = rhs.tag;
169 state = rhs.state;
170 }
171
172 int get_state() const { return state; }
173 void set_state(int new_state) { state = new_state; }
174
175private:
176 boost::uuids::uuid tag;
177
178 int state;
179};
180
181object o1(1);
182object o2 = o1;
183o2.set_state(2);
184assert(o1 == o2);
185
186object o3(3);
187assert(o1 != o3);
188assert(o2 != o3);
189</pre>
190
191<h3><a name="POD Efficiencies">POD Efficiencies</a></h3>
192<p>
193This library implements a UUID as a POD allowing a UUID
194to be used in the most efficient ways, including using memcpy,
195and aggregate initializers. A drawback is that a POD can
196not have any constructors, and thus declaring a UUID will not
197initialize it to a value generated by one of the defined
198mechanisms. But a class based on a UUID can be defined
199that does initialize itself to a value generated by one of
200the defined mechanisms.
201<p>
202Note that <tt>boost::is_pod</tt> is specialized for <tt>boost::uuids::uuid</tt>
203and depends on <a href="http://www.boost.org/libs/type_traits">Boost.TypeTraits</a>.
204Define <tt>BOOST_UUID_NO_TYPE_TRAITS</tt> before including <a href="./../../boost/uuid/uuid.hpp"><tt>boost/uuid/uuid.hpp</tt></a>
205to remove the dependency on <a href="http://www.boost.org/libs/type_traits">Boost.TypeTraits</a>.
206<pre>
207// example using memcpy and aggregate initializers
208// example of a class uuid see <a href="./test/test_uuid_class.cpp"><tt>boost/libs/uuid/test/test_uuid_class.cpp</tt></a>
209
210#include &lt;<a href="./../../boost/uuid/uuid.hpp"><tt>boost/uuid/uuid.hpp</tt></a>&gt;
211#include &lt;<a href="./../../boost/uuid/uuid_generators.hpp"><tt>boost/uuid/uuid_generators.hpp</tt></a>&gt;
212
213{ // example using memcpy
214 unsigned char uuid_data[16];
215 // fill uuid_data
216
217 boost::uuids::uuid u;
218
219 memcpy(&amp;u, uuid_data, 16);
220}
221
222{ // example using aggregate initializers
223 boost::uuids::uuid u =
224 { 0x12 ,0x34, 0x56, 0x78
225 , 0x90, 0xab
226 , 0xcd, 0xef
227 , 0x12, 0x34
228 , 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef
229 };
230}
231
232// example of creating a uuid class that
233// initializes the uuid in the constructor
234// using a defined mechanism
235
236class uuid_class : public boost::uuids::uuid
237{
238public:
239 uuid_class()
240 : boost::uuids::uuid(boost::uuids::random_generator()())
241 {}
242
243 explicit uuid_class(boost::uuids::uuid const&amp; u)
244 : boost::uuids::uuid(u)
245 {}
246
247 operator boost::uuids::uuid() {
248 return static_cast&lt;boost::uuids::uuid&amp;&gt;(*this);
249 }
250
251 operator boost::uuids::uuid() const {
252 return static_cast&lt;boost::uuids::uuid const&amp;&gt;(*this);
253 }
254};
255
256uuid_class u1;
257uuid_class u2;
258
259assert(u1 != u2);
260</pre>
261
262<h3><a name="Byte Extraction">Byte Extraction</a></h3>
263<p>It is sometimes useful to get at the 16 bytes of a <b>uuid</b> directly.
264Typical use is as follows:
265
266<pre>
267boost::uuids::uuid u;
268std::vector&lt;char&gt; v(u.size());
269std::copy(u.begin(), u.end(), v.begin());
270</pre>
271
272<p>Note: <tt>boost::uuids::uuid::size()</tt> always returns 16.
273
274<h2><a name="Reference">Reference</a></h2>
275<h3><a name="boost/uuid/uuid.hpp" href="./../../boost/uuid/uuid.hpp">boost/uuid/uuid.hpp</a></h3>
276<h4><a name="Synopsis">Synopsis</a></h4>
277<pre>
278namespace boost {
279namespace uuids {
280
281class uuid {
282public:
283 typedef uint8_t value_type;
284 typedef uint8_t&amp; reference;
285 typedef uint8_t const&amp; const_reference;
286 typedef uint8_t* iterator;
287 typedef uint8_t const* const_iterator;
288 typedef std::size_t size_type;
289 typedef std::ptrdiff_t difference_type;
290
291 static constexpr size_type static_size() noexcept;
292
293 // iteration
294 iterator begin() noexcept;
295 iterator end() noexcept;
296 const_iterator begin() const noexcept;
297 const_iterator end() const noexcept;
298
299 constexpr size_type size() const noexcept;
300
301 bool is_nil() const noexcept;
302
303 enum variant_type {
304 variant_ncs, // NCS backward compatibility
305 variant_rfc_4122, // defined in RFC 4122 document
306 variant_microsoft, // Microsoft Corporation backward compatibility
307 variant_future // future definition
308 };
309 variant_type variant() const noexcept;
310
311 enum version_type {
312 version_unknown = -1,
313 version_time_based = 1,
314 version_dce_security = 2,
315 version_name_based_md5 = 3,
316 version_random_number_based = 4,
317 version_name_based_sha1 = 5
318 };
319 version_type version() const noexcept;
320
321 // Swap function
322 void swap(uuid&amp; rhs) noexcept;
323
324 uint8_t data[static_size()];
325};
326
327// standard operators
328bool operator==(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
329bool operator!=(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
330bool operator&lt;(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
331bool operator&gt;(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
332bool operator&lt;=(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
333bool operator&gt;=(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
334
335void swap(uuid&amp; lhs, uuid&amp; rhs) noexcept;
336
337std::size_t hash_value(uuid const&amp; u) noexcept;
338
339}} // namespace boost::uuids
340</pre>
341
342<h4><a name="Size">Size</a></h4>
343
344<p>The size of a <b>uuid</b> (in bytes) can be obtained either by
345calling the function <tt>boost::uuids::uuid::size()</tt> or by
346calling the static function <tt>boost::uuids::uuid::static_size()</tt>,
347both always return 16.
348<pre>
349 boost::uuids::uuid u;
350 assert(16 == u.size());
351 assert(16 == boost::uuids::uuid::static_size());
352</pre>
353
354<h4><a name="Iteration">Iteration</a></h4>
355
356<p>Both iterators and constant iterators are provided.
357<pre>
358 boost::uuids::uuid u;
359 for (boost::uuids::uuid::const_iterator it=u.begin(); it!=u.end(); ++it) {
360 boost::uuids::uuid::value_type v = *it;
361 }
362 for (boost::uuids::uuid::iterator it=u.begin(); it!=u.end(); ++it) {
363 *it = 0;
364 }
365</pre>
366
367<h4><a name="Nil">Nil uuid</a></h4>
368<p>The function, <tt>boost::uuids::uuid::is_nil()</tt> returns true if and
369only if the <b>uuid</b> is equal to {00000000-0000-0000-0000-000000000000}.
370</p>
371
372<h4><a name="Variant">Variant</a></h4>
373<p>Three bits of a <b>uuid</b> determine the variant.</p>
374<pre>
375 boost::uuids::uuid u;
376 boost::uuids::uuid::variant_type v = u.variant();
377</pre>
378
379<h4><a name="Version">Version</a></h4>
380<p>Four bits of a <b>uuid</b> determine the variant, that is the mechanism
381used to generate the <b>uuid</b>.
382</p>
383<pre>
384 boost::uuids::uuid u;
385 boost::uuids::uuid::version_type v = u.version();
386</pre>
387
388<h4><a name="Swap">Swap</a></h4>
389<p>Both <tt>boost::uuids::uuid::swap()</tt> and <tt>boost::uuids::swap()</tt>
390are provided.
391</p>
392<pre>
393 boost::uuids::uuid u1, u2;
394 u1.swap(u2);
395 swap(u1, u2);
396</pre>
397
398<h4><a name="Operators">Operators</a></h4>
399<p>
400All of the standard numeric operators are defined for the <b>uuid</b>
401class. These include:
402<pre>
403 operator==
404 operator!=
405 operator&lt;
406 operator&gt;
407 operator&lt;=
408 operator&gt;=
409</pre>
410
411<h4><a name="Hash">Hash Function</a></h4>
412<p>
413This function allows <b>uuid</b>s to be used with
414<a href="http://www.boost.org/doc/html/hash.html"><b>boost::hash</b></a>
415
416<pre>
417boost::hash&lt;boost::uuids::uuid&gt; uuid_hasher;
418std::size_t uuid_hash_value = uuid_hasher(boost::uuids::uuid());
419</pre>
420
421<h3><a name="boost/uuid/uuid_generators.hpp" href="./../../boost/uuid/uuid_generators.hpp">boost/uuid/uuid_generators.hpp</a></h3>
422<h4><a name="Synopsis_generators">Synopsis</a></h4>
423This file includes all the <b>uuid</b> generators for convenience.
424<pre>
425#include &lt;<a href="./../../boost/uuid/nil_generator.hpp"><tt>boost/uuid/nil_generator.hpp</tt></a>&gt;
426#include &lt;<a href="./../../boost/uuid/string_generator.hpp"><tt>boost/uuid/string_generator.hpp</tt></a>&gt;
427#include &lt;<a href="./../../boost/uuid/name_generator.hpp"><tt>boost/uuid/name_generator.hpp</tt></a>&gt;
428#include &lt;<a href="./../../boost/uuid/random_generator.hpp"><tt>boost/uuid/random_generator.hpp</tt></a>&gt;
429</pre>
430
431<h3><a name="boost/uuid/nil_generator.hpp" href="./../../boost/uuid/nil_generator.hpp">boost/uuid/nil_generator.hpp</a></h3>
432<h4><a name="Synopsis_nil_generator">Synopsis</a></h4>
433<pre>
434namespace boost {
435namespace uuids {
436
437struct nil_generator {
438 typedef uuid result_type;
439
440 uuid operator()() const;
441};
442uuid nil_uuid();
443
444}} //namespace boost::uuids
445</pre>
446
447<h4><a name="Nil Generator">Nil Generator</a></h4>
448<p>The <tt>boost::uuids::nil_generator</tt> class always generates a nil <b>uuid</b>.
449<pre>
450boost::uuids::nil_generator gen;
451boost::uuids::uuid u = gen();
452assert(u.is_nil() == true);
453
454// or for convenience
455boost::uuids::uuid u = boost::uuids::nil_uuid();
456assert(u.is_nil() == true);
457</pre>
458
459<h3><a name="boost/uuid/string_generator.hpp" href="./../../boost/uuid/string_generator.hpp">boost/uuid/string_generator.hpp</a></h3>
460<h4><a name="Synopsis_string_generator">Synopsis</a></h4>
461
462<pre>
463namespace boost {
464namespace uuids {
465
466struct string_generator {
467 typedef uuid result_type;
468
469 template &lt;typename ch, typename char_traits, typename alloc&gt;
470 uuid operator()(std::basic_string&lt;ch, char_traits, alloc&gt; const&amp; s) const;
471};
472
473}} //namespace boost::uuids
474</pre>
475
476<h4><a name="String Generator">String Generator</a></h4>
477<p>The <tt>boost::uuids::string_generator</tt> class generates a <b>uuid</b> from a string.
478<pre>
479boost::uuids::string_generator gen;
480boost::uuids::uuid u1 = gen("{01234567-89ab-cdef-0123-456789abcdef}");
481boost::uuids::uuid u2 = gen(L"01234567-89ab-cdef-0123-456789abcdef");
482boost::uuids::uuid u3 = gen(std::string("0123456789abcdef0123456789abcdef"));
483boost::uuids::uuid u4 = gen(std::wstring(L"01234567-89ab-cdef-0123-456789abcdef"));
484</pre>
485
486<h3><a name="boost/uuid/name_generator.hpp" href="./../../boost/uuid/name_generator.hpp">boost/uuid/name_generator.hpp</a></h3>
487<h4><a name="Synopsis_name_generator">Synopsis</a></h4>
488
489<pre>
490namespace boost {
491namespace uuids {
492
493class name_generator {
494public:
495 typedef uuid result_type;
496
497 explicit name_generator(uuid const&amp; namespace_uuid);
498
499 uuid operator()(const char* name) const;
500 uuid operator()(const wchar_t* name) const;
501 tempate &lt;typename ch, typename char_traits, typename alloc&gt;
502 uuid operator()(std::basic_string&lt;ch, char_traits, alloc&gt; const&amp; name) const;
503 uuid operator()(void const* buffer, std::size_t byte_count) const;
504};
505
506}} //namespace boost::uuids
507</pre>
508
509<h4><a name="Name Generator">Name Generator</a></h4>
510<p>
511The <tt>boost::uuids::name_generator</tt> class generates a name based <b>uuid</b> from a
512namespace uuid and a name.
513<pre>
514boost::uuids::uuid dns_namespace_uuid; // initialize to {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
515
516boost::uuids::name_generator gen(dns_namespace_uuid);
517boost::uuids::uuid u = gen("boost.org");
518</pre>
519
520<h3><a name="boost/uuid/random_generator.hpp" href="./../../boost/uuid/random_generator.hpp">boost/uuid/random_generator.hpp</a></h3>
521<h4><a name="Synopsis_random_generator">Synopsis</a></h4>
522
523<pre>
524namespace boost {
525namespace uuids {
526
527template &lt;typename UniformRandomNumberGenerator&gt;
528class basic_random_generator {
529public:
530 typedef uuid result_type;
531
532 basic_random_generator();
533 explicit basic_random_generator(UniformRandomNumberGenerator&amp; gen);
534 explicit basic_random_generator(UniformRandomNumberGenerator* pGen);
535
536 uuid operator()();
537};
538typedef basic_random_generator&lt;mt19937&gt; random_generator;
539
540}} // namespace boost::uuids
541</pre>
542
543<h4><a name="Random Generator">Random Generator</a></h4>
544<p>
545The <tt>boost::uuids::basic_random_generator</tt> class generates a random number
546based uuid from a random number generator (one that conforms to the
547<a href="http://www.boost.org/libs/random/random-concepts.html#uniform-rng">UniformRandomNumberGenerator</a>
548concept).
549<pre>
550//default construct the random number generator and seed it
551boost::uuids::basic_random_generator&lt;boost::mt19937&gt; gen;
552boost::uuids::uuid u = gen();
553
554//for convenience boost::uuids::random_generator
555//is equivalent to boost::uuids::basic_random_generator&lt;boost::mt19937&gt;
556boost::uuids::random_generator gen;
557boost::uuids::uuid u = gen();
558
559//use an existing random number generator
560//pass either a reference or a pointer to the random number generator
561boost::mt19937 ran;
562boost::uuids::basic_random_generator&lt;boost::mt19937&gt; gen(&amp;ran);
563boost::uuids::uuid u = gen();
564</pre>
565
566<h3><a name="boost/uuid/uuid_io.hpp" href="./../../boost/uuid/uuid_io.hpp">boost/uuid/uuid_io.hpp</a></h3>
567<h4><a name="Synopsis_io">Synopsis</a></h4>
568<pre>
569namespace boost {
570namespace uuids {
571
572template &lt;typename ch, typename char_traits&gt;
573 std::basic_ostream&lt;ch, char_traits&gt;&amp; operator&lt;&lt;(std::basic_ostream&lt;ch, char_traits&gt; &amp;os, uuid const&amp; u);
574
575template &lt;typename ch, typename char_traits&gt;
576 std::basic_istream&lt;ch, char_traits&gt;&amp; operator&gt;&gt;(std::basic_istream&lt;ch, char_traits&gt; &amp;is, uuid &amp;u);
577
578std::string to_string(uuid const&amp; u);
579std::wstring to_wstring(uuid const&amp; u);
580
581}} // namespace boost::uuids
582</pre>
583
584<h4><a name="Stream_operators">Stream Operators</a></h4>
585<p>
586The standard input and output stream operators <tt>&lt;&lt;</tt> and <tt>&gt;&gt;</tt>
587are provided by including <a href="../../boost/uuid/uuid_io.hpp"><tt>boost/uuid/uuid_io.hpp</tt></a>.
588The string representation of a <b>uuid</b> is <tt>hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh</tt>
589where <tt>h</tt> is a hexidecimal digit.
590<pre>
591boost::uuids::uuid u1; // initialize uuid
592
593std::stringstream ss;
594ss &lt;&lt; u1;
595
596boost::uuids::uuid u2;
597ss &gt;&gt; u2;
598
599assert(u1, u2);
600</pre>
601
602<p>
603One can also use <a href="http://www.boost.org/libs/conversion/lexical_cast.htm"><tt>boost::lexical_cast</tt></a>.
604<pre>
605boost::uuids::uuid u1; // initialize uuid
606
607std::string s = boost::lexical_cast&lt;std::string&gt;(u);
608boost::uuids::uuid u2 = boost::lexical_cast&lt;boost::uuids::uuid&gt;(s);
609
610assert(u1 == u2);
611</pre>
612
613<h4><a name="to_string">To String</a></h4>
614<p>
615The functions <tt>to_string</tt> and <tt>to_wstring</tt> are provided as a
616convenience to convert a <b>uuid</b> to a string. They are also likely faster than
617the stream operators or using <a href="http://www.boost.org/libs/conversion/lexical_cast.htm"><tt>boost::lexical_cast</tt></a>.
618<pre>
619boost::uuids::uuid u; // initialize uuid
620
621std::string s1 = to_string(u);
622
623std::wstring s2 = to_wstring(u);
624</pre>
625
626<h3><a name="boost/uuid/uuid_serialize.hpp" href="./../../boost/uuid/uuid_serialize.hpp">boost/uuid/uuid_serialize.hpp</a></h3>
627<h4><a name="Synopsis_serialize">Synopsis</a></h4>
628<pre>
629namespace boost {
630namespace uuids {
631
632BOOST_CLASS_IMPLEMENTATION(boost::uuids::uuid, boost::serialization::primitive_type)
633
634}} // namespace boost::uuids
635</pre>
636
637<h4><a name="Serialization">Serialization</a></h4>
638<p>
639Serialization is accomplished with the <a href="http://www.boost.org/libs/serialization/doc/index.html">
640Boost Serialization</a> library. A <b>uuid</b> is serialized as a
641<a href="http://www.boost.org/libs/serialization/doc/serialization.html#primitiveoperators">
642primitive type</a>, thus only the <b>uuid</b> value will be saved to/loaded from an archive.
643<p>
644Include <a href="../../boost/uuid/uuid_serialize.hpp"><tt>boost/uuid/uuid_serialize.hpp</tt></a> to enable serialization for <b>uuid</b>s.
645
646<h2><a name="Design notes">Design notes</a></h2>
647<p>
648The document, <a href="http://www.itu.int/ITU-T/studygroups/com17/oid/X.667-E.pdf">
649http://www.itu.int/ITU-T/studygroups/com17/oid/X.667-E.pdf</a>, was used to design
650and implement the <b>boost::uuids::uuid</b> struct.
651
652<p>The <tt>boost::uuids::basic_random_generator</tt> class' default constructor
653seeds the random number generator with a SHA-1 hash of a number of different
654values including <tt>std::time(0)</tt>, <tt>std::clock()</tt>, uninitialized
655data, value return from <tt>new unsigned int</tt>, etc..
656
657<p>Using <a href="http://valgrind.org/">Valgrind</a> produces a number of false
658positives with the default constructor of <tt>boost::uuids::basic_random_generator</tt>.
659One solution is to suppress the errors as described in
660<a href="http://valgrind.org/docs/manual/manual-core.html#manual-core.suppress">Valgrind's documentation</a>.
661Another solution is to use a different constructor of <tt>boost::uuids::basic_random_generator</tt>
662and explicitly pass in a random number generator.
663<pre>
664boost::mt19937 ran;
665ran.seed(time(NULL)); // one should likely seed in a better way
666boost::uuids::basic_random_generator&lt;boost::mt19937&gt; gen(&ran);
667boost::uuids::uuid u = gen();
668</pre>
669
670<p>The <tt>boost::uuids::name_generator</tt> class uses the SHA-1 hash function to
671compute the <b>uuid</b>.
672
673<p>All functions are re-entrant. Classes are as thread-safe as an int. That is an
674instance can not be shared between threads without proper synchronization.
675
676<h2><a name="History and Acknowledgements">History and Acknowledgements</a></h2>
677<p>
678A number of people on the <a href="http://www.boost.org/">boost.org</a>
679mailing list provided useful comments and greatly helped to shape the library.
680
681<p>Revised&nbsp; February 6, 2010</p>
682
683<hr>
684