changeset 47:966ba575d4e6

Re #24: Add "limit" objects that can be used for numeric limits * Add initial "Numeric" limit that won't go beyond the size it is given
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Oct 2009 18:49:04 +0000
parents 298b2ff956bb
children f3bb5b77a7e4
files IBBoard.csproj Limits/NumericSizeConstrainedLimit.cs
diffstat 2 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.csproj	Tue Oct 06 18:31:14 2009 +0000
+++ b/IBBoard.csproj	Tue Oct 06 18:49:04 2009 +0000
@@ -128,6 +128,7 @@
     <Compile Include="IO\BinaryReaderBigEndian.cs" />
     <Compile Include="Lang\IBBMath.cs" />
     <Compile Include="CustomMath\IBBMath.cs" />
+    <Compile Include="Limits\NumericSizeConstrainedLimit.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="libs\log4net.dll" />
@@ -146,4 +147,7 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Limits\" />
+  </ItemGroup>
 </Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Limits/NumericSizeConstrainedLimit.cs	Tue Oct 06 18:49:04 2009 +0000
@@ -0,0 +1,35 @@
+// 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.
+
+using System;
+
+namespace IBBoard.Limits
+{
+	/// <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)
+		{
+			limit = numericLimit;
+		}
+		
+		/// <summary>
+		/// Gets the limited number, based on the limit that this <code>Limit</code> represents and the maximum size.
+		/// </summary>
+		/// <param name="size">
+		/// The maximum size
+		/// </param>
+		/// <returns>
+		/// <code>size</code> or the numeric limit this object was created with, whichever is smaller.
+		/// </returns>
+		public int GetLimit(int size)
+		{
+			return Math.Min(size, limit);
+		}
+	}
+}