Committed C# port from Mohamad
[zxing.git] / csharp / Result.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 \r
15 using System;\r
16 using System.Collections;\r
17 \r
18 namespace com.google.zxing\r
19 {\r
20 \r
21     /// <summary> The general exception class throw when something goes wrong during decoding of a barcode.\r
22     /// This includes, but is not limited to, failing checksums / error correction algorithms, being\r
23     /// unable to locate finder timing patterns, and so on.\r
24     /// \r
25     /// </summary>\r
26     /// <author>  srowen@google.com (Sean Owen)\r
27     /// </author>\r
28     //[Serializable]\r
29     public sealed class Result \r
30     {\r
31           private String text;\r
32           private sbyte[] rawBytes;\r
33           private ResultPoint[] resultPoints;\r
34           private BarcodeFormat format;\r
35           private Hashtable resultMetadata;\r
36 \r
37           public Result(String text,\r
38                         sbyte[] rawBytes,\r
39                         ResultPoint[] resultPoints,\r
40                         BarcodeFormat format) {\r
41             if (text == null && rawBytes == null) {\r
42               throw new ArgumentException("Text and bytes are null");\r
43             }\r
44             this.text = text;\r
45             this.rawBytes = rawBytes;\r
46             this.resultPoints = resultPoints;\r
47             this.format = format;\r
48             this.resultMetadata = null;\r
49           }\r
50 \r
51           /**\r
52            * @return raw text encoded by the barcode, if applicable, otherwise <code>null</code>\r
53            */\r
54           public String getText() {\r
55             return text;\r
56           }\r
57 \r
58           /**\r
59            * @return raw bytes encoded by the barcode, if applicable, otherwise <code>null</code>\r
60            */\r
61           public sbyte[] getRawBytes() {\r
62             return rawBytes;\r
63           }\r
64 \r
65           /**\r
66            * @return points related to the barcode in the image. These are typically points\r
67            *         identifying finder patterns or the corners of the barcode. The exact meaning is\r
68            *         specific to the type of barcode that was decoded.\r
69            */\r
70           public ResultPoint[] getResultPoints() {\r
71             return resultPoints;\r
72           }\r
73 \r
74           /**\r
75            * @return {@link BarcodeFormat} representing the format of the barcode that was recognized and decoded\r
76            */\r
77           public BarcodeFormat getBarcodeFormat() {\r
78             return format;\r
79           }\r
80 \r
81           /**\r
82            * @return {@link Hashtable} mapping {@link ResultMetadataType} keys to values. May be <code>null</code>.\r
83            *  This contains optional metadata about what was detected about the barcode, like orientation.\r
84            */\r
85           public Hashtable getResultMetadata() {\r
86             return resultMetadata;\r
87           }\r
88 \r
89           public void putMetadata(ResultMetadataType type, Object value) {\r
90             if (resultMetadata == null) {\r
91               resultMetadata = new Hashtable(3);\r
92             }\r
93             resultMetadata.Add(type, value);\r
94           }\r
95 \r
96           public String toString() {\r
97             if (text == null) {\r
98               return "[" + rawBytes.Length + " bytes]";\r
99             } else {\r
100               return text;\r
101             }\r
102           }\r
103     \r
104     \r
105     }\r
106 }