~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Mono.Cecil/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:
5
5
//   Jb Evain (jbevain@gmail.com)
6
6
//
7
 
// (C) 2005 Jb Evain
 
7
// Copyright (c) 2008 - 2010 Jb Evain
8
8
//
9
9
// Permission is hereby granted, free of charge, to any person obtaining
10
10
// a copy of this software and associated documentation files (the
26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
27
//
28
28
 
 
29
using System;
 
30
 
 
31
using Mono.Cecil.PE;
 
32
 
29
33
namespace Mono.Cecil.Metadata {
30
34
 
31
 
        using System;
32
 
        using System.Collections;
33
 
 
34
 
        public class GuidHeap : MetadataHeap {
35
 
 
36
 
                readonly IDictionary m_guids;
37
 
 
38
 
                public IDictionary Guids {
39
 
                        get { return m_guids; }
40
 
                }
41
 
 
42
 
                public GuidHeap (MetadataStream stream) : base (stream, MetadataStream.GUID)
43
 
                {
44
 
                        int capacity = (int)(stream.Header.Size / 16);
45
 
                        m_guids = new Hashtable (capacity);
46
 
                }
47
 
 
48
 
                public Guid this [uint index] {
49
 
                        get {
50
 
                                if (index == 0)
51
 
                                        return new Guid (new byte [16]);
52
 
 
53
 
                                int idx = (int) index - 1;
54
 
 
55
 
                                if (m_guids.Contains (idx))
56
 
                                        return (Guid) m_guids [idx];
57
 
 
58
 
                                if (idx + 16 > this.Data.Length)
59
 
                                        throw new IndexOutOfRangeException ();
60
 
 
61
 
                                byte [] buffer = null;
62
 
                                if (this.Data.Length == 16) {
63
 
                                        buffer = this.Data;
64
 
                                } else {
65
 
                                        buffer = new byte [16];
66
 
                                        Buffer.BlockCopy (this.Data, idx, buffer, 0, 16);
67
 
                                }
68
 
                                Guid res = new Guid (buffer);
69
 
                                m_guids [idx] = res;
70
 
                                return res;
71
 
                        }
72
 
                        set { m_guids [index] = value; }
73
 
                }
74
 
 
75
 
                public override void Accept (IMetadataVisitor visitor)
76
 
                {
77
 
                        visitor.VisitGuidHeap (this);
 
35
        sealed class GuidHeap : Heap {
 
36
 
 
37
                public GuidHeap (Section section, uint start, uint size)
 
38
                        : base (section, start, size)
 
39
                {
 
40
                }
 
41
 
 
42
                public Guid Read (uint index)
 
43
                {
 
44
                        if (index == 0)
 
45
                                return new Guid ();
 
46
 
 
47
                        const int guid_size = 16;
 
48
 
 
49
                        var buffer = new byte [guid_size];
 
50
 
 
51
                        index--;
 
52
 
 
53
                        Buffer.BlockCopy (Section.Data, (int) (Offset + index), buffer, 0, guid_size);
 
54
 
 
55
                        return new Guid (buffer);
 
56
 
78
57
                }
79
58
        }
80
59
}