changeset 339:50cd43bf51b3

Re #27: Unit requirements * Add tri-state enum (passed, failed, not applicable) and helper class
author IBBoard <dev@ibboard.co.uk>
date Sun, 03 Apr 2011 19:40:42 +0000
parents 4497ebce9a57
children 7bd2a7cdbfbd
files API/Objects/Requirement/Validation.cs IBBoard.WarFoundry.API.csproj
diffstat 2 files changed, 56 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/Validation.cs	Sun Apr 03 19:40:42 2011 +0000
     1.3 @@ -0,0 +1,54 @@
     1.4 +// This file (Validation.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     1.5 +//
     1.6 +// 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.
     1.7 +using System;
     1.8 +
     1.9 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.10 +{
    1.11 +	/// <summary>
    1.12 +	/// A custom enum for validation to distinguish between "validation wasn't necessary" and "validation passed".
    1.13 +	/// This should allow for easier handling of failed requirements later being satisfied.
    1.14 +	/// </summary>
    1.15 +	public enum Validation
    1.16 +	{
    1.17 +		Passed = 1,
    1.18 +		Failed = 2,
    1.19 +		NotApplicable = 3
    1.20 +	}
    1.21 +
    1.22 +	/// <summary>
    1.23 +	/// A helper class to handle the enums and treat them as booleans where a pass/fail is all that is necessary.
    1.24 +	/// </summary>
    1.25 +	public class Validates
    1.26 +	{
    1.27 +		/// <summary>
    1.28 +		/// Checks if the validation was okay (pass or not applicable)
    1.29 +		/// </summary>
    1.30 +		/// <returns>
    1.31 +		/// <code>true</code> if the validation passed or was not applicable, else <code>false</code>
    1.32 +		/// </returns>
    1.33 +		/// <param name='passed'>
    1.34 +		/// The Validation enum value to check
    1.35 +		/// </param>
    1.36 +		public static bool AsOkay(Validation result)
    1.37 +		{
    1.38 +			return (result | Validation.Passed) == Validation.Passed;
    1.39 +		}
    1.40 +
    1.41 +		/// <summary>
    1.42 +		/// Checks if the validation result was not okay (failed or not applicable). Note that this is different
    1.43 +		/// to <code>!Validates.AsOkay(result)</code> because this method treats not applicable as not being okay.
    1.44 +		/// </summary>
    1.45 +		/// <returns>
    1.46 +		/// <code>true</code> if the validation failed or was not applicable, else <code>false</code>
    1.47 +		/// </returns>
    1.48 +		/// <param name='result'>
    1.49 +		/// The Validation enum value to check
    1.50 +		/// </param>
    1.51 +		public static bool AsNotOkay (Validation result)
    1.52 +		{
    1.53 +			return (result | Validation.Failed) == Validation.Failed;
    1.54 +		}
    1.55 +	}
    1.56 +}
    1.57 +
     2.1 --- a/IBBoard.WarFoundry.API.csproj	Sun Apr 03 19:03:30 2011 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.csproj	Sun Apr 03 19:40:42 2011 +0000
     2.3 @@ -1,5 +1,5 @@
     2.4  <?xml version="1.0" encoding="utf-8"?>
     2.5 -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
     2.6 +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2.7    <PropertyGroup>
     2.8      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     2.9      <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    2.10 @@ -189,6 +189,7 @@
    2.11      <Compile Include="API\Objects\Requirement\UnitCountRequirementData.cs" />
    2.12      <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirement.cs" />
    2.13      <Compile Include="API\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirement.cs" />
    2.14 +    <Compile Include="API\Objects\Requirement\Validation.cs" />
    2.15    </ItemGroup>
    2.16    <ItemGroup>
    2.17      <Reference Include="System.Xml" />