Committed C# port from Mohamad
[zxing.git] / csharp / common / ECI.cs
1 /*\r
2 * Copyright 2008 ZXing authors\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16 namespace com.google.zxing.common\r
17 {\r
18     using System;\r
19     using System.Text;\r
20 \r
21     /// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a\r
22     /// unsigned container, it's up to you to do byteValue & 0xff at each location.\r
23     /// *\r
24     /// JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have\r
25     /// the horizontal component first, but this is for compatibility with the C++ code. The original\r
26     /// code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use\r
27     /// less memory and go with bytes.\r
28     /// *\r
29     /// </summary>\r
30     /// <author>  dswitkin@google.com (Daniel Switkin)\r
31     /// \r
32     /// </author>\r
33     public abstract class ECI\r
34     { \r
35           private int value;\r
36         \r
37           public ECI(int value) {\r
38             this.value = value;\r
39           }\r
40 \r
41           public int getValue() {\r
42             return value;\r
43           }\r
44 \r
45           public static ECI getECIByValue(int value) {\r
46             if (value < 0 || value > 999999) {\r
47               throw new Exception("Bad ECI value: " + value);\r
48             }\r
49             if (value < 900) { // Character set ECIs use 000000 - 000899\r
50               return CharacterSetECI.getCharacterSetECIByValue(value);\r
51             }\r
52             throw new Exception("Unsupported ECI value: " + value);\r
53           }\r
54 \r
55     }\r
56 }