aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/OSUUID.cs
blob: 2a69671b2cc3964e6b75f7ce05ae2e5278041839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// OSUUID.cs created with MonoDevelop
// User: sdague at 10:17 AMĀ 4/9/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using libsecondlife;

namespace OpenSim.Framework
{
    [Serializable]
    public class OSUUID: IComparable
    {
        public Guid UUID;
	
        public OSUUID() {}

        /* Constructors */
        public OSUUID(string s)
        {
            if (s == null)
                UUID = new Guid();
            else
                UUID = new Guid(s);
        }

        public OSUUID(Guid g)
        {
            UUID = g;
        }

        public OSUUID(LLUUID l)
        {
            UUID = l.UUID;
        }

        public OSUUID(ulong u)
        {
            UUID = new Guid(0, 0, 0, BitConverter.GetBytes(u));
        }

        // out conversion
        public override string ToString()
        {
            return UUID.ToString();
        }

        public LLUUID ToLLUUID()
        {
            return new LLUUID(UUID);
        }

        // for comparison bits
        public override int GetHashCode()
        {
            return UUID.GetHashCode();
        }

        public override bool Equals(object o)
        {
            if (!(o is LLUUID)) return false;
            
            OSUUID uuid = (OSUUID)o;
            return UUID == uuid.UUID;
        }

        public int CompareTo(object obj)
        {
            if (obj is OSUUID)
            {
                OSUUID ID = (OSUUID)obj;
                return this.UUID.CompareTo(ID.UUID);
            }

            throw new ArgumentException("object is not a OSUUID");
        }

        // Static methods
        public static OSUUID Random()
        {
            return new OSUUID(Guid.NewGuid());
        }

        public static readonly OSUUID Zero = new OSUUID();
    }
}