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

namespace CommonHelpers {

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

public static readonly IntPtr
   NullValue = IntPtr.Zero,
   AllBitsValue = (IntPtr)(-1);

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

public static bool IsNull(IntPtr value)
{
   return value == NullValue;
}

public static bool IsAllBitsValue(IntPtr value)
{
   return value == AllBitsValue;
}

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

public static IntPtr Exchange([HVolatileAccess] ref IntPtr operand,IntPtr value)
{
   return HIntPtr.Exchange(ref operand,value);
}

public static IntPtr NullValueExchange([HVolatileAccess] ref IntPtr operand)
{
   return Exchange(ref operand,NullValue);
}

public static IntPtr AllBitsValueExchange([HVolatileAccess] ref IntPtr operand)
{
   return Exchange(ref operand,AllBitsValue);
}

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

public static void Swap( [HVolatileAccess] ref IntPtr operand_1,
                         [HVolatileAccess] ref IntPtr operand_2 )
{
   HIntPtr.Swap(ref operand_1,ref operand_2);
}

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

public static IntPtr IsNullSubstitution(IntPtr value,IntPtr subst)
{
   return XValueSubstitution(value,NullValue,subst);
}

public static IntPtr SubstiteNullValue([HInterlockedAccess] ref IntPtr operand,IntPtr subst)
{
   return SubstituteXValue(ref operand,NullValue,subst);
} 

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

public static IntPtr AllBitsValueSubstitution(IntPtr value,IntPtr subst)
{
   return XValueSubstitution(value,AllBitsValue,subst);
}

public static IntPtr SubstiteAllBitsValue([HInterlockedAccess] ref IntPtr operand,IntPtr subst)
{
   return SubstituteXValue(ref operand,AllBitsValue,subst);
} 

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

public static IntPtr XValueSubstitution(IntPtr value,IntPtr xValue,IntPtr subst)
{
   return HIntPtr.XValueSubstitution(value,xValue,subst);
}

public static IntPtr SubstituteXValue( [HInterlockedAccess] ref IntPtr operand,
                                       IntPtr xValue, IntPtr subst )
{
   return HIntPtr.SubstituteXValue(ref operand,xValue,subst);
}

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

static HPointer()
{
   CommonHelpers_PAccess.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HPointer
//**************************************************************************************************

} // CommonHelpers
