diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmath/lluuid.h | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2 meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz |
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llmath/lluuid.h')
-rw-r--r-- | linden/indra/llmath/lluuid.h | 330 |
1 files changed, 0 insertions, 330 deletions
diff --git a/linden/indra/llmath/lluuid.h b/linden/indra/llmath/lluuid.h deleted file mode 100644 index 48308f2..0000000 --- a/linden/indra/llmath/lluuid.h +++ /dev/null | |||
@@ -1,330 +0,0 @@ | |||
1 | /** | ||
2 | * @file lluuid.h | ||
3 | * | ||
4 | * $LicenseInfo:firstyear=2000&license=viewergpl$ | ||
5 | * | ||
6 | * Copyright (c) 2000-2008, Linden Research, Inc. | ||
7 | * | ||
8 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | * $/LicenseInfo$ | ||
29 | */ | ||
30 | |||
31 | #ifndef LL_LLUUID_H | ||
32 | #define LL_LLUUID_H | ||
33 | |||
34 | #include <iostream> | ||
35 | #include <set> | ||
36 | #include "stdtypes.h" | ||
37 | |||
38 | const S32 UUID_BYTES = 16; | ||
39 | const S32 UUID_WORDS = 4; | ||
40 | const S32 UUID_STR_LENGTH = 37; // actually wrong, should be 36 and use size below | ||
41 | const S32 UUID_STR_SIZE = 37; | ||
42 | const S32 UUID_BASE85_LENGTH = 21; // including the trailing NULL. | ||
43 | |||
44 | struct uuid_time_t { | ||
45 | U32 high; | ||
46 | U32 low; | ||
47 | }; | ||
48 | |||
49 | class LLUUID | ||
50 | { | ||
51 | public: | ||
52 | // | ||
53 | // CREATORS | ||
54 | // | ||
55 | LLUUID(); | ||
56 | explicit LLUUID(const char *in_string); // Convert from string. | ||
57 | explicit LLUUID(const std::string& in_string); // Convert from string. | ||
58 | LLUUID(const LLUUID &in); | ||
59 | LLUUID &operator=(const LLUUID &rhs); | ||
60 | |||
61 | ~LLUUID(); | ||
62 | |||
63 | // | ||
64 | // MANIPULATORS | ||
65 | // | ||
66 | void generate(); // Generate a new UUID | ||
67 | void generate(std::string stream); //Generate a new UUID based on hash of input stream | ||
68 | BOOL set(const char *in_string, BOOL emit = TRUE); // Convert from string, if emit is FALSE, do not emit warnings | ||
69 | BOOL set(const std::string& in_string, BOOL emit = TRUE); // Convert from string, if emit is FALSE, do not emit warnings | ||
70 | void setNull(); // Faster than setting to LLUUID::null. | ||
71 | |||
72 | S32 cmpTime(uuid_time_t *t1, uuid_time_t *t2); | ||
73 | static void getSystemTime(uuid_time_t *timestamp); | ||
74 | void getCurrentTime(uuid_time_t *timestamp); | ||
75 | |||
76 | // | ||
77 | // ACCESSORS | ||
78 | // | ||
79 | BOOL isNull() const; // Faster than comparing to LLUUID::null. | ||
80 | BOOL notNull() const; // Faster than comparing to LLUUID::null. | ||
81 | // JC: This is dangerous. It allows UUIDs to be cast automatically | ||
82 | // to integers, among other things. Use isNull() or notNull(). | ||
83 | // operator bool() const; | ||
84 | |||
85 | // JC: These must return real bool's (not BOOLs) or else use of the STL | ||
86 | // will generate bool-to-int performance warnings. | ||
87 | bool operator==(const LLUUID &rhs) const; | ||
88 | bool operator!=(const LLUUID &rhs) const; | ||
89 | bool operator<(const LLUUID &rhs) const; | ||
90 | bool operator>(const LLUUID &rhs) const; | ||
91 | |||
92 | // xor functions. Useful since any two random uuids xored together | ||
93 | // will yield a determinate third random unique id that can be | ||
94 | // used as a key in a single uuid that represents 2. | ||
95 | const LLUUID& operator^=(const LLUUID& rhs); | ||
96 | LLUUID operator^(const LLUUID& rhs) const; | ||
97 | |||
98 | // similar to functions above, but not invertible | ||
99 | // yields a third random UUID that can be reproduced from the two inputs | ||
100 | // but which, given the result and one of the inputs can't be used to | ||
101 | // deduce the other input | ||
102 | LLUUID combine(const LLUUID& other) const; | ||
103 | void combine(const LLUUID& other, LLUUID& result) const; | ||
104 | |||
105 | friend std::ostream& operator<<(std::ostream& s, const LLUUID &uuid); | ||
106 | friend std::istream& operator>>(std::istream& s, LLUUID &uuid); | ||
107 | |||
108 | void toString(char *out) const; // Does not allocate memory, needs 36 characters (including \0) | ||
109 | void toCompressedString(char *out) const; // Does not allocate memory, needs 17 characters (including \0) | ||
110 | |||
111 | std::string asString() const; | ||
112 | std::string getString() const; | ||
113 | |||
114 | U16 getCRC16() const; | ||
115 | U32 getCRC32() const; | ||
116 | |||
117 | static BOOL validate(const std::string& in_string); // Validate that the UUID string is legal. | ||
118 | static BOOL validate(const char *in_string); // Validate that the UUID string is legal. | ||
119 | |||
120 | static const LLUUID null; | ||
121 | |||
122 | static U32 getRandomSeed(); | ||
123 | static S32 getNodeID(unsigned char * node_id); | ||
124 | |||
125 | static BOOL parseUUID(const char* buf, LLUUID* value); | ||
126 | |||
127 | U8 mData[UUID_BYTES]; | ||
128 | }; | ||
129 | |||
130 | |||
131 | // Construct | ||
132 | inline LLUUID::LLUUID() | ||
133 | { | ||
134 | setNull(); | ||
135 | } | ||
136 | |||
137 | |||
138 | // Faster than copying from memory | ||
139 | inline void LLUUID::setNull() | ||
140 | { | ||
141 | U32 *word = (U32 *)mData; | ||
142 | word[0] = 0; | ||
143 | word[1] = 0; | ||
144 | word[2] = 0; | ||
145 | word[3] = 0; | ||
146 | } | ||
147 | |||
148 | |||
149 | // Compare | ||
150 | inline bool LLUUID::operator==(const LLUUID& rhs) const | ||
151 | { | ||
152 | U32 *tmp = (U32 *)mData; | ||
153 | U32 *rhstmp = (U32 *)rhs.mData; | ||
154 | // Note: binary & to avoid branching | ||
155 | return | ||
156 | (tmp[0] == rhstmp[0]) & | ||
157 | (tmp[1] == rhstmp[1]) & | ||
158 | (tmp[2] == rhstmp[2]) & | ||
159 | (tmp[3] == rhstmp[3]); | ||
160 | } | ||
161 | |||
162 | |||
163 | inline bool LLUUID::operator!=(const LLUUID& rhs) const | ||
164 | { | ||
165 | U32 *tmp = (U32 *)mData; | ||
166 | U32 *rhstmp = (U32 *)rhs.mData; | ||
167 | // Note: binary | to avoid branching | ||
168 | return | ||
169 | (tmp[0] != rhstmp[0]) | | ||
170 | (tmp[1] != rhstmp[1]) | | ||
171 | (tmp[2] != rhstmp[2]) | | ||
172 | (tmp[3] != rhstmp[3]); | ||
173 | } | ||
174 | |||
175 | /* | ||
176 | // JC: This is dangerous. It allows UUIDs to be cast automatically | ||
177 | // to integers, among other things. Use isNull() or notNull(). | ||
178 | inline LLUUID::operator bool() const | ||
179 | { | ||
180 | U32 *word = (U32 *)mData; | ||
181 | return (word[0] | word[1] | word[2] | word[3]) > 0; | ||
182 | } | ||
183 | */ | ||
184 | |||
185 | inline BOOL LLUUID::notNull() const | ||
186 | { | ||
187 | U32 *word = (U32 *)mData; | ||
188 | return (word[0] | word[1] | word[2] | word[3]) > 0; | ||
189 | } | ||
190 | |||
191 | // Faster than == LLUUID::null because doesn't require | ||
192 | // as much memory access. | ||
193 | inline BOOL LLUUID::isNull() const | ||
194 | { | ||
195 | U32 *word = (U32 *)mData; | ||
196 | // If all bits are zero, return !0 == TRUE | ||
197 | return !(word[0] | word[1] | word[2] | word[3]); | ||
198 | } | ||
199 | |||
200 | // Copy constructor | ||
201 | inline LLUUID::LLUUID(const LLUUID& rhs) | ||
202 | { | ||
203 | U32 *tmp = (U32 *)mData; | ||
204 | U32 *rhstmp = (U32 *)rhs.mData; | ||
205 | tmp[0] = rhstmp[0]; | ||
206 | tmp[1] = rhstmp[1]; | ||
207 | tmp[2] = rhstmp[2]; | ||
208 | tmp[3] = rhstmp[3]; | ||
209 | } | ||
210 | |||
211 | inline LLUUID::~LLUUID() | ||
212 | { | ||
213 | } | ||
214 | |||
215 | // Assignment | ||
216 | inline LLUUID& LLUUID::operator=(const LLUUID& rhs) | ||
217 | { | ||
218 | // No need to check the case where this==&rhs. The branch is slower than the write. | ||
219 | U32 *tmp = (U32 *)mData; | ||
220 | U32 *rhstmp = (U32 *)rhs.mData; | ||
221 | tmp[0] = rhstmp[0]; | ||
222 | tmp[1] = rhstmp[1]; | ||
223 | tmp[2] = rhstmp[2]; | ||
224 | tmp[3] = rhstmp[3]; | ||
225 | |||
226 | return *this; | ||
227 | } | ||
228 | |||
229 | |||
230 | inline LLUUID::LLUUID(const char *in_string) | ||
231 | { | ||
232 | if (!in_string || in_string[0] == 0) | ||
233 | { | ||
234 | setNull(); | ||
235 | return; | ||
236 | } | ||
237 | |||
238 | set(in_string); | ||
239 | } | ||
240 | |||
241 | inline LLUUID::LLUUID(const std::string& in_string) | ||
242 | { | ||
243 | if (in_string.empty()) | ||
244 | { | ||
245 | setNull(); | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | set(in_string); | ||
250 | } | ||
251 | |||
252 | // IW: DON'T "optimize" these w/ U32s or you'll scoogie the sort order | ||
253 | // IW: this will make me very sad | ||
254 | inline bool LLUUID::operator<(const LLUUID &rhs) const | ||
255 | { | ||
256 | U32 i; | ||
257 | for( i = 0; i < (UUID_BYTES - 1); i++ ) | ||
258 | { | ||
259 | if( mData[i] != rhs.mData[i] ) | ||
260 | { | ||
261 | return (mData[i] < rhs.mData[i]); | ||
262 | } | ||
263 | } | ||
264 | return (mData[UUID_BYTES - 1] < rhs.mData[UUID_BYTES - 1]); | ||
265 | } | ||
266 | |||
267 | inline bool LLUUID::operator>(const LLUUID &rhs) const | ||
268 | { | ||
269 | U32 i; | ||
270 | for( i = 0; i < (UUID_BYTES - 1); i++ ) | ||
271 | { | ||
272 | if( mData[i] != rhs.mData[i] ) | ||
273 | { | ||
274 | return (mData[i] > rhs.mData[i]); | ||
275 | } | ||
276 | } | ||
277 | return (mData[UUID_BYTES - 1] > rhs.mData[UUID_BYTES - 1]); | ||
278 | } | ||
279 | |||
280 | inline U16 LLUUID::getCRC16() const | ||
281 | { | ||
282 | // A UUID is 16 bytes, or 8 shorts. | ||
283 | U16 *short_data = (U16*)mData; | ||
284 | U16 out = 0; | ||
285 | out += short_data[0]; | ||
286 | out += short_data[1]; | ||
287 | out += short_data[2]; | ||
288 | out += short_data[3]; | ||
289 | out += short_data[4]; | ||
290 | out += short_data[5]; | ||
291 | out += short_data[6]; | ||
292 | out += short_data[7]; | ||
293 | return out; | ||
294 | } | ||
295 | |||
296 | inline U32 LLUUID::getCRC32() const | ||
297 | { | ||
298 | U32 *tmp = (U32*)mData; | ||
299 | return tmp[0] + tmp[1] + tmp[2] + tmp[3]; | ||
300 | } | ||
301 | |||
302 | |||
303 | // Helper structure for ordering lluuids in stl containers. | ||
304 | // eg: std::map<LLUUID, LLWidget*, lluuid_less> widget_map; | ||
305 | struct lluuid_less | ||
306 | { | ||
307 | bool operator()(const LLUUID& lhs, const LLUUID& rhs) const | ||
308 | { | ||
309 | return (lhs < rhs) ? true : false; | ||
310 | } | ||
311 | }; | ||
312 | |||
313 | typedef std::set<LLUUID, lluuid_less> uuid_list_t; | ||
314 | |||
315 | /* | ||
316 | * Sub-classes for keeping transaction IDs and asset IDs | ||
317 | * straight. | ||
318 | */ | ||
319 | typedef LLUUID LLAssetID; | ||
320 | |||
321 | class LLTransactionID : public LLUUID | ||
322 | { | ||
323 | public: | ||
324 | LLTransactionID() : LLUUID() { } | ||
325 | |||
326 | static const LLTransactionID tnull; | ||
327 | LLAssetID makeAssetID(const LLUUID& session) const; | ||
328 | }; | ||
329 | |||
330 | #endif | ||