From 8d9d8ac01e84ddf3464cd421fa3b798068652434 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 22 Jan 2014 00:47:22 +0000 Subject: [PATCH] Clean up the Bit struct and rename the file from Types.cs to Bit.cs --- BizHawk.Common/Bit.cs | 88 ++++++++++++++++++++++++++++ BizHawk.Common/BizHawk.Common.csproj | 2 +- BizHawk.Common/Types.cs | 31 ---------- 3 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 BizHawk.Common/Bit.cs delete mode 100644 BizHawk.Common/Types.cs diff --git a/BizHawk.Common/Bit.cs b/BizHawk.Common/Bit.cs new file mode 100644 index 0000000000..7d9ffe3619 --- /dev/null +++ b/BizHawk.Common/Bit.cs @@ -0,0 +1,88 @@ +using System.Diagnostics; + +namespace BizHawk.Common +{ + // I think this is a little faster with uint than with byte + public struct Bit + { + private readonly uint _val; + + public Bit(uint val) + { + _val = val; + } + + public static implicit operator Bit(int rhs) + { + Debug.Assert((rhs & ~1) == 0); + return new Bit((uint)rhs); + } + + public static implicit operator Bit(uint rhs) + { + Debug.Assert((rhs & ~1) == 0); + return new Bit(rhs); + } + + public static implicit operator Bit(byte rhs) + { + Debug.Assert((rhs & ~1) == 0); + return new Bit(rhs); + } + + public static implicit operator Bit(bool rhs) + { + return new Bit(rhs ? (byte)1 : (byte)0); + } + + public static implicit operator long(Bit rhs) + { + return rhs._val; + } + + public static implicit operator int(Bit rhs) + { + return (int)rhs._val; + } + + public static implicit operator uint(Bit rhs) + { + return rhs._val; + } + + public static implicit operator byte(Bit rhs) + { + return (byte)rhs._val; + } + + public static implicit operator bool(Bit rhs) + { + return rhs._val != 0; + } + + public override string ToString() + { + return _val.ToString(); + } + + public static bool operator ==(Bit lhs, Bit rhs) + { + return lhs._val == rhs._val; + } + + public static bool operator !=(Bit lhs, Bit rhs) + { + return lhs._val != rhs._val; + } + + public override int GetHashCode() + { + return _val.GetHashCode(); + } + + public override bool Equals(object obj) + { + return this == (Bit)obj; // this is probably wrong + } + } +} \ No newline at end of file diff --git a/BizHawk.Common/BizHawk.Common.csproj b/BizHawk.Common/BizHawk.Common.csproj index 7d5bcf50a0..848a4819e0 100644 --- a/BizHawk.Common/BizHawk.Common.csproj +++ b/BizHawk.Common/BizHawk.Common.csproj @@ -47,6 +47,7 @@ VersionInfo.cs + @@ -62,7 +63,6 @@ - diff --git a/BizHawk.Common/Types.cs b/BizHawk.Common/Types.cs deleted file mode 100644 index a1a0c7a48d..0000000000 --- a/BizHawk.Common/Types.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Diagnostics; - -namespace BizHawk.Common -{ - //I think this is a little faster with uint than with byte - public struct Bit - { - readonly uint val; - - Bit(uint val) - { - this.val = val; - } - - public static implicit operator Bit(int rhs) { Debug.Assert((rhs & ~1) == 0); return new Bit((uint)(rhs)); } - public static implicit operator Bit(uint rhs) { Debug.Assert((rhs & ~1) == 0); return new Bit((uint)(rhs)); } - public static implicit operator Bit(byte rhs) { Debug.Assert((rhs & ~1) == 0); return new Bit((uint)(rhs)); } - public static implicit operator Bit(bool rhs) { return new Bit(rhs ? (byte)1 : (byte)0); } - public static implicit operator long(Bit rhs) { return (long)rhs.val; } - public static implicit operator int(Bit rhs) { return (int)rhs.val; } - public static implicit operator uint(Bit rhs) { return (uint)rhs.val; } - public static implicit operator byte(Bit rhs) { return (byte)rhs.val; } - public static implicit operator bool(Bit rhs) { return rhs.val != 0; } - public override string ToString() {return val.ToString(); } - public static bool operator ==(Bit lhs, Bit rhs) { return lhs.val == rhs.val; } - public static bool operator !=(Bit lhs, Bit rhs) { return lhs.val != rhs.val; } - public override int GetHashCode() { return val.GetHashCode(); } - public override bool Equals(object obj) { return this == (Bit)obj; } //this is probably wrong - } - -} \ No newline at end of file