//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

#if !WASM
namespace CommonHelpers {
#else
namespace CommonHelpers.WASM {
#endif

//**************************************************************************************************
/// <summary>
/// </summary>
public static partial class HPlatform {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static int Bitness
{
   get { return IntPtr.Size * 8; }
}

//--------------------------------------------------------------------------------------------------

public static bool Is32BitPlatform
{
   get { return Bitness == 32; }
}

public static bool Is64BitPlatform
{
   get { return Bitness == 64; }
}

public static bool Is128BitPlatform
{
   get { return Bitness == 128; }
}

//--------------------------------------------------------------------------------------------------

#if WIN32
/// <exception cref="HOperationFailedException" />
public static ProcessorArchitecture ProcessorArchitecture
{
   get
   {
      return GetProcessorArchitecture( false );
   }
}
#endif // WIN32

//==================================================================================================

public static NotSupportedException CreateNotSupportedOperationException()
{
   return new NotSupportedException(
      "Operation is not supported on this platform." );
}

//==================================================================================================

static HPlatform()
{
   CommonHelpers_Core.Access();
}

//==================================================================================================

#if WIN32
/// <exception cref="HOperationFailedException" />
[MethodImpl(MethodImplOptions.NoInlining)]
internal static ProcessorArchitecture GetProcessorArchitecture(bool nativeEnvironment)
{
   Win32_Core.SYSTEM_INFO systemInfo;
   if ( nativeEnvironment )
      Win32_Core.GetNativeSystemInfo(out systemInfo);
   else
      Win32_Core.GetSystemInfo(out systemInfo);
   switch ( systemInfo.wProcessorArchitecture )
   {
   case Win32_Core.PROCESSOR_ARCHITECTURE_AMD64: return ProcessorArchitecture.Amd64;
   //case Win32.PROCESSOR_ARCHITECTURE_ARM: return ProcessorArchitecture.Arm;
   case Win32_Core.PROCESSOR_ARCHITECTURE_IA64 : return ProcessorArchitecture.IA64;
   case Win32_Core.PROCESSOR_ARCHITECTURE_INTEL: return ProcessorArchitecture.X86;
   }
   throw HOpFailedExceptionCreator.Create(
      "Unknown processor architecture ({0}).",
      nativeEnvironment ? "native environment" : "process environment" );
}
#endif // WIN32

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HPlatform
//**************************************************************************************************

} // CommonHelpers (.WASM)
