Committed C# port from Mohamad
[zxing.git] / csharp / common / ECI.cs
diff --git a/csharp/common/ECI.cs b/csharp/common/ECI.cs
new file mode 100755 (executable)
index 0000000..05f8dc6
--- /dev/null
@@ -0,0 +1,56 @@
+/*\r
+* Copyright 2008 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
+namespace com.google.zxing.common\r
+{\r
+    using System;\r
+    using System.Text;\r
+\r
+    /// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a\r
+    /// unsigned container, it's up to you to do byteValue & 0xff at each location.\r
+    /// *\r
+    /// JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have\r
+    /// the horizontal component first, but this is for compatibility with the C++ code. The original\r
+    /// code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use\r
+    /// less memory and go with bytes.\r
+    /// *\r
+    /// </summary>\r
+    /// <author>  dswitkin@google.com (Daniel Switkin)\r
+    /// \r
+    /// </author>\r
+    public abstract class ECI\r
+    { \r
+          private int value;\r
+        \r
+          public ECI(int value) {\r
+            this.value = value;\r
+          }\r
+\r
+          public int getValue() {\r
+            return value;\r
+          }\r
+\r
+          public static ECI getECIByValue(int value) {\r
+            if (value < 0 || value > 999999) {\r
+              throw new Exception("Bad ECI value: " + value);\r
+            }\r
+            if (value < 900) { // Character set ECIs use 000000 - 000899\r
+              return CharacterSetECI.getCharacterSetECIByValue(value);\r
+            }\r
+            throw new Exception("Unsupported ECI value: " + value);\r
+          }\r
+\r
+    }\r
+}
\ No newline at end of file