Committed C# port from Mohamad
[zxing.git] / csharp / oned / MultiFormatOneDReader.cs
1 /*\r
2 * Licensed under the Apache License, Version 2.0 (the "License");\r
3 * you may not use this file except in compliance with the License.\r
4 * You may obtain a copy of the License at\r
5 *\r
6 *      http://www.apache.org/licenses/LICENSE-2.0\r
7 *\r
8 * Unless required by applicable law or agreed to in writing, software\r
9 * distributed under the License is distributed on an "AS IS" BASIS,\r
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
11 * See the License for the specific language governing permissions and\r
12 * limitations under the License.\r
13 */\r
14 namespace com.google.zxing.oned\r
15 {\r
16     /**\r
17      * @author dswitkin@google.com (Daniel Switkin)\r
18      * @author Sean Owen\r
19      */\r
20     using System.Text;\r
21     using com.google.zxing.common;\r
22 \r
23     public sealed class MultiFormatOneDReader : AbstractOneDReader\r
24     { \r
25           private System.Collections.ArrayList readers;\r
26           public MultiFormatOneDReader(System.Collections.Hashtable hints)\r
27           {\r
28             System.Collections.ArrayList possibleFormats = hints == null ? null : (System.Collections.ArrayList) hints[DecodeHintType.POSSIBLE_FORMATS];\r
29             readers = new System.Collections.ArrayList();\r
30             if (possibleFormats != null) {\r
31               if (possibleFormats.Contains(BarcodeFormat.EAN_13) ||\r
32                   possibleFormats.Contains(BarcodeFormat.UPC_A) ||\r
33                   possibleFormats.Contains(BarcodeFormat.EAN_8) ||\r
34                   possibleFormats.Contains(BarcodeFormat.UPC_E))\r
35               {\r
36                 readers.Add(new MultiFormatUPCEANReader(hints));\r
37               }\r
38               if (possibleFormats.Contains(BarcodeFormat.CODE_39)) {\r
39                   readers.Add(new Code39Reader());\r
40               }\r
41               if (possibleFormats.Contains(BarcodeFormat.CODE_128))\r
42               {\r
43                   readers.Add(new Code128Reader());\r
44               }\r
45               if (possibleFormats.Contains(BarcodeFormat.ITF))\r
46               {\r
47                   readers.Add(new ITFReader());\r
48               }\r
49             }\r
50             if (readers.Count==0) {\r
51                 readers.Contains(new MultiFormatUPCEANReader(hints));\r
52                 readers.Contains(new Code39Reader());\r
53                 readers.Contains(new Code128Reader());\r
54               // TODO: Add ITFReader once it is validated as production ready, and tested for performance.\r
55               //readers.addElement(new ITFReader());\r
56             }\r
57           }\r
58 \r
59           public override Result decodeRow(int rowNumber, BitArray row, System.Collections.Hashtable hints)\r
60           {\r
61             int size = readers.Count;\r
62             for (int i = 0; i < size; i++) {\r
63               OneDReader reader = (OneDReader) readers[i];\r
64               try {\r
65                 return reader.decodeRow(rowNumber, row, hints);\r
66               } catch (ReaderException re) {\r
67                 // continue\r
68               }\r
69             }\r
70 \r
71             throw new ReaderException();\r
72           }\r
73     \r
74     }\r
75 }