// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
namespace SharpGen.Runtime.Win32
{
///
/// A boolean value stored on 4 bytes (instead of 1 in .NET).
///
[StructLayout(LayoutKind.Sequential, Size = 4)]
public struct RawBool : IEquatable
{
private readonly int boolValue;
///
/// Initializes a new instance of the class.
///
/// if set to true [bool value].
public RawBool(bool boolValue)
{
this.boolValue = boolValue ? 1 : 0;
}
///
/// Indicates whether this instance and a specified object are equal.
///
/// The other.
/// true if and this instance are the same type and represent the same value; otherwise, false.
public bool Equals(RawBool other)
{
return this.boolValue == other.boolValue;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
return false;
return obj is RawBool && Equals((RawBool)obj);
}
public override int GetHashCode()
{
return this.boolValue;
}
///
/// Implements the ==.
///
/// The left.
/// The right.
/// The result of the operator.
public static bool operator ==(RawBool left, RawBool right)
{
return left.Equals(right);
}
///
/// Implements the !=.
///
/// The left.
/// The right.
/// The result of the operator.
public static bool operator !=(RawBool left, RawBool right)
{
return !left.Equals(right);
}
///
/// Performs an explicit conversion from to .
///
/// The value.
/// The result of the conversion.
public static implicit operator bool(RawBool booleanValue)
{
return booleanValue.boolValue != 0;
}
///
/// Performs an explicit conversion from to .
///
/// The value.
/// The result of the conversion.
public static implicit operator RawBool(bool boolValue)
{
return new RawBool(boolValue);
}
public override string ToString()
{
return string.Format("{0}", boolValue != 0);
}
}
}