diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/OSUUID.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/OpenSim/Framework/OSUUID.cs b/OpenSim/Framework/OSUUID.cs new file mode 100644 index 0000000..8a45290 --- /dev/null +++ b/OpenSim/Framework/OSUUID.cs | |||
@@ -0,0 +1,85 @@ | |||
1 | // OSUUID.cs created with MonoDevelop | ||
2 | // User: sdague at 10:17 AMĀ 4/9/2008 | ||
3 | // | ||
4 | // To change standard headers go to Edit->Preferences->Coding->Standard Headers | ||
5 | // | ||
6 | |||
7 | using System; | ||
8 | using libsecondlife; | ||
9 | |||
10 | namespace OpenSim.Framework | ||
11 | { | ||
12 | [Serializable] | ||
13 | public struct OSUUID: IComparable | ||
14 | { | ||
15 | public Guid UUID; | ||
16 | |||
17 | /* Constructors */ | ||
18 | public OSUUID(string s) | ||
19 | { | ||
20 | if (s == null) | ||
21 | UUID = new Guid(); | ||
22 | else | ||
23 | UUID = new Guid(s); | ||
24 | } | ||
25 | |||
26 | public OSUUID(Guid g) | ||
27 | { | ||
28 | UUID = g; | ||
29 | } | ||
30 | |||
31 | public OSUUID(LLUUID l) | ||
32 | { | ||
33 | UUID = l.UUID; | ||
34 | } | ||
35 | |||
36 | public OSUUID(ulong u) | ||
37 | { | ||
38 | UUID = new Guid(0, 0, 0, BitConverter.GetBytes(u)); | ||
39 | } | ||
40 | |||
41 | // out conversion | ||
42 | public string ToString() | ||
43 | { | ||
44 | return UUID.ToString(); | ||
45 | } | ||
46 | |||
47 | public LLUUID ToLLUUID() | ||
48 | { | ||
49 | return new LLUUID(UUID); | ||
50 | } | ||
51 | |||
52 | // for comparison bits | ||
53 | public override int GetHashCode() | ||
54 | { | ||
55 | return UUID.GetHashCode(); | ||
56 | } | ||
57 | |||
58 | public override bool Equals(object o) | ||
59 | { | ||
60 | if (!(o is LLUUID)) return false; | ||
61 | |||
62 | OSUUID uuid = (OSUUID)o; | ||
63 | return UUID == uuid.UUID; | ||
64 | } | ||
65 | |||
66 | public int CompareTo(object obj) | ||
67 | { | ||
68 | if (obj is OSUUID) | ||
69 | { | ||
70 | OSUUID ID = (OSUUID)obj; | ||
71 | return this.UUID.CompareTo(ID.UUID); | ||
72 | } | ||
73 | |||
74 | throw new ArgumentException("object is not a OSUUID"); | ||
75 | } | ||
76 | |||
77 | // Static methods | ||
78 | public static OSUUID Random() | ||
79 | { | ||
80 | return new OSUUID(Guid.NewGuid()); | ||
81 | } | ||
82 | |||
83 | public static readonly OSUUID Zero = new OSUUID(); | ||
84 | } | ||
85 | } | ||