// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // using System.Diagnostics; namespace Microsoft.SqlTools.EditorServices { /// /// Provides details about a position in a file buffer. All /// positions are expressed in 1-based positions (i.e. the /// first line and column in the file is position 1,1). /// [DebuggerDisplay("Position = {Line}:{Column}")] public class BufferPosition { #region Properties /// /// Provides an instance that represents a position that has not been set. /// public static readonly BufferPosition None = new BufferPosition(-1, -1); /// /// Gets the line number of the position in the buffer. /// public int Line { get; private set; } /// /// Gets the column number of the position in the buffer. /// public int Column { get; private set; } #endregion #region Constructors /// /// Creates a new instance of the BufferPosition class. /// /// The line number of the position. /// The column number of the position. public BufferPosition(int line, int column) { this.Line = line; this.Column = column; } #endregion #region Public Methods /// /// Compares two instances of the BufferPosition class. /// /// The object to which this instance will be compared. /// True if the positions are equal, false otherwise. public override bool Equals(object obj) { if (!(obj is BufferPosition)) { return false; } BufferPosition other = (BufferPosition)obj; return this.Line == other.Line && this.Column == other.Column; } /// /// Calculates a unique hash code that represents this instance. /// /// A hash code representing this instance. public override int GetHashCode() { return this.Line.GetHashCode() ^ this.Column.GetHashCode(); } /// /// Compares two positions to check if one is greater than the other. /// /// The first position to compare. /// The second position to compare. /// True if positionOne is greater than positionTwo. public static bool operator >(BufferPosition positionOne, BufferPosition positionTwo) { return (positionOne != null && positionTwo == null) || (positionOne.Line > positionTwo.Line) || (positionOne.Line == positionTwo.Line && positionOne.Column > positionTwo.Column); } /// /// Compares two positions to check if one is less than the other. /// /// The first position to compare. /// The second position to compare. /// True if positionOne is less than positionTwo. public static bool operator <(BufferPosition positionOne, BufferPosition positionTwo) { return positionTwo > positionOne; } #endregion } }