Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-14 08:30:46

0001 // Created on: 1997-06-19
0002 // Created by: Christophe LEYNADIER
0003 // Copyright (c) 1997-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Standard_GUID_HeaderFile
0018 #define _Standard_GUID_HeaderFile
0019 
0020 #include <Standard_Handle.hxx>
0021 
0022 #include <Standard_Integer.hxx>
0023 #include <Standard_CString.hxx>
0024 #include <Standard_UUID.hxx>
0025 #include <Standard_PCharacter.hxx>
0026 #include <Standard_PExtCharacter.hxx>
0027 #include <Standard_OStream.hxx>
0028 
0029 #define Standard_GUID_SIZE 36
0030 #define Standard_GUID_SIZE_ALLOC Standard_GUID_SIZE + 1
0031 
0032 class Standard_GUID
0033 {
0034 public:
0035   DEFINE_STANDARD_ALLOC
0036 
0037   Standard_EXPORT Standard_GUID();
0038 
0039   //! build a GUID from an ascii string with the
0040   //! following format:
0041   //! Length : 36 char
0042   //! "00000000-0000-0000-0000-000000000000"
0043   Standard_EXPORT Standard_GUID(const Standard_CString aGuid);
0044 
0045   //! build a GUID from an unicode string with the
0046   //! following format:
0047   //!
0048   //! "00000000-0000-0000-0000-000000000000"
0049   Standard_EXPORT Standard_GUID(const Standard_ExtString aGuid);
0050 
0051   Standard_EXPORT Standard_GUID(const Standard_Integer      a32b,
0052                                 const Standard_ExtCharacter a16b1,
0053                                 const Standard_ExtCharacter a16b2,
0054                                 const Standard_ExtCharacter a16b3,
0055                                 const Standard_Byte         a8b1,
0056                                 const Standard_Byte         a8b2,
0057                                 const Standard_Byte         a8b3,
0058                                 const Standard_Byte         a8b4,
0059                                 const Standard_Byte         a8b5,
0060                                 const Standard_Byte         a8b6);
0061 
0062   Standard_EXPORT Standard_GUID(const Standard_UUID& aGuid);
0063 
0064   Standard_EXPORT Standard_GUID(const Standard_GUID& aGuid);
0065 
0066   Standard_EXPORT Standard_UUID ToUUID() const;
0067 
0068   //! translate the GUID into ascii string
0069   //! the aStrGuid is allocated by user.
0070   //! the guid have the following format:
0071   //!
0072   //! "00000000-0000-0000-0000-000000000000"
0073   Standard_EXPORT void ToCString(const Standard_PCharacter aStrGuid) const;
0074 
0075   //! translate the GUID into unicode string
0076   //! the aStrGuid is allocated by user.
0077   //! the guid have the following format:
0078   //!
0079   //! "00000000-0000-0000-0000-000000000000"
0080   Standard_EXPORT void ToExtString(const Standard_PExtCharacter aStrGuid) const;
0081 
0082   Standard_EXPORT Standard_Boolean IsSame(const Standard_GUID& uid) const;
0083 
0084   Standard_Boolean operator==(const Standard_GUID& uid) const { return IsSame(uid); }
0085 
0086   Standard_EXPORT Standard_Boolean IsNotSame(const Standard_GUID& uid) const;
0087 
0088   Standard_Boolean operator!=(const Standard_GUID& uid) const { return IsNotSame(uid); }
0089 
0090   Standard_EXPORT void Assign(const Standard_GUID& uid);
0091 
0092   void operator=(const Standard_GUID& uid) { Assign(uid); }
0093 
0094   Standard_EXPORT void Assign(const Standard_UUID& uid);
0095 
0096   void operator=(const Standard_UUID& uid) { Assign(uid); }
0097 
0098   //! Display the GUID with the following format:
0099   //!
0100   //! "00000000-0000-0000-0000-000000000000"
0101   Standard_EXPORT void ShallowDump(Standard_OStream& aStream) const;
0102 
0103   //! Check the format of a GUID string.
0104   //! It checks the size, the position of the '-' and the correct size of fields.
0105   Standard_EXPORT static Standard_Boolean CheckGUIDFormat(const Standard_CString aGuid);
0106 
0107   template <class T>
0108   friend struct std::hash;
0109 
0110 private:
0111   Standard_Integer      my32b;
0112   Standard_ExtCharacter my16b1;
0113   Standard_ExtCharacter my16b2;
0114   Standard_ExtCharacter my16b3;
0115   Standard_Byte         my8b1;
0116   Standard_Byte         my8b2;
0117   Standard_Byte         my8b3;
0118   Standard_Byte         my8b4;
0119   Standard_Byte         my8b5;
0120   Standard_Byte         my8b6;
0121 };
0122 
0123 namespace std
0124 {
0125 template <>
0126 struct hash<Standard_GUID>
0127 {
0128   size_t operator()(const Standard_GUID& theGUID) const noexcept
0129   {
0130     struct GUID
0131     {
0132       Standard_Integer      my32b;
0133       Standard_ExtCharacter my16b1;
0134       Standard_ExtCharacter my16b2;
0135       Standard_ExtCharacter my16b3;
0136       Standard_Byte         my8b1;
0137       Standard_Byte         my8b2;
0138       Standard_Byte         my8b3;
0139       Standard_Byte         my8b4;
0140       Standard_Byte         my8b5;
0141       Standard_Byte         my8b6;
0142     };
0143 
0144     GUID aGUID{theGUID.my32b,
0145                theGUID.my16b1,
0146                theGUID.my16b2,
0147                theGUID.my16b3,
0148                theGUID.my8b1,
0149                theGUID.my8b2,
0150                theGUID.my8b3,
0151                theGUID.my8b4,
0152                theGUID.my8b5,
0153                theGUID.my8b6};
0154     return opencascade::hashBytes(&aGUID, sizeof(GUID));
0155   }
0156 };
0157 } // namespace std
0158 
0159 #endif // _Standard_GUID_HeaderFile