| 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 23 matching lines...) Expand all Loading... |
| 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. |
| 42 UUID(); | 42 UUID(); |
| 43 | 43 |
| 44 //! \brief Tag to pass to constructor to indicate it should initialize with |
| 45 //! generated data. |
| 46 struct InitializeWithNewTag {}; |
| 47 |
| 48 //! \brief Initializes the %UUID using a standard system facility to generate |
| 49 //! the value. |
| 50 //! |
| 51 //! CHECKs on failure with a message logged. |
| 52 explicit UUID(InitializeWithNewTag); |
| 53 |
| 44 //! \copydoc InitializeFromBytes() | 54 //! \copydoc InitializeFromBytes() |
| 45 explicit UUID(const uint8_t* bytes); | 55 explicit UUID(const uint8_t* bytes); |
| 46 | 56 |
| 47 bool operator==(const UUID& that) const; | 57 bool operator==(const UUID& that) const; |
| 48 bool operator!=(const UUID& that) const { return !operator==(that); } | 58 bool operator!=(const UUID& that) const { return !operator==(that); } |
| 49 | 59 |
| 50 //! \brief Initializes the %UUID from a sequence of bytes. | 60 //! \brief Initializes the %UUID from a sequence of bytes. |
| 51 //! | 61 //! |
| 52 //! \a bytes is taken as a %UUID laid out in big-endian format in memory. On | 62 //! \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 | 63 //! little-endian machines, appropriate byte-swapping will be performed to |
| 54 //! initialize an object’s data members. | 64 //! initialize an object’s data members. |
| 55 //! | 65 //! |
| 56 //! \param[in] bytes A buffer of exactly 16 bytes that will be assigned to the | 66 //! \param[in] bytes A buffer of exactly 16 bytes that will be assigned to the |
| 57 //! %UUID. | 67 //! %UUID. |
| 58 void InitializeFromBytes(const uint8_t* bytes); | 68 void InitializeFromBytes(const uint8_t* bytes); |
| 59 | 69 |
| 60 //! \brief Initializes the %UUID from a RFC 4122 §3 formatted string. | 70 //! \brief Initializes the %UUID from a RFC 4122 §3 formatted string. |
| 61 //! | 71 //! |
| 62 //! \param[in] string A string of the form | 72 //! \param[in] string A string of the form |
| 63 //! `"00112233-4455-6677-8899-aabbccddeeff"`. | 73 //! `"00112233-4455-6677-8899-aabbccddeeff"`. |
| 64 //! | 74 //! |
| 65 //! \return `true` if the string was formatted correctly and the object has | 75 //! \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 | 76 //! been initialized with the data. `false` if the string could not be |
| 67 //! parsed, with the object state untouched. | 77 //! parsed, with the object state untouched. |
| 68 bool InitializeFromString(const base::StringPiece& string); | 78 bool InitializeFromString(const base::StringPiece& string); |
| 69 | 79 |
| 80 //! \brief Initializes the %UUID using a standard system facility to generate |
| 81 //! the value. |
| 82 //! |
| 83 //! \return `true` if the %UUID was initialized correctly, `false` otherwise |
| 84 //! with a message logged. |
| 85 bool InitializeWithNew(); |
| 86 |
| 70 #if defined(OS_WIN) || DOXYGEN | 87 #if defined(OS_WIN) || DOXYGEN |
| 71 //! \brief Initializes the %UUID from a system `UUID` or `GUID` structure. | 88 //! \brief Initializes the %UUID from a system `UUID` or `GUID` structure. |
| 72 //! | 89 //! |
| 73 //! \param[in] system_uuid A system `UUID` or `GUID` structure. | 90 //! \param[in] system_uuid A system `UUID` or `GUID` structure. |
| 74 void InitializeFromSystemUUID(const ::UUID* system_uuid); | 91 void InitializeFromSystemUUID(const ::UUID* system_uuid); |
| 75 #endif // OS_WIN | 92 #endif // OS_WIN |
| 76 | 93 |
| 77 //! \brief Formats the %UUID per RFC 4122 §3. | 94 //! \brief Formats the %UUID per RFC 4122 §3. |
| 78 //! | 95 //! |
| 79 //! \return A string of the form `"00112233-4455-6677-8899-aabbccddeeff"`. | 96 //! \return A string of the form `"00112233-4455-6677-8899-aabbccddeeff"`. |
| 80 std::string ToString() const; | 97 std::string ToString() const; |
| 81 | 98 |
| 82 #if defined(OS_WIN) || DOXYGEN | 99 #if defined(OS_WIN) || DOXYGEN |
| 83 //! \brief The same as ToString, but returned as a string16. | 100 //! \brief The same as ToString, but returned as a string16. |
| 84 base::string16 ToString16() const; | 101 base::string16 ToString16() const; |
| 85 #endif // OS_WIN | 102 #endif // OS_WIN |
| 86 | 103 |
| 87 // These fields are laid out according to RFC 4122 §4.1.2. | 104 // These fields are laid out according to RFC 4122 §4.1.2. |
| 88 uint32_t data_1; | 105 uint32_t data_1; |
| 89 uint16_t data_2; | 106 uint16_t data_2; |
| 90 uint16_t data_3; | 107 uint16_t data_3; |
| 91 uint8_t data_4[2]; | 108 uint8_t data_4[2]; |
| 92 uint8_t data_5[6]; | 109 uint8_t data_5[6]; |
| 93 }; | 110 }; |
| 94 | 111 |
| 95 } // namespace crashpad | 112 } // namespace crashpad |
| 96 | 113 |
| 97 #endif // CRASHPAD_UTIL_MISC_UUID_H_ | 114 #endif // CRASHPAD_UTIL_MISC_UUID_H_ |
| OLD | NEW |