~ubuntu-branches/ubuntu/raring/monodevelop/raring

« back to all changes in this revision

Viewing changes to contrib/Mono.Debugger.Soft/Mono.Debugger.Soft/ArrayMirror.cs

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2011-06-29 06:56:25 UTC
  • mfrom: (1.8.1 upstream) (1.3.11 experimental)
  • Revision ID: james.westby@ubuntu.com-20110629065625-7xx19c4vb95j65pl
Tags: 2.5.92+dfsg-1ubuntu1
* Merge from Debian experimental:
 - Dropped patches & changes to debian/control for Moonlight
   + debian/patches/remove_support_for_moonlight.patch,
   + debian/patches/dont_add_moonlight_to_core_addins.patch,
 - Remaining patches:
   + debian/patches/no_appmenu:

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections;
 
3
using System.Collections.Generic;
 
4
 
 
5
namespace Mono.Debugger.Soft
 
6
{
 
7
        public class ArrayMirror : ObjectMirror, IEnumerable {
 
8
 
 
9
                public int[] lengths;
 
10
                public int[] lower_bounds;
 
11
                public int rank;
 
12
 
 
13
                internal ArrayMirror (VirtualMachine vm, long id) : base (vm, id) {
 
14
                }
 
15
 
 
16
                public int Length {
 
17
                        get {
 
18
                                GetLengths ();
 
19
 
 
20
                                int length = lengths [0];
 
21
 
 
22
                                for (int i = 1; i < Rank; i++) {
 
23
                                        length *= lengths [i];
 
24
                                }
 
25
 
 
26
                                return length;
 
27
                        }
 
28
                }
 
29
 
 
30
                public int Rank {
 
31
                        get {
 
32
                                GetLengths ();
 
33
 
 
34
                                return rank;
 
35
                        }
 
36
                }
 
37
 
 
38
                public int GetLength (int dimension) {
 
39
                        GetLengths ();
 
40
 
 
41
                        if (dimension < 0 || dimension >= Rank)
 
42
                                throw new ArgumentOutOfRangeException ("dimension");
 
43
 
 
44
                        return lengths [dimension];
 
45
                }
 
46
 
 
47
                public int GetLowerBound (int dimension) {
 
48
                        GetLengths ();
 
49
 
 
50
                        if (dimension < 0 || dimension >= Rank)
 
51
                                throw new ArgumentOutOfRangeException ("dimension");
 
52
 
 
53
                        return lower_bounds [dimension];
 
54
                }
 
55
 
 
56
                void GetLengths () {
 
57
                        if (lengths == null)
 
58
                                lengths = vm.conn.Array_GetLength (id, out this.rank, out this.lower_bounds);
 
59
                }
 
60
 
 
61
                public Value this [int index] {
 
62
                        get {
 
63
                                // FIXME: Multiple dimensions
 
64
                                if (index < 0 || index > Length - 1)
 
65
                                        throw new IndexOutOfRangeException ();
 
66
                                return vm.DecodeValue (vm.conn.Array_GetValues (id, index, 1) [0]);
 
67
                        }
 
68
                        set {
 
69
                                // FIXME: Multiple dimensions
 
70
                                if (index < 0 || index > Length - 1)
 
71
                                        throw new IndexOutOfRangeException ();
 
72
                                vm.conn.Array_SetValues (id, index, new ValueImpl [] { vm.EncodeValue (value) });
 
73
                        }
 
74
                }
 
75
 
 
76
                public IList<Value> GetValues (int index, int length) {
 
77
                        // FIXME: Multiple dimensions
 
78
                                if (index < 0 || index > Length - length)
 
79
                                        throw new IndexOutOfRangeException ();
 
80
                        return vm.DecodeValues (vm.conn.Array_GetValues (id, index, length));
 
81
                }
 
82
 
 
83
                public void SetValues (int index, Value[] values) {
 
84
                        if (values == null)
 
85
                                throw new ArgumentNullException ("values");
 
86
                        // FIXME: Multiple dimensions
 
87
                        if (index < 0 || index > Length - values.Length)
 
88
                                throw new IndexOutOfRangeException ();
 
89
                        vm.conn.Array_SetValues (id, index, vm.EncodeValues (values));
 
90
                }
 
91
 
 
92
                IEnumerator IEnumerable.GetEnumerator ()
 
93
                {
 
94
                        return new SimpleEnumerator (this);
 
95
                }
 
96
 
 
97
                internal class SimpleEnumerator : IEnumerator, ICloneable
 
98
                {
 
99
                        ArrayMirror arr;
 
100
                        int pos, length;
 
101
 
 
102
                        public SimpleEnumerator (ArrayMirror arr)
 
103
                        {
 
104
                                this.arr = arr;
 
105
                                this.pos = -1;
 
106
                                this.length = arr.Length;
 
107
                        }
 
108
 
 
109
                        public object Current {
 
110
                                get {
 
111
                                        if (pos < 0 )
 
112
                                                throw new InvalidOperationException ("Enumeration has not started.");
 
113
                                        if  (pos >= length)
 
114
                                                throw new InvalidOperationException ("Enumeration has already ended");
 
115
                                        return arr [pos];
 
116
                                }
 
117
                        }
 
118
 
 
119
                        public bool MoveNext()
 
120
                        {
 
121
                                if (pos < length)
 
122
                                        pos++;
 
123
                                if(pos < length)
 
124
                                        return true;
 
125
                                else
 
126
                                        return false;
 
127
                        }
 
128
 
 
129
                        public void Reset()
 
130
                        {
 
131
                                pos = -1;
 
132
                        }
 
133
 
 
134
                        public object Clone ()
 
135
                        {
 
136
                                return MemberwiseClone ();
 
137
                        }
 
138
                }
 
139
        }
 
140
}