OLD | NEW |
---|---|
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 //! \brief A universally unique identifier (%UUID). | 32 //! \brief A universally unique identifier (%UUID). |
33 //! | 33 //! |
34 //! An alternate term for %UUID is “globally unique identifier” (GUID), used | 34 //! An alternate term for %UUID is “globally unique identifier” (GUID), used |
35 //! primarily by Microsoft. | 35 //! primarily by Microsoft. |
36 //! | 36 //! |
37 //! A %UUID is a unique 128-bit number specified by RFC 4122. | 37 //! A %UUID is a unique 128-bit number specified by RFC 4122. |
38 //! | 38 //! |
39 //! This is a standard-layout structure. | 39 //! This is a standard-layout structure. |
40 struct UUID { | 40 struct UUID { |
41 //! \brief Initializes the %UUID to zero. | 41 //! \brief Initializes the %UUID to zero. |
Mark Mentovai
2015/04/17 21:32:44
The constructor form would be nice because it avoi
scottmg
2015/04/20 18:20:41
OK, added. I made it CHECKing for Windows' potenti
| |
42 UUID(); | 42 UUID(); |
43 | 43 |
44 //! \copydoc InitializeFromBytes() | 44 //! \copydoc InitializeFromBytes() |
45 explicit UUID(const uint8_t* bytes); | 45 explicit UUID(const uint8_t* bytes); |
46 | 46 |
47 bool operator==(const UUID& that) const; | 47 bool operator==(const UUID& that) const; |
48 bool operator!=(const UUID& that) const { return !operator==(that); } | 48 bool operator!=(const UUID& that) const { return !operator==(that); } |
49 | 49 |
50 //! \brief Initializes the %UUID from a sequence of bytes. | 50 //! \brief Initializes the %UUID from a sequence of bytes. |
51 //! | 51 //! |
52 //! \a bytes is taken as a %UUID laid out in big-endian format in memory. On | 52 //! \a bytes is taken as a %UUID laid out in big-endian format in memory. On |
53 //! little-endian machines, appropriate byte-swapping will be performed to | 53 //! little-endian machines, appropriate byte-swapping will be performed to |
54 //! initialize an object’s data members. | 54 //! initialize an object’s data members. |
55 //! | 55 //! |
56 //! \param[in] bytes A buffer of exactly 16 bytes that will be assigned to the | 56 //! \param[in] bytes A buffer of exactly 16 bytes that will be assigned to the |
57 //! %UUID. | 57 //! %UUID. |
58 void InitializeFromBytes(const uint8_t* bytes); | 58 void InitializeFromBytes(const uint8_t* bytes); |
59 | 59 |
60 //! \brief Initializes the %UUID from a RFC 4122 §3 formatted string. | 60 //! \brief Initializes the %UUID from a RFC 4122 §3 formatted string. |
61 //! | 61 //! |
62 //! \param[in] string A string of the form | 62 //! \param[in] string A string of the form |
63 //! `"00112233-4455-6677-8899-aabbccddeeff"`. | 63 //! `"00112233-4455-6677-8899-aabbccddeeff"`. |
64 //! | 64 //! |
65 //! \return `true` if the string was formatted correctly and the object has | 65 //! \return `true` if the string was formatted correctly and the object has |
66 //! been initialized with the data. `false` if the string could not be | 66 //! been initialized with the data. `false` if the string could not be |
67 //! parsed, with the object state untouched. | 67 //! parsed, with the object state untouched. |
68 bool InitializeFromString(const base::StringPiece& string); | 68 bool InitializeFromString(const base::StringPiece& string); |
69 | 69 |
70 //! \brief Initializes the %UUID using a standard system facility to generate | |
71 //! the value. | |
72 //! | |
73 //! \return `true` if the %UUID was initialized correctly, `false` otherwise | |
74 //! with a message logged. | |
75 bool InitializeWithNew(); | |
76 | |
70 #if defined(OS_WIN) || DOXYGEN | 77 #if defined(OS_WIN) || DOXYGEN |
71 //! \brief Initializes the %UUID from a system `UUID` or `GUID` structure. | 78 //! \brief Initializes the %UUID from a system `UUID` or `GUID` structure. |
72 //! | 79 //! |
73 //! \param[in] system_uuid A system `UUID` or `GUID` structure. | 80 //! \param[in] system_uuid A system `UUID` or `GUID` structure. |
74 void InitializeFromSystemUUID(const ::UUID* system_uuid); | 81 void InitializeFromSystemUUID(const ::UUID* system_uuid); |
75 #endif // OS_WIN | 82 #endif // OS_WIN |
76 | 83 |
77 //! \brief Formats the %UUID per RFC 4122 §3. | 84 //! \brief Formats the %UUID per RFC 4122 §3. |
78 //! | 85 //! |
79 //! \return A string of the form `"00112233-4455-6677-8899-aabbccddeeff"`. | 86 //! \return A string of the form `"00112233-4455-6677-8899-aabbccddeeff"`. |
80 std::string ToString() const; | 87 std::string ToString() const; |
81 | 88 |
82 #if defined(OS_WIN) || DOXYGEN | 89 #if defined(OS_WIN) || DOXYGEN |
83 //! \brief The same as ToString, but returned as a string16. | 90 //! \brief The same as ToString, but returned as a string16. |
84 base::string16 ToString16() const; | 91 base::string16 ToString16() const; |
85 #endif // OS_WIN | 92 #endif // OS_WIN |
86 | 93 |
87 // These fields are laid out according to RFC 4122 §4.1.2. | 94 // These fields are laid out according to RFC 4122 §4.1.2. |
88 uint32_t data_1; | 95 uint32_t data_1; |
89 uint16_t data_2; | 96 uint16_t data_2; |
90 uint16_t data_3; | 97 uint16_t data_3; |
91 uint8_t data_4[2]; | 98 uint8_t data_4[2]; |
92 uint8_t data_5[6]; | 99 uint8_t data_5[6]; |
93 }; | 100 }; |
94 | 101 |
95 } // namespace crashpad | 102 } // namespace crashpad |
96 | 103 |
97 #endif // CRASHPAD_UTIL_MISC_UUID_H_ | 104 #endif // CRASHPAD_UTIL_MISC_UUID_H_ |
OLD | NEW |