Point Cloud Library (PCL)  1.9.1-dev
opennurbs_uuid.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_UUID_INC_)
18 #define OPENNURBS_UUID_INC_
19 
20 // ON_UUID is a 16 byte universally unique identifier
21 #if defined(UUID_DEFINED)
22 typedef UUID ON_UUID;
23 #elif defined(GUID_DEFINED)
24 typedef GUID ON_UUID;
25 #else
26 
27 #define ON_UUID_DECLARED_AS_CLASS
28 // For uuids, it is critical that the DataN fields have
29 // exactly the sizes specified below. For that reason,
30 // the ON__UINTnn typedefs are used.
31 class ON_CLASS ON_UUID
32 {
33 public:
34  ON__UINT32 Data1; // 32 bit unsigned integer
35  ON__UINT16 Data2; // 16 bit unsigned integer
36  ON__UINT16 Data3; // 16 bit unsigned integer
37  unsigned char Data4[8];
38 
39  bool operator==(const ON_UUID& other) const;
40  bool operator!=(const ON_UUID& other) const;
41 };
42 
43 #endif
44 
45 ON_BEGIN_EXTERNC
46 
47 // All bits are zero in ON_nil_uuid and
48 // ON_UuidCompare( ON_nil_uuid, U ) < 0 if U != ON_nil_uuid.
49 extern ON_EXTERN_DECL const ON_UUID ON_nil_uuid;
50 
51 // All bits are one in ON_max_uuid and
52 // ON_UuidCompare( U, ON_max_uuid ) < 0 if U != ON_max_uuid.
53 extern ON_EXTERN_DECL const ON_UUID ON_max_uuid;
54 
55 // Application ids for the versions of Rhino that
56 // write 3dm files. All userdata classed defined
57 // in the core Rhino.exe should use these ids
58 // as the application id.
59 // In situations where you want to use the id
60 // for the current version of Rhino, use
61 // ON_rhino_id and you won't have to update
62 // your code when Rhino versions roll.
63 extern ON_EXTERN_DECL const ON_UUID ON_rhino2_id;
64 extern ON_EXTERN_DECL const ON_UUID ON_rhino3_id;
65 extern ON_EXTERN_DECL const ON_UUID ON_rhino4_id;
66 extern ON_EXTERN_DECL const ON_UUID ON_rhino5_id;
67 extern ON_EXTERN_DECL const ON_UUID ON_rhino_id;
68 
69 // Application ids for usedata written by versions
70 // of opennurbs before userdata had application ids.
71 extern ON_EXTERN_DECL const ON_UUID ON_v2_userdata_id;
72 extern ON_EXTERN_DECL const ON_UUID ON_v3_userdata_id;
73 extern ON_EXTERN_DECL const ON_UUID ON_v4_userdata_id;
74 
75 // Application id for the versions of openNURBS that
76 // write userdata in 3dm files. User data whose class
77 // definition is in opennurbs should use these
78 // ids as the user data application id.
79 // No other user data should use these ids.
80 // The "extern ON_EXTERN_DECL" prefix on the declarations
81 // of these ids was a mistake that will be corrected when
82 // the public SDK can be changed.
83 // In situations where you want to use the id
84 // for the current version of opennurbs, use
85 // ON_opennurbs_id and you won't have to update
86 // your code when opennurbs versions roll.
87 extern ON_EXTERN_DECL const ON_UUID ON_opennurbs4_id;
88 extern ON_EXTERN_DECL const ON_UUID ON_opennurbs5_id;
89 extern ON_EXTERN_DECL const ON_UUID ON_opennurbs_id;
90 
91 ON_END_EXTERNC
92 
93 #if defined(ON_CPLUSPLUS)
94 
95 /*
96 Description:
97  Creates a new uuid.(&a,&b) compares two uuids.
98 Parameters:
99  new_uuid - [out]
100 Returns:
101  True if successful.
102 Remarks:
103  Only works on Windows.
104 */
105 ON_DECL
106 bool ON_CreateUuid( ON_UUID& uuid );
107 
108 /*
109 Description:
110  This class is used by ON_UuidIndexList. It is used when
111  uuids are used to search for items that can be found by
112  an integer index.
113 */
114 class ON_CLASS ON_UuidIndex
115 {
116 public:
117  ON_UuidIndex();
118 
119  /*
120  Dictionary compare m_id and then m_i.
121  */
122  static
123  int CompareIdAndIndex( const ON_UuidIndex* a, const ON_UuidIndex* b );
124 
125  /*
126  Dictionary compare m_id and then m_i.
127  */
128  static
129  int CompareIndexAndId( const ON_UuidIndex* a, const ON_UuidIndex* b );
130 
131  /*
132  Compare m_id and ignore m_i.
133  */
134  static
135  int CompareId( const ON_UuidIndex* a, const ON_UuidIndex* b );
136 
137  /*
138  Compare m_i and ignore m_id.
139  */
140  static
141  int CompareIndex( const ON_UuidIndex* a, const ON_UuidIndex* b );
142 
143  // In cases when there is a discrepancy between the m_id and
144  // m_i, m_id is assumed to be valid unless comments where this
145  // class is used indicate otherwise.
146  ON_UUID m_id;
147  int m_i;
148 };
149 
150 /*
151 Description:
152  ON_UuidCompare(&a,&b) compares two uuids.
153 Parameters:
154  a - [in]
155  b - [in]
156 Returns:
157  @untitled table
158  -1 a < b
159  0 a == b
160  +1 a > b
161 Remarks:
162  A NULL pointer is considered < a non-NULL pointer.
163 */
164 ON_DECL
165 int ON_UuidCompare(
166  const ON_UUID* a,
167  const ON_UUID* b
168  );
169 
170 /*
171 Description:
172  ON_UuidCompare(a,b) compares two uuids.
173 Parameters:
174  a - [in]
175  b - [in]
176 Returns:
177  @untitled table
178  -1 a < b
179  0 a == b
180  +1 a > b
181 */
182 ON_DECL
183 int ON_UuidCompare(
184  const ON_UUID& a,
185  const ON_UUID& b
186  );
187 
188 /*
189 Description:
190  Test uuid to see if it is nil (identically zero).
191 Parameters:
192  uuid - [in]
193 Returns:
194  true if uuid is nil.
195 */
196 ON_DECL
197 bool ON_UuidIsNil(
198  const ON_UUID& uuid
199  );
200 
201 /*
202 Description:
203  Test uuid to see if it is not nil (not identically zero).
204 Parameters:
205  uuid - [in]
206 Returns:
207  true if uuid is not nil (non zero)
208 */
209 ON_DECL
210 bool ON_UuidIsNotNil(
211  const ON_UUID& uuid
212  );
213 
214 /*
215 Description:
216  Converts a string like
217  "{85A08515-f383-11d3-BFE7-0010830122F0}"
218  into a uuid.
219  The brackets are optional and are ignored.
220  Hyphens can appear anywhere or be missing.
221  The hex digits can be upper or lower case.
222 Parameters:
223  s - [in]
224 Returns:
225  uuid.
226  If the string is not a uuid, then ON_nil_uuid is returnd.
227 */
228 ON_DECL
229 ON_UUID ON_UuidFromString( const char* s );
230 
231 /*
232 Description:
233  Converts a string like
234  "{85A08515-f383-11d3-BFE7-0010830122F0}"
235  into a uuid.
236  The brackets are optional and are ignored.
237  Hyphens can appear anywhere or be missing.
238  The hex digits can be upper or lower case.
239 Parameters:
240  s - [in]
241 Returns:
242  uuid.
243  If the string is not a uuid, then ON_nil_uuid is returnd.
244 */
245 ON_DECL
246 ON_UUID ON_UuidFromString( const wchar_t* s );
247 
248 /*
249 Description:
250  Converts a uuid to a null termintated ASCII string like
251  "85a08515-f383-11d3-bfe7-0010830122f0".
252 Parameters:
253  uuid - [in]
254  s - [out] The s[] char array must have length >= 37.
255  The returned char array will have a 36
256  character uuid in s[0..35] and a null in s[36].
257 Returns:
258  The pointer to the array is returned.
259 */
260 ON_DECL
261 char* ON_UuidToString( const ON_UUID& uuid, char* s );
262 
263 
264 /*
265 Description:
266  Converts a uuid to a null termintated UNICODE string like
267  "85a08515-f383-11d3-bfe7-0010830122f0".
268 Parameters:
269  uuid - [in]
270  s - [out] The s[] wchar_t array must have length >= 37.
271  The returned char array will have a 36
272  character uuid in s[0..35] and a null in s[36].
273 Returns:
274  The pointer to the array is returned.
275 */
276 ON_DECL
277 wchar_t* ON_UuidToString( const ON_UUID& uuid, wchar_t* s );
278 
279 class ON_String;
280 
281 /*
282 Description:
283  Converts a uuid to a null termintated string like
284  "85a08515-f383-11d3-bfe7-0010830122f0".
285 Parameters:
286  uuid - [in]
287  s - [out]
288 Returns:
289  The pointer to the array is returned.
290 */
291 ON_DECL
292 const char* ON_UuidToString( const ON_UUID& uuid, ON_String& s);
293 
294 class ON_wString;
295 
296 /*
297 Description:
298  Converts a uuid to a null termintated string like
299  "85a08515-f383-11d3-bfe7-0010830122f0".
300 Parameters:
301  uuid - [in]
302  s - [out]
303 Returns:
304  The pointer to the array is returned.
305 */
306 ON_DECL
307 const wchar_t* ON_UuidToString( const ON_UUID& uuid, ON_wString& s);
308 
309 #endif
310 
311 #endif
ON__UINT32 Data1
ON__UINT16 Data2
ON__UINT16 Data3