# HG changeset patch # User IBBoard # Date 1254940809 0 # Node ID a177a3750acd4222b799c99fb90e4791d9d3c0f2 # Parent f3bb5b77a7e4a510f649f25c32e7b7fb5d88df23 Re #24: Add "limit" objects that can be used for numeric limits * Refactor out common base class * Fix licenses for new files diff -r f3bb5b77a7e4 -r a177a3750acd IBBoard.csproj --- 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 @@ + diff -r f3bb5b77a7e4 -r a177a3750acd Limits/AbstractLimit.cs --- /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 +{ + /// + /// The abstract base class for all limits + /// + public abstract class AbstractLimit + { + private double limit; + + public AbstractLimit (double limitNum) + { + limit = limitNum; + } + + protected double Limit + { + get + { + return limit; + } + } + + /// + /// Gets the limited number, based on the limit that this Limit represents and the number it is limiting (size). + /// + /// + /// The number to be limited + /// + /// + /// the limited number, as defined by the implementation of the limit + /// + public abstract int GetLimit(int size); + } +} diff -r f3bb5b77a7e4 -r a177a3750acd Limits/NumericSizeConstrainedLimit.cs --- 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 @@ /// /// A limit of a specified number, or the number it is limited against, whichever is smaller. /// - public class NumericSizeConstrainedLimit - { - private int limit; - - public NumericSizeConstrainedLimit (int numericLimit) + public class NumericSizeConstrainedLimit : AbstractLimit + { + public NumericSizeConstrainedLimit (int numericLimit) : base(numericLimit) { - limit = numericLimit; } /// @@ -29,7 +26,7 @@ /// public int GetLimit(int size) { - return Math.Min(size, limit); + return (int)Math.Min(size, Limit); } } } diff -r f3bb5b77a7e4 -r a177a3750acd Limits/SimpleRoundedPercentageLimit.cs --- 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 @@ /// /// A percentage-based limit that always either rounds up or down to the closest integer /// - 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 @@ /// public int GetLimit(int size) { - return (int)IBBMath.Round(size * limit / 100, roundUp); + return (int)IBBMath.Round(size * Limit / 100, roundUp); } } }