|
using System;
using System.Collections.Generic;
namespace DigitalSamurai.SpellSharp.InputProcessing
{
public struct DocumentPosition : IComparable<DocumentPosition>, IEquatable<DocumentPosition>
{
#region public int Line { get; }
private int _Line;
public int Line
{
get { return _Line; }
}
#endregion
#region public int Column { get; }
private int _Column;
public int Column
{
get { return _Column; }
}
#endregion
public DocumentPosition (int line, int column)
{
_Line = line;
_Column = column;
}
public override bool Equals (object other)
{
if (other is DocumentPosition)
{
return Equals ((DocumentPosition) other);
}
return false;
}
public override int GetHashCode ()
{
return Line ^ Column;
}
public override string ToString ()
{
return string.Format ("{{ Line : {0}; Column : {1} }}", Line, Column);
}
public static int Compare (DocumentPosition a, DocumentPosition b)
{
int result = Comparer<int>.Default.Compare (a.Line, b.Line);
if (result != 0)
{
return result;
}
return Comparer<int>.Default.Compare (a.Column, b.Column);
}
public int CompareTo (DocumentPosition other)
{
return Compare (this, other);
}
public bool Equals (DocumentPosition other)
{
return Compare (this, other) == 0;
}
public DocumentPosition Increment (int lineIncrement, int columnIncrement)
{
return new DocumentPosition
(
Line + lineIncrement,
Column + columnIncrement
);
}
public static bool operator < (DocumentPosition a, DocumentPosition b)
{
return Compare (a, b) < 0;
}
public static bool operator <= (DocumentPosition a, DocumentPosition b)
{
return Compare (a, b) <= 0;
}
public static bool operator == (DocumentPosition a, DocumentPosition b)
{
return Compare (a, b) == 0;
}
public static bool operator != (DocumentPosition a, DocumentPosition b)
{
return Compare (a, b) != 0;
}
public static bool operator >= (DocumentPosition a, DocumentPosition b)
{
return Compare (a, b) >= 0;
}
public static bool operator > (DocumentPosition a, DocumentPosition b)
{
return Compare (a, b) > 0;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.