view API/Objects/Requirement/Validation.cs @ 458:680db2462e34

Re #379: * Move GetObjectCountFromArmy(Army, OBJECT_TYPE) to top level and implement * Fix army validation for appropriate "NA" returns * Make basic "Requires..." requirements abstract so that we always need to make specific versions (e.g. UnitRequires... that knows how to check amount of units)
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Feb 2012 20:16:33 +0000
parents 47acc63cf529
children
line wrap: on
line source

// This file (Validation.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
//
// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
using System;

namespace IBBoard.WarFoundry.API.Objects.Requirement
{
	/// <summary>
	/// A custom enum for validation to distinguish between "validation wasn't necessary" and "validation passed".
	/// This should allow for easier handling of failed requirements later being satisfied.
	/// </summary>
	public enum Validation
	{
		Passed = 1,
		Failed = 2,
		NotApplicable = 3
	}

	/// <summary>
	/// A helper class to handle the enums and treat them as booleans where a pass/fail is all that is necessary.
	/// </summary>
	public class Validates
	{
		/// <summary>
		/// Checks if the validation was okay (pass or not applicable)
		/// </summary>
		/// <returns>
		/// <code>true</code> if the validation passed or was not applicable, else <code>false</code>
		/// </returns>
		/// <param name='passed'>
		/// The Validation enum value to check
		/// </param>
		public static bool AsOkay(Validation result)
		{
			return (result & Validation.Passed) == Validation.Passed;
		}

		/// <summary>
		/// Checks if the validation result was not okay (failed or not applicable). Note that this is different
		/// to <code>!Validates.AsOkay(result)</code> because this method treats not applicable as not being okay.
		/// </summary>
		/// <returns>
		/// <code>true</code> if the validation failed or was not applicable, else <code>false</code>
		/// </returns>
		/// <param name='result'>
		/// The Validation enum value to check
		/// </param>
		public static bool AsNotOkay (Validation result)
		{
			return (result & Validation.Failed) == Validation.Failed;
		}
	}
}