#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see .
*/
#endregion
using System.Collections.Generic;
namespace OpenRa.FileFormats
{
public struct Pair
{
public T First;
public U Second;
public Pair(T first, U second)
{
First = first;
Second = second;
}
static IEqualityComparer tc = EqualityComparer.Default;
static IEqualityComparer uc = EqualityComparer.Default;
public static bool operator ==(Pair a, Pair b)
{
return tc.Equals(a.First, b.First) && uc.Equals(a.Second, b.Second);
}
public static bool operator !=(Pair a, Pair b)
{
return !(a == b);
}
public override bool Equals(object obj)
{
if (!(obj is Pair))
return false;
return (Pair)obj == this;
}
public override int GetHashCode()
{
return First.GetHashCode() ^ Second.GetHashCode();
}
public Pair WithFirst(T t) { return new Pair(t, Second); }
public Pair WithSecond(U u) { return new Pair(First, u); }
public static T AsFirst(Pair p) { return p.First; }
public static U AsSecond(Pair p) { return p.Second; }
public Pair Swap() { return Pair.New(Second, First); }
}
public static class Pair
{
public static Pair New(T t, U u) { return new Pair(t, u); }
}
}