X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=csharp%2FSupportClass.cs;h=7e2d298fd17c74a0b341157accc9881f07327f45;hb=660beaca57a1c4318e83f0f548c63b622ce0f526;hp=5058d7d3c5ff3123ff5d580a5f8fce58453640ba;hpb=e35d358134873c3f640672da7cd0c01f02253151;p=zxing.git
diff --git a/csharp/SupportClass.cs b/csharp/SupportClass.cs
index 5058d7d3..7e2d298f 100755
--- a/csharp/SupportClass.cs
+++ b/csharp/SupportClass.cs
@@ -1,115 +1,21 @@
-/*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+//
+// In order to convert some functionality to Visual C#, the Java Language Conversion Assistant
+// creates "support classes" that duplicate the original functionality.
+//
+// Support classes replicate the functionality of the original code, but in some cases they are
+// substantially different architecturally. Although every effort is made to preserve the
+// original architecture of the application in the converted project, the user should be aware that
+// the primary goal of these support classes is to replicate functionality, and that at times
+// the architecture of the resulting solution may differ somewhat.
+//
using System;
- ///
- /// This interface should be implemented by any class whose instances are intended
- /// to be executed by a thread.
- ///
- public interface IThreadRunnable
- {
- ///
- /// This method has to be implemented in order that starting of the thread causes the object's
- /// run method to be called in that separately executing thread.
- ///
- void Run();
- }
-
///
/// Contains conversion support elements such as classes, interfaces and static methods.
///
public class SupportClass
{
-
-
-
- ///
- /// Performs an unsigned bitwise right shift with the specified number
- ///
- /// Number to operate on
- /// Ammount of bits to shift
- /// The resulting number from the shift operation
- public static int URShift(int number, int bits)
- {
- if ( number >= 0)
- return number >> bits;
- else
- return (number >> bits) + (2 << ~bits);
- }
-
- ///
- /// Performs an unsigned bitwise right shift with the specified number
- ///
- /// Number to operate on
- /// Ammount of bits to shift
- /// The resulting number from the shift operation
- public static int URShift(int number, long bits)
- {
- return URShift(number, (int)bits);
- }
-
- ///
- /// Performs an unsigned bitwise right shift with the specified number
- ///
- /// Number to operate on
- /// Ammount of bits to shift
- /// The resulting number from the shift operation
- public static long URShift(long number, int bits)
- {
- if ( number >= 0)
- return number >> bits;
- else
- return (number >> bits) + (2L << ~bits);
- }
-
- ///
- /// Performs an unsigned bitwise right shift with the specified number
- ///
- /// Number to operate on
- /// Ammount of bits to shift
- /// The resulting number from the shift operation
- public static long URShift(long number, long bits)
- {
- return URShift(number, (int)bits);
- }
-
- /*******************************/
- ///
- /// Copies an array of chars obtained from a String into a specified array of chars
- ///
- /// The String to get the chars from
- /// Position of the String to start getting the chars
- /// Position of the String to end getting the chars
- /// Array to return the chars
- /// Position of the destination array of chars to start storing the chars
- /// An array of chars
- public static void GetCharsFromString(System.String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)
- {
- int sourceCounter;
- int destinationCounter;
- sourceCounter = sourceStart;
- destinationCounter = destinationStart;
- while (sourceCounter < sourceEnd)
- {
- destinationArray[destinationCounter] = (char) sourceString[sourceCounter];
- sourceCounter++;
- destinationCounter++;
- }
- }
-
- /*******************************/
///
/// Converts an array of sbytes to an array of bytes
///
@@ -157,20 +63,54 @@ public class SupportClass
/*******************************/
///
- /// Sets the capacity for the specified ArrayList
+ /// Performs an unsigned bitwise right shift with the specified number
///
- /// The ArrayList which capacity will be set
- /// The new capacity value
- public static void SetCapacity(System.Collections.ArrayList vector, int newCapacity)
+ /// Number to operate on
+ /// Ammount of bits to shift
+ /// The resulting number from the shift operation
+ public static int URShift(int number, int bits)
{
- if (newCapacity > vector.Count)
- vector.AddRange(new Array[newCapacity-vector.Count]);
- else if (newCapacity < vector.Count)
- vector.RemoveRange(newCapacity, vector.Count - newCapacity);
- vector.Capacity = newCapacity;
+ if ( number >= 0)
+ return number >> bits;
+ else
+ return (number >> bits) + (2 << ~bits);
}
+ ///
+ /// Performs an unsigned bitwise right shift with the specified number
+ ///
+ /// Number to operate on
+ /// Ammount of bits to shift
+ /// The resulting number from the shift operation
+ public static int URShift(int number, long bits)
+ {
+ return URShift(number, (int)bits);
+ }
+ ///
+ /// Performs an unsigned bitwise right shift with the specified number
+ ///
+ /// Number to operate on
+ /// Ammount of bits to shift
+ /// The resulting number from the shift operation
+ public static long URShift(long number, int bits)
+ {
+ if ( number >= 0)
+ return number >> bits;
+ else
+ return (number >> bits) + (2L << ~bits);
+ }
+
+ ///
+ /// Performs an unsigned bitwise right shift with the specified number
+ ///
+ /// Number to operate on
+ /// Ammount of bits to shift
+ /// The resulting number from the shift operation
+ public static long URShift(long number, long bits)
+ {
+ return URShift(number, (int)bits);
+ }
/*******************************/
///
@@ -215,242 +155,61 @@ public class SupportClass
/*******************************/
///
- /// Support class used to handle threads
+ /// Copies an array of chars obtained from a String into a specified array of chars
///
- public class ThreadClass : IThreadRunnable
- {
- ///
- /// The instance of System.Threading.Thread
- ///
- private System.Threading.Thread threadField;
-
- ///
- /// Initializes a new instance of the ThreadClass class
- ///
- public ThreadClass()
- {
- threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
- }
-
- ///
- /// Initializes a new instance of the Thread class.
- ///
- /// The name of the thread
- public ThreadClass(System.String Name)
- {
- threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
- this.Name = Name;
- }
-
- ///
- /// Initializes a new instance of the Thread class.
- ///
- /// A ThreadStart delegate that references the methods to be invoked when this thread begins executing
- public ThreadClass(System.Threading.ThreadStart Start)
- {
- threadField = new System.Threading.Thread(Start);
- }
-
- ///
- /// Initializes a new instance of the Thread class.
- ///
- /// A ThreadStart delegate that references the methods to be invoked when this thread begins executing
- /// The name of the thread
- public ThreadClass(System.Threading.ThreadStart Start, System.String Name)
- {
- threadField = new System.Threading.Thread(Start);
- this.Name = Name;
- }
-
- ///
- /// This method has no functionality unless the method is overridden
- ///
- public virtual void Run()
- {
- }
-
- ///
- /// Causes the operating system to change the state of the current thread instance to ThreadState.Running
- ///
- public virtual void Start()
- {
- threadField.Start();
- }
-
- /////
- ///// Interrupts a thread that is in the WaitSleepJoin thread state
- /////
- //public virtual void Interrupt()
- //{
- // threadField.Interrupt();
- //}
-
- ///
- /// Gets the current thread instance
- ///
- public System.Threading.Thread Instance
- {
- get
- {
- return threadField;
- }
- set
- {
- threadField = value;
- }
- }
-
- ///
- /// Gets or sets the name of the thread
- ///
- public System.String Name
- {
- get
- {
- return threadField.Name;
- }
- set
- {
- if (threadField.Name == null)
- threadField.Name = value;
- }
- }
-
- ///
- /// Gets or sets a value indicating the scheduling priority of a thread
- ///
- public System.Threading.ThreadPriority Priority
- {
- get
- {
- return threadField.Priority;
- }
- set
- {
- threadField.Priority = value;
- }
- }
-
- /////
- ///// Gets a value indicating the execution status of the current thread
- /////
- //public bool IsAlive
- //{
- // get
- // {
- // return threadField.IsAlive;
- // }
- //}
-
- ///
- /// Gets or sets a value indicating whether or not a thread is a background thread.
- ///
- public bool IsBackground
- {
- get
- {
- return threadField.IsBackground;
- }
- set
- {
- threadField.IsBackground = value;
- }
- }
-
- ///
- /// Blocks the calling thread until a thread terminates
- ///
- public void Join()
- {
- threadField.Join();
- }
-
- ///
- /// Blocks the calling thread until a thread terminates or the specified time elapses
- ///
- /// Time of wait in milliseconds
- public void Join(int MiliSeconds)
- {
- lock(this)
- {
- threadField.Join(MiliSeconds);
- }
- }
-
- /////
- ///// Blocks the calling thread until a thread terminates or the specified time elapses
- /////
- ///// Time of wait in milliseconds
- ///// Time of wait in nanoseconds
- //public void Join(long MiliSeconds, int NanoSeconds)
- //{
- // lock(this)
- // {
- // threadField.Join(new System.TimeSpan(MiliSeconds * 10000 + NanoSeconds * 100));
- // }
- //}
-
- /////
- ///// Resumes a thread that has been suspended
- /////
- //public void Resume()
- //{
- // threadField.Resume();
- //}
-
- ///
- /// Raises a ThreadAbortException in the thread on which it is invoked,
- /// to begin the process of terminating the thread. Calling this method
- /// usually terminates the thread
- ///
- public void Abort()
- {
- threadField.Abort();
- }
-
- ///
- /// Raises a ThreadAbortException in the thread on which it is invoked,
- /// to begin the process of terminating the thread while also providing
- /// exception information about the thread termination.
- /// Calling this method usually terminates the thread.
- ///
- /// An object that contains application-specific information, such as state, which can be used by the thread being aborted
- public void Abort(System.Object stateInfo)
- {
- lock(this)
- {
- threadField.Abort(stateInfo);
- }
- }
-
- /////
- ///// Suspends the thread, if the thread is already suspended it has no effect
- /////
- //public void Suspend()
- //{
- // threadField.Suspend();
- //}
-
- ///
- /// Obtain a String that represents the current Object
- ///
- /// A String that represents the current Object
- public override System.String ToString()
+ /// The String to get the chars from
+ /// Position of the String to start getting the chars
+ /// Position of the String to end getting the chars
+ /// Array to return the chars
+ /// Position of the destination array of chars to start storing the chars
+ /// An array of chars
+ public static void GetCharsFromString(System.String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)
+ {
+ int sourceCounter;
+ int destinationCounter;
+ sourceCounter = sourceStart;
+ destinationCounter = destinationStart;
+ while (sourceCounter < sourceEnd)
{
- return "Thread[" + Name + "," + Priority.ToString() + "," + "" + "]";
+ destinationArray[destinationCounter] = (char) sourceString[sourceCounter];
+ sourceCounter++;
+ destinationCounter++;
}
-
- ///
- /// Gets the currently running thread
- ///
- /// The currently running thread
- public static ThreadClass Current()
+ }
+
+ /*******************************/
+ ///
+ /// Sets the capacity for the specified ArrayList
+ ///
+ /// The ArrayList which capacity will be set
+ /// The new capacity value
+ public static void SetCapacity(System.Collections.ArrayList vector, int newCapacity)
+ {
+ if (newCapacity > vector.Count)
+ vector.AddRange(new Array[newCapacity-vector.Count]);
+ else if (newCapacity < vector.Count)
+ vector.RemoveRange(newCapacity, vector.Count - newCapacity);
+ vector.Capacity = newCapacity;
+ }
+
+
+
+ /*******************************/
+ ///
+ /// Receives a byte array and returns it transformed in an sbyte array
+ ///
+ /// Byte array to process
+ /// The transformed array
+ public static sbyte[] ToSByteArray(byte[] byteArray)
+ {
+ sbyte[] sbyteArray = null;
+ if (byteArray != null)
{
- ThreadClass CurrentThread = new ThreadClass();
- CurrentThread.Instance = System.Threading.Thread.CurrentThread;
- return CurrentThread;
+ sbyteArray = new sbyte[byteArray.Length];
+ for(int index=0; index < byteArray.Length; index++)
+ sbyteArray[index] = (sbyte) byteArray[index];
}
+ return sbyteArray;
}
-
}