Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2787 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
9 changed files with 222 additions and 58 deletions
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
|
||||
// <version>$Revision: 2786 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace Debugger |
||||
{ |
||||
/// <summary>
|
||||
/// Specifies the range of valid indicies for an array dimension
|
||||
/// </summary>
|
||||
public class ArrayDimension |
||||
{ |
||||
int lowerBound; |
||||
int upperBound; |
||||
|
||||
/// <summary> The smallest valid index in this dimension </summary>
|
||||
public int LowerBound { |
||||
get { return lowerBound; } |
||||
} |
||||
|
||||
/// <summary> The largest valid index in this dimension.
|
||||
/// Returns LowerBound - 1 if the array is empty. </summary>
|
||||
public int UpperBound { |
||||
get { return upperBound; } |
||||
} |
||||
|
||||
/// <summary> The number of valid indicies of this dimension </summary>
|
||||
public int Count { |
||||
get { return upperBound - lowerBound + 1; } |
||||
} |
||||
|
||||
/// <summary> Determines whether the given index is a valid index for this dimension </summary>
|
||||
public bool IsIndexValid(int index) |
||||
{ |
||||
return (this.LowerBound <= index && index <= this.UpperBound); |
||||
} |
||||
|
||||
public ArrayDimension(int lowerBound, int upperBound) |
||||
{ |
||||
this.lowerBound = lowerBound; |
||||
this.upperBound = upperBound; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
if (this.LowerBound == 0) { |
||||
return this.Count.ToString(); |
||||
} else { |
||||
return this.LowerBound + ".." + this.UpperBound; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,101 @@
@@ -0,0 +1,101 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
|
||||
// <version>$Revision: 2786 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Debugger |
||||
{ |
||||
/// <summary>
|
||||
/// Specifies the range of valid indicies for all array dimensions
|
||||
/// </summary>
|
||||
public class ArrayDimensions: IEnumerable<ArrayDimension> |
||||
{ |
||||
List<ArrayDimension> dimensions = new List<ArrayDimension>(); |
||||
|
||||
public IEnumerator<ArrayDimension> GetEnumerator() |
||||
{ |
||||
return dimensions.GetEnumerator(); |
||||
} |
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() |
||||
{ |
||||
return ((IEnumerable)dimensions).GetEnumerator(); |
||||
} |
||||
|
||||
/// <summary> Gets a given dimension </summary>
|
||||
public ArrayDimension this[int index] { |
||||
get { |
||||
return dimensions[index]; |
||||
} |
||||
} |
||||
|
||||
/// <summary> Get the number of dimensions of the array </summary>
|
||||
public int Count { |
||||
get { |
||||
return dimensions.Count; |
||||
} |
||||
} |
||||
|
||||
/// <summary> Enumerate all vaild indicies in the array </summary>
|
||||
public IEnumerable<int[]> Indices { |
||||
get { |
||||
foreach(ArrayDimension dim in this) { |
||||
if (dim.Count == 0) yield break; |
||||
} |
||||
|
||||
int rank = this.Count; |
||||
int[] indices = new int[rank]; |
||||
for(int i = 0; i < rank; i++) { |
||||
indices[i] = this[i].LowerBound; |
||||
} |
||||
|
||||
while(true) { // Go thought all combinations
|
||||
for (int i = rank - 1; i >= 1; i--) { |
||||
if (indices[i] > this[i].UpperBound) { |
||||
indices[i] = this[i].LowerBound; |
||||
indices[i - 1]++; |
||||
} |
||||
} |
||||
if (indices[0] > this[0].UpperBound) yield break; // We are done
|
||||
|
||||
yield return (int[])indices.Clone(); |
||||
|
||||
indices[rank - 1]++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary> Determines whether the given index is a valid index for the array </summary>
|
||||
public bool IsIndexValid(int[] indices) |
||||
{ |
||||
for (int i = 0; i < this.Count; i++) { |
||||
if (!this[i].IsIndexValid(indices[i])) return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public ArrayDimensions(List<ArrayDimension> dimensions) |
||||
{ |
||||
this.dimensions = dimensions; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
string result = "["; |
||||
bool isFirst = true; |
||||
foreach(ArrayDimension dim in this) { |
||||
if (!isFirst) result += ", "; |
||||
result += dim.ToString(); |
||||
isFirst = false; |
||||
} |
||||
result += "]"; |
||||
return result; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue