changeset 49:a177a3750acd

Re #24: Add "limit" objects that can be used for numeric limits * Refactor out common base class * Fix licenses for new files
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Oct 2009 18:40:09 +0000
parents f3bb5b77a7e4
children e98708559618
files IBBoard.csproj Limits/AbstractLimit.cs Limits/NumericSizeConstrainedLimit.cs Limits/SimpleRoundedPercentageLimit.cs
diffstat 4 files changed, 52 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.csproj	Tue Oct 06 18:59:25 2009 +0000
+++ b/IBBoard.csproj	Wed Oct 07 18:40:09 2009 +0000
@@ -130,6 +130,7 @@
     <Compile Include="CustomMath\IBBMath.cs" />
     <Compile Include="Limits\NumericSizeConstrainedLimit.cs" />
     <Compile Include="Limits\SimpleRoundedPercentageLimit.cs" />
+    <Compile Include="Limits\AbstractLimit.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="libs\log4net.dll" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Limits/AbstractLimit.cs	Wed Oct 07 18:40:09 2009 +0000
@@ -0,0 +1,40 @@
+//  This file (AbstractLimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard
+// 
+//  The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
+
+using System;
+
+namespace IBBoard
+{
+	/// <summary>
+	/// The abstract base class for all limits
+	/// </summary>
+	public abstract class AbstractLimit
+	{
+		private double limit;
+
+		public AbstractLimit (double limitNum)
+		{
+			limit = limitNum;
+		}
+		
+		protected double Limit
+		{
+			get
+			{
+				return limit;
+			}
+		}
+		
+		/// <summary>
+		/// Gets the limited number, based on the limit that this <code>Limit</code> represents and the number it is limiting (<code>size</code>).
+		/// </summary>
+		/// <param name="size">
+		/// The number to be limited
+		/// </param>
+		/// <returns>
+		/// the limited number, as defined by the implementation of the limit
+		/// </returns>
+		public abstract int GetLimit(int size);
+	}
+}
--- a/Limits/NumericSizeConstrainedLimit.cs	Tue Oct 06 18:59:25 2009 +0000
+++ b/Limits/NumericSizeConstrainedLimit.cs	Wed Oct 07 18:40:09 2009 +0000
@@ -1,6 +1,6 @@
-// This file (NumericSizeConstrainedLimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard
+//  This file (NumericSizeConstrainedLimit.cs) is a part of the IBBoard project and is copyright 2009 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.
+//  The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
 
 using System;
 
@@ -9,13 +9,10 @@
 	/// <summary>
 	/// A limit of a specified number, or the number it is limited against, whichever is smaller.
 	/// </summary>
-	public class NumericSizeConstrainedLimit
-	{
-		private int limit;
-		
-		public NumericSizeConstrainedLimit (int numericLimit)
+	public class NumericSizeConstrainedLimit : AbstractLimit
+	{		
+		public NumericSizeConstrainedLimit (int numericLimit) : base(numericLimit)
 		{
-			limit = numericLimit;
 		}
 		
 		/// <summary>
@@ -29,7 +26,7 @@
 		/// </returns>
 		public int GetLimit(int size)
 		{
-			return Math.Min(size, limit);
+			return (int)Math.Min(size, Limit);
 		}
 	}
 }
--- a/Limits/SimpleRoundedPercentageLimit.cs	Tue Oct 06 18:59:25 2009 +0000
+++ b/Limits/SimpleRoundedPercentageLimit.cs	Wed Oct 07 18:40:09 2009 +0000
@@ -1,6 +1,6 @@
-// This file (SimpleRoundedPercentageLimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard
+//  This file (SimpleRoundedPercentageLimit.cs) is a part of the IBBoard project and is copyright 2009 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.
+//  The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
 
 using System;
 using IBBoard.CustomMath;
@@ -10,14 +10,12 @@
 	/// <summary>
 	/// A percentage-based limit that always either rounds up or down to the closest integer
 	/// </summary>
-	public class SimpleRoundedPercentageLimit
+	public class SimpleRoundedPercentageLimit : AbstractLimit
 	{
-		private double limit;
 		private bool roundUp;
 		
-		public SimpleRoundedPercentageLimit (double percentageLimit, bool roundFractionUp)
+		public SimpleRoundedPercentageLimit (double percentageLimit, bool roundFractionUp) : base(percentageLimit)
 		{
-			limit = percentageLimit;
 			roundUp = roundFractionUp;
 		}
 		
@@ -32,7 +30,7 @@
 		/// </returns>
 		public int GetLimit(int size)
 		{
-			return (int)IBBMath.Round(size * limit / 100, roundUp);
+			return (int)IBBMath.Round(size * Limit / 100, roundUp);
 		}
 	}
 }