using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Attributes;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Helpers.Structures;
using NvAPIWrapper.Native.Interfaces;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Native.Display.Structures
{
///
/// Holds information about a path
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
// ReSharper disable once RedundantExtendsListEntry
public struct PathInfoV1 : IPathInfo, IInitializable, IAllocatable, IEquatable
{
internal StructureVersion _Version;
internal readonly uint _ReservedSourceId;
internal readonly uint _TargetInfoCount;
internal ValueTypeArray _TargetsInfo;
internal ValueTypeReference _SourceModeInfo;
///
public uint SourceId
{
get => _ReservedSourceId;
}
///
public IEnumerable TargetsInfo
{
get => _TargetsInfo.ToArray((int) _TargetInfoCount)?.Cast() ?? new IPathTargetInfo[0];
}
///
public SourceModeInfo SourceModeInfo
{
get => _SourceModeInfo.ToValueType() ?? default(SourceModeInfo);
}
///
/// Creates a new PathInfoV1
///
/// Information about path targets
/// Source mode information
/// Source Id, can be zero
public PathInfoV1(
PathTargetInfoV1[] targetsInformation,
SourceModeInfo sourceModeInformation,
uint sourceId = 0)
{
this = typeof(PathInfoV1).Instantiate();
_TargetInfoCount = (uint) targetsInformation.Length;
_TargetsInfo = ValueTypeArray.FromArray(targetsInformation);
_SourceModeInfo = ValueTypeReference.FromValueType(sourceModeInformation);
_ReservedSourceId = sourceId;
}
///
public bool Equals(PathInfoV1 other)
{
return _TargetInfoCount == other._TargetInfoCount &&
_TargetsInfo.Equals(other._TargetsInfo) &&
_SourceModeInfo.Equals(other._SourceModeInfo);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is PathInfoV1 && Equals((PathInfoV1) obj);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _TargetInfoCount;
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ _TargetsInfo.GetHashCode();
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ _SourceModeInfo.GetHashCode();
return hashCode;
}
}
///
/// Creates a new PathInfoV1
///
/// Information about path targets
/// Source Id, can be zero
public PathInfoV1(PathTargetInfoV1[] targetsInformation, uint sourceId = 0)
{
this = typeof(PathInfoV1).Instantiate();
_TargetInfoCount = (uint) targetsInformation.Length;
_TargetsInfo = ValueTypeArray.FromArray(targetsInformation);
_SourceModeInfo = ValueTypeReference.Null;
_ReservedSourceId = sourceId;
}
///
/// Creates a new PathInfoV1
///
/// Source Id, can be zero
public PathInfoV1(uint sourceId)
{
this = typeof(PathInfoV1).Instantiate();
_TargetInfoCount = 0;
_TargetsInfo = ValueTypeArray.Null;
_SourceModeInfo = ValueTypeReference.Null;
_ReservedSourceId = sourceId;
}
///
/// Creates a new PathInfoV1
///
/// Source mode information
/// Source Id, can be zero
public PathInfoV1(SourceModeInfo sourceModeInfo, uint sourceId)
{
this = typeof(PathInfoV1).Instantiate();
_TargetInfoCount = 0;
_TargetsInfo = ValueTypeArray.Null;
_SourceModeInfo = ValueTypeReference.FromValueType(sourceModeInfo);
_ReservedSourceId = sourceId;
}
///
public void Dispose()
{
TargetsInfo.DisposeAll();
_TargetsInfo.Dispose();
_SourceModeInfo.Dispose();
}
void IAllocatable.Allocate()
{
if (_TargetInfoCount > 0 && _TargetsInfo.IsNull)
{
var targetInfo = typeof(PathTargetInfoV1).Instantiate();
var targetInfoList = targetInfo.Repeat((int) _TargetInfoCount).AllocateAll();
_TargetsInfo = ValueTypeArray.FromArray(targetInfoList.ToArray());
}
if (_SourceModeInfo.IsNull)
{
var sourceModeInfo = typeof(SourceModeInfo).Instantiate();
_SourceModeInfo = ValueTypeReference.FromValueType(sourceModeInfo);
}
}
}
}