// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text;
namespace UnrealControls
{
///
/// Represents a location within the text of a document.
///
public struct TextLocation
{
private int mLine;
private int mColumn;
///
/// Gets/Sets the line number.
///
public int Line
{
get { return mLine; }
set { mLine = value; }
}
///
/// Gets/Sets the character column.
///
public int Column
{
get { return mColumn; }
set { mColumn = value; }
}
///
/// Constructor.
///
/// The line number.
/// The character column.
public TextLocation(int Line, int Column)
{
this.mLine = Line;
this.mColumn = Column;
}
///
/// Operator overload for !=.
///
/// Left operand.
/// Right operand.
/// True if the left operand is not equal to the right operand.
public static bool operator !=(TextLocation Left, TextLocation Right)
{
return Left.Line != Right.Line || Left.Column != Right.Column;
}
///
/// Operator overload for ==.
///
/// Left operand.
/// Right operand.
/// True if the left operand is equal to the right operand.
public static bool operator ==(TextLocation Left, TextLocation Right)
{
return Left.Line == Right.Line && Left.Column == Right.Column;
}
///
/// Operator overload for <.
///
/// Left operand.
/// Right operand.
/// True if the left operand is less than the right operand.
public static bool operator <(TextLocation Left, TextLocation Right)
{
if(Left.Line == Right.Line)
{
return Left.Column < Right.Column;
}
return Left.Line < Right.Line;
}
///
/// Operator overload for >.
///
/// Left operand.
/// Right operand.
/// True if the left operand is greater than the right operand.
public static bool operator >(TextLocation Left, TextLocation Right)
{
if(Left.Line == Right.Line)
{
return Left.Column > Right.Column;
}
return Left.Line > Right.Line;
}
///
/// Operator overload for <=.
///
/// Left operand.
/// Right operand.
/// True if the left operand is less than or equal to the right operand.
public static bool operator <=(TextLocation Left, TextLocation Right)
{
if(Left == Right)
{
return true;
}
if(Left.Line == Right.Line)
{
return Left.Column < Right.Column;
}
return Left.Line < Right.Line;
}
///
/// Operator overload for >=.
///
/// Left operand.
/// Right operand.
/// True if the left operand is greater than or equal to the right operand.
public static bool operator >=(TextLocation Left, TextLocation Right)
{
if(Left == Right)
{
return true;
}
if(Left.Line == Right.Line)
{
return Left.Column > Right.Column;
}
return Left.Line > Right.Line;
}
///
/// Checks an object for equality.
///
/// The object to check.
/// True if the object is equal to the one conducting the check.
public override bool Equals(object obj)
{
if(obj is TextLocation)
{
TextLocation Marker = (TextLocation)obj;
return this.mLine == Marker.mLine && this.mColumn == Marker.mColumn;
}
return base.Equals(obj);
}
///
/// Generates a hash code.
///
/// A hash code for the object.
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}