00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00017 #if !defined(OPENNURBS_UUID_INC_) 00018 #define OPENNURBS_UUID_INC_ 00019 00020 // ON_UUID is a 16 byte universally unique identifier 00021 #if defined(UUID_DEFINED) 00022 typedef UUID ON_UUID; 00023 #elif defined(GUID_DEFINED) 00024 typedef GUID ON_UUID; 00025 #else 00026 00027 #define ON_UUID_DECLARED_AS_CLASS 00028 // For uuids, it is critical that the DataN fields have 00029 // exactly the sizes specified below. For that reason, 00030 // the ON__UINTnn typedefs are used. 00031 class ON_CLASS ON_UUID 00032 { 00033 public: 00034 ON__UINT32 Data1; // 32 bit unsigned integer 00035 ON__UINT16 Data2; // 16 bit unsigned integer 00036 ON__UINT16 Data3; // 16 bit unsigned integer 00037 unsigned char Data4[8]; 00038 00039 bool operator==(const ON_UUID& other) const; 00040 bool operator!=(const ON_UUID& other) const; 00041 }; 00042 00043 #endif 00044 00045 ON_BEGIN_EXTERNC 00046 00047 // All bits are zero in ON_nil_uuid and 00048 // ON_UuidCompare( ON_nil_uuid, U ) < 0 if U != ON_nil_uuid. 00049 extern ON_EXTERN_DECL const ON_UUID ON_nil_uuid; 00050 00051 // All bits are one in ON_max_uuid and 00052 // ON_UuidCompare( U, ON_max_uuid ) < 0 if U != ON_max_uuid. 00053 extern ON_EXTERN_DECL const ON_UUID ON_max_uuid; 00054 00055 // Application ids for the versions of Rhino that 00056 // write 3dm files. All userdata classed defined 00057 // in the core Rhino.exe should use these ids 00058 // as the application id. 00059 // In situations where you want to use the id 00060 // for the current version of Rhino, use 00061 // ON_rhino_id and you won't have to update 00062 // your code when Rhino versions roll. 00063 extern ON_EXTERN_DECL const ON_UUID ON_rhino2_id; 00064 extern ON_EXTERN_DECL const ON_UUID ON_rhino3_id; 00065 extern ON_EXTERN_DECL const ON_UUID ON_rhino4_id; 00066 extern ON_EXTERN_DECL const ON_UUID ON_rhino5_id; 00067 extern ON_EXTERN_DECL const ON_UUID ON_rhino_id; 00068 00069 // Application ids for usedata written by versions 00070 // of opennurbs before userdata had application ids. 00071 extern ON_EXTERN_DECL const ON_UUID ON_v2_userdata_id; 00072 extern ON_EXTERN_DECL const ON_UUID ON_v3_userdata_id; 00073 extern ON_EXTERN_DECL const ON_UUID ON_v4_userdata_id; 00074 00075 // Application id for the versions of openNURBS that 00076 // write userdata in 3dm files. User data whose class 00077 // definition is in opennurbs should use these 00078 // ids as the user data application id. 00079 // No other user data should use these ids. 00080 // The "extern ON_EXTERN_DECL" prefix on the declarations 00081 // of these ids was a mistake that will be corrected when 00082 // the public SDK can be changed. 00083 // In situations where you want to use the id 00084 // for the current version of opennurbs, use 00085 // ON_opennurbs_id and you won't have to update 00086 // your code when opennurbs versions roll. 00087 extern ON_EXTERN_DECL const ON_UUID ON_opennurbs4_id; 00088 extern ON_EXTERN_DECL const ON_UUID ON_opennurbs5_id; 00089 extern ON_EXTERN_DECL const ON_UUID ON_opennurbs_id; 00090 00091 ON_END_EXTERNC 00092 00093 #if defined(ON_CPLUSPLUS) 00094 00095 /* 00096 Description: 00097 Creates a new uuid.(&a,&b) compares two uuids. 00098 Parameters: 00099 new_uuid - [out] 00100 Returns: 00101 True if successful. 00102 Remarks: 00103 Only works on Windows. 00104 */ 00105 ON_DECL 00106 bool ON_CreateUuid( ON_UUID& uuid ); 00107 00108 /* 00109 Description: 00110 This class is used by ON_UuidIndexList. It is used when 00111 uuids are used to search for items that can be found by 00112 an integer index. 00113 */ 00114 class ON_CLASS ON_UuidIndex 00115 { 00116 public: 00117 ON_UuidIndex(); 00118 00119 /* 00120 Dictionary compare m_id and then m_i. 00121 */ 00122 static 00123 int CompareIdAndIndex( const ON_UuidIndex* a, const ON_UuidIndex* b ); 00124 00125 /* 00126 Dictionary compare m_id and then m_i. 00127 */ 00128 static 00129 int CompareIndexAndId( const ON_UuidIndex* a, const ON_UuidIndex* b ); 00130 00131 /* 00132 Compare m_id and ignore m_i. 00133 */ 00134 static 00135 int CompareId( const ON_UuidIndex* a, const ON_UuidIndex* b ); 00136 00137 /* 00138 Compare m_i and ignore m_id. 00139 */ 00140 static 00141 int CompareIndex( const ON_UuidIndex* a, const ON_UuidIndex* b ); 00142 00143 // In cases when there is a discrepancy between the m_id and 00144 // m_i, m_id is assumed to be valid unless comments where this 00145 // class is used indicate otherwise. 00146 ON_UUID m_id; 00147 int m_i; 00148 }; 00149 00150 /* 00151 Description: 00152 ON_UuidCompare(&a,&b) compares two uuids. 00153 Parameters: 00154 a - [in] 00155 b - [in] 00156 Returns: 00157 @untitled table 00158 -1 a < b 00159 0 a == b 00160 +1 a > b 00161 Remarks: 00162 A NULL pointer is considered < a non-NULL pointer. 00163 */ 00164 ON_DECL 00165 int ON_UuidCompare( 00166 const ON_UUID* a, 00167 const ON_UUID* b 00168 ); 00169 00170 /* 00171 Description: 00172 ON_UuidCompare(a,b) compares two uuids. 00173 Parameters: 00174 a - [in] 00175 b - [in] 00176 Returns: 00177 @untitled table 00178 -1 a < b 00179 0 a == b 00180 +1 a > b 00181 */ 00182 ON_DECL 00183 int ON_UuidCompare( 00184 const ON_UUID& a, 00185 const ON_UUID& b 00186 ); 00187 00188 /* 00189 Description: 00190 Test uuid to see if it is nil (identically zero). 00191 Parameters: 00192 uuid - [in] 00193 Returns: 00194 true if uuid is nil. 00195 */ 00196 ON_DECL 00197 bool ON_UuidIsNil( 00198 const ON_UUID& uuid 00199 ); 00200 00201 /* 00202 Description: 00203 Test uuid to see if it is not nil (not identically zero). 00204 Parameters: 00205 uuid - [in] 00206 Returns: 00207 true if uuid is not nil (non zero) 00208 */ 00209 ON_DECL 00210 bool ON_UuidIsNotNil( 00211 const ON_UUID& uuid 00212 ); 00213 00214 /* 00215 Description: 00216 Converts a string like 00217 "{85A08515-f383-11d3-BFE7-0010830122F0}" 00218 into a uuid. 00219 The brackets are optional and are ignored. 00220 Hyphens can appear anywhere or be missing. 00221 The hex digits can be upper or lower case. 00222 Parameters: 00223 s - [in] 00224 Returns: 00225 uuid. 00226 If the string is not a uuid, then ON_nil_uuid is returnd. 00227 */ 00228 ON_DECL 00229 ON_UUID ON_UuidFromString( const char* s ); 00230 00231 /* 00232 Description: 00233 Converts a string like 00234 "{85A08515-f383-11d3-BFE7-0010830122F0}" 00235 into a uuid. 00236 The brackets are optional and are ignored. 00237 Hyphens can appear anywhere or be missing. 00238 The hex digits can be upper or lower case. 00239 Parameters: 00240 s - [in] 00241 Returns: 00242 uuid. 00243 If the string is not a uuid, then ON_nil_uuid is returnd. 00244 */ 00245 ON_DECL 00246 ON_UUID ON_UuidFromString( const wchar_t* s ); 00247 00248 /* 00249 Description: 00250 Converts a uuid to a null termintated ASCII string like 00251 "85a08515-f383-11d3-bfe7-0010830122f0". 00252 Parameters: 00253 uuid - [in] 00254 s - [out] The s[] char array must have length >= 37. 00255 The returned char array will have a 36 00256 character uuid in s[0..35] and a null in s[36]. 00257 Returns: 00258 The pointer to the array is returned. 00259 */ 00260 ON_DECL 00261 char* ON_UuidToString( const ON_UUID& uuid, char* s ); 00262 00263 00264 /* 00265 Description: 00266 Converts a uuid to a null termintated UNICODE string like 00267 "85a08515-f383-11d3-bfe7-0010830122f0". 00268 Parameters: 00269 uuid - [in] 00270 s - [out] The s[] wchar_t array must have length >= 37. 00271 The returned char array will have a 36 00272 character uuid in s[0..35] and a null in s[36]. 00273 Returns: 00274 The pointer to the array is returned. 00275 */ 00276 ON_DECL 00277 wchar_t* ON_UuidToString( const ON_UUID& uuid, wchar_t* s ); 00278 00279 class ON_String; 00280 00281 /* 00282 Description: 00283 Converts a uuid to a null termintated string like 00284 "85a08515-f383-11d3-bfe7-0010830122f0". 00285 Parameters: 00286 uuid - [in] 00287 s - [out] 00288 Returns: 00289 The pointer to the array is returned. 00290 */ 00291 ON_DECL 00292 const char* ON_UuidToString( const ON_UUID& uuid, ON_String& s); 00293 00294 class ON_wString; 00295 00296 /* 00297 Description: 00298 Converts a uuid to a null termintated string like 00299 "85a08515-f383-11d3-bfe7-0010830122f0". 00300 Parameters: 00301 uuid - [in] 00302 s - [out] 00303 Returns: 00304 The pointer to the array is returned. 00305 */ 00306 ON_DECL 00307 const wchar_t* ON_UuidToString( const ON_UUID& uuid, ON_wString& s); 00308 00309 #endif 00310 00311 #endif