using System;
using System.Linq;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Native.Mosaic;
namespace NvAPIWrapper.Mosaic
{
///
/// Holds extra information about a topology
///
public class TopologyDetails : IEquatable
{
internal TopologyDetails(Native.Mosaic.Structures.TopologyDetails details)
{
Rows = details.Rows;
Columns = details.Columns;
LogicalGPU = !details.LogicalGPUHandle.IsNull ? new LogicalGPU(details.LogicalGPUHandle) : null;
ValidityFlags = details.ValidityFlags;
Displays =
details.Layout.Select(cells => cells.Select(cell => new TopologyDisplay(cell)).ToArray()).ToArray();
}
///
/// Gets the number of columns in the topology
///
public int Columns { get; }
///
/// Gets the list of topology displays
///
public TopologyDisplay[][] Displays { get; }
///
/// Gets the logical GPU in charge of controling the topology
///
public LogicalGPU LogicalGPU { get; }
///
/// Gets the number of rows in the topology
///
public int Rows { get; }
///
/// Gets the validity status of this topology
///
public TopologyValidity ValidityFlags { get; }
///
public bool Equals(TopologyDetails other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Rows == other.Rows &&
Columns == other.Columns &&
LogicalGPU.Equals(other.LogicalGPU) &&
Displays.SequenceEqual(other.Displays);
}
///
/// Checks for equality between two objects of same type
///
/// The first object
/// The second object
/// true, if both objects are equal, otherwise false
public static bool operator ==(TopologyDetails left, TopologyDetails right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
///
/// Checks for inequality between two objects of same type
///
/// The first object
/// The second object
/// true, if both objects are not equal, otherwise false
public static bool operator !=(TopologyDetails left, TopologyDetails right)
{
return !(left == right);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((TopologyDetails) obj);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = Rows;
hashCode = (hashCode * 397) ^ Columns;
hashCode = (hashCode * 397) ^ (LogicalGPU != null ? LogicalGPU.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Displays?.GetHashCode() ?? 0);
return hashCode;
}
}
}
}