New C# port from Suraj Supekar
[zxing.git] / csharp / qrcode / decoder / ErrorCorrectionLevel.cs
diff --git a/csharp/qrcode/decoder/ErrorCorrectionLevel.cs b/csharp/qrcode/decoder/ErrorCorrectionLevel.cs
new file mode 100755 (executable)
index 0000000..1b65cc9
--- /dev/null
@@ -0,0 +1,102 @@
+/*\r
+* Copyright 2007 ZXing authors\r
+*\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+*      http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+using System;\r
+namespace com.google.zxing.qrcode.decoder\r
+{\r
+       \r
+       /// <summary> <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels\r
+       /// defined by the QR code standard.</p>\r
+       /// \r
+       /// </summary>\r
+       /// <author>  Sean Owen\r
+       /// </author>\r
+       /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
+       /// </author>\r
+       public sealed class ErrorCorrectionLevel\r
+       {\r
+               public int Bits\r
+               {\r
+                       get\r
+                       {\r
+                               return bits;\r
+                       }\r
+                       \r
+               }\r
+               public System.String Name\r
+               {\r
+                       get\r
+                       {\r
+                               return name;\r
+                       }\r
+                       \r
+               }\r
+               \r
+               // No, we can't use an enum here. J2ME doesn't support it.\r
+               \r
+               /// <summary> L = ~7% correction</summary>\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'L '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               public static readonly ErrorCorrectionLevel L = new ErrorCorrectionLevel(0, 0x01, "L");\r
+               /// <summary> M = ~15% correction</summary>\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'M '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               public static readonly ErrorCorrectionLevel M = new ErrorCorrectionLevel(1, 0x00, "M");\r
+               /// <summary> Q = ~25% correction</summary>\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'Q '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               public static readonly ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2, 0x03, "Q");\r
+               /// <summary> H = ~30% correction</summary>\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'H '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               public static readonly ErrorCorrectionLevel H = new ErrorCorrectionLevel(3, 0x02, "H");\r
+               \r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'FOR_BITS '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private static readonly ErrorCorrectionLevel[] FOR_BITS = new ErrorCorrectionLevel[]{M, L, H, Q};\r
+               \r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'ordinal '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private int ordinal_Renamed_Field;\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'bits '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private int bits;\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'name '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private System.String name;\r
+               \r
+               private ErrorCorrectionLevel(int ordinal, int bits, System.String name)\r
+               {\r
+                       this.ordinal_Renamed_Field = ordinal;\r
+                       this.bits = bits;\r
+                       this.name = name;\r
+               }\r
+               \r
+               public int ordinal()\r
+               {\r
+                       return ordinal_Renamed_Field;\r
+               }\r
+               \r
+               public override System.String ToString()\r
+               {\r
+                       return name;\r
+               }\r
+               \r
+               /// <param name="bits">int containing the two bits encoding a QR Code's error correction level\r
+               /// </param>\r
+               /// <returns> {@link ErrorCorrectionLevel} representing the encoded error correction level\r
+               /// </returns>\r
+               public static ErrorCorrectionLevel forBits(int bits)\r
+               {\r
+                       if (bits < 0 || bits >= FOR_BITS.Length)\r
+                       {\r
+                               throw new System.ArgumentException();\r
+                       }\r
+                       return FOR_BITS[bits];\r
+               }\r
+       }\r
+}
\ No newline at end of file