source: 2013/30/MiskaK/MW2(My Warfare 2)/Paranneltu Jypeli/AdvanceMath/ThrowHelper.cs @ 4507

Revision 4507, 2.7 KB checked in by anlakane, 6 years ago (diff)

Talletus.

Line 
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25#if UseDouble
26using Scalar = System.Double;
27#else
28using Scalar = System.Single;
29#endif
30using System;
31namespace AdvanceMath
32{
33    internal static class ThrowHelper
34    {
35        public static void CheckCopy(Scalar[] array, int index, int count)
36        {
37            if (array == null) { throw new ArgumentNullException("array", "The array cannot be null"); }
38            if (index < 0) { throw new ArgumentOutOfRangeException("index", "the index must be greater or equal to zero"); }
39            if (array.Length - index < count) { throw new ArgumentOutOfRangeException("array", String.Format("the array must have the length of {0} from the index", count)); }
40        }
41#if UNSAFE
42        public static void CheckIndex(string name, int index, int count)
43        {
44            if (index < 0 || index >= count)
45            {
46                throw GetThrowIndex(name, count);
47            }
48        }
49#endif
50        public static Exception GetThrowIndex(string name, int count)
51        {
52            return new ArgumentOutOfRangeException(name, string.Format("the {0} must be greater or equal to zero and less then {1}", name, count));
53        }
54        public static void ThrowVectorFormatException(string value, int count, string format)
55        {
56            throw new FormatException(
57                string.Format("Cannot parse the text '{0}' because it does not have {1} parts separated by commas in the form {2} with optional parenthesis.",
58                value, count, string.Format(format, 'X', 'Y', 'Z', 'W')));
59        }
60    }
61}
Note: See TracBrowser for help on using the repository browser.