Ejemplo n.º 1
0
    /// <summary>
    /// Returns a new array containing the input array's elements in reverse order.
    /// </summary>
    /// <param name="input">The input array.</param>
    /// <returns>A reversed clone of the input array.</returns>
    public static Array ReverseArray(Array input)
    {
        Array clone = (Array)input.Clone();
        for (int g = 0; g < clone.Length; g++)
        {
            clone.SetValue(input.GetValue(input.Length - g - 1), g);
        }

        return clone;
    }
Ejemplo n.º 2
0
 static public int Clone(IntPtr l)
 {
     try {
         System.Array self = (System.Array)checkSelf(l);
         var          ret  = self.Clone();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 3
0
 static int Clone(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         System.Array obj = (System.Array)ToLua.CheckObject(L, 1, typeof(System.Array));
         object       o   = obj.Clone();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 4
0
        public static Array Add(Array aFirst, Array aSecond)
        {
            if (aFirst ==  null)
            {
                return aSecond.Clone() as Array;
            }

            if (aSecond == null)
            {
                return aFirst.Clone() as Array;
            }

            Type typeFirst = aFirst.GetType().GetElementType();
            Type typeSecond = aSecond.GetType().GetElementType();

            System.Diagnostics.Debug.Assert(typeFirst == typeSecond);

            Array aNewArray = Array.CreateInstance(typeFirst, aFirst.Length + aSecond.Length);
            aFirst.CopyTo(aNewArray, 0);
            aSecond.CopyTo(aNewArray, aFirst.Length);

            return aNewArray;
        }
Ejemplo n.º 5
0
		private static void AssertArrayEqualsSorted (Array o1, Array o2)
		{
			Array s1 = (Array) o1.Clone ();
			Array s2 = (Array) o2.Clone ();

			Array.Sort (s1);
			Array.Sort (s2);

			Assert.AreEqual (s1.Length, s2.Length, "#1");
			for (int i = 0; i < s1.Length; ++i)
				Assert.AreEqual (s1.GetValue (i), s2.GetValue (i), "#2: " + i);
		}
Ejemplo n.º 6
0
		/// <summary>
		/// The actual implementation
		/// </summary>
		/// <param name="primary"></param>
		/// <param name="left"></param>
		/// <param name="right"></param>
		/// <param name="compare"></param>
		protected void InternalSort(
		ref Array primary,
		int left,
		int right,
		System.Collections.IComparer compare)
		{
			if (secondary == null || secondary.Length != primary.Length)
				secondary = (Array)primary.Clone();

			if (right > left)
			{
				int middle = (left + right) / 2;
				InternalSort(ref primary, left, middle, compare);
				InternalSort(ref primary, middle + 1, right, compare);

				int i, j, k;
				for (i = middle + 1; i > left; i--)
					secondary.SetValue(primary.GetValue(i - 1), i - 1);
				for (j = middle; j < right; j++)
					secondary.SetValue(primary.GetValue(j + 1), right + middle - j);
				for (k = left; k <= right; k++)
					primary.SetValue(
					(compare.Compare(secondary.GetValue(i), secondary.GetValue(j)) < 0) ?
					secondary.GetValue(i++) :
					secondary.GetValue(j--), k);
			}
		}
Ejemplo n.º 7
0
        private static Array GetMergedArray(object selected, Array oldArray, Array newArray, bool[] equalComponents)
        {
            Array result = newArray;
            if (oldArray != null)
            {
                result = (Array)oldArray.Clone();
                for (int i = 0; i < newArray.Length; i++)
                    if (!equalComponents[i])
                        result.SetValue(newArray.GetValue(i), i);
            }

            return result;
        }
Ejemplo n.º 8
0
        /// <summary>Writes the data to the wrapped array starting with the specified origin indices.
        /// </summary>
        /// <param name="origin">Indices to start adding of data. Null means all zeros.</param>
        /// <param name="a">Data to add to the variable.</param>
        public virtual void PutData(int[] origin, Array a)
        {
            if (a == null) return;
            if (rank == 0)
            {
                if (a.Rank != 1)
                    throw new Exception("Wrong rank");
                array.SetValue(a.GetValue(0), 0);
                return;
            }

            if (rank != a.Rank)
                throw new Exception("Wrong rank");

            int[] shape = null;

            if (array == null)
            {
                if (origin == null || IsZero(origin))
                {
                    array = (Array)a.Clone();
                    return;
                }

                shape = new int[rank];
                for (int i = 0; i < rank; i++)
                    shape[i] = origin[i] + a.GetLength(i);

                array = Array.CreateInstance(type, shape);
                CopyArray(a, array, new int[origin.Length], origin, true);
            }
            else
            {
                Array oldArr = array;

                if (origin == null)
                    origin = new int[rank];

                shape = new int[array.Rank];
                bool sufficient = true;
                for (int i = 0; i < array.Rank; i++)
                {
                    int size = origin[i] + a.GetLength(i);
                    sufficient = sufficient && (size <= oldArr.GetLength(i));

                    shape[i] = Math.Max(size, oldArr.GetLength(i));
                }

                Array newArr;
                if (sufficient)
                {
                    newArr = oldArr;
                }
                else
                {
                    newArr = Array.CreateInstance(type, shape);
                    CopyArray(oldArr, newArr, new int[array.Rank], new int[array.Rank],true);
                }

                if (origin == null)
                    origin = new int[array.Rank];
                CopyArray(a, newArr, new int[origin.Length], origin, true);
                array = newArr;
            }

            return;// shape;
        }
Ejemplo n.º 9
0
        public static object CopyValue(IValueManager manager, object value)
        {
            IDataValue dataValue = value as IDataValue;

            if (dataValue != null)
            {
                return(dataValue.Copy());
            }

            ICloneable cloneable = value as ICloneable;

            if (cloneable != null)
            {
                return(cloneable.Clone());
            }

                        #if SILVERLIGHT
            System.Array array = value as System.Array;
            if (array != null)
            {
                return(array.Clone());
            }
                        #endif

            if (value is StreamID)
            {
                return(manager.StreamManager.Reference((StreamID)value));
            }

            NativeRow nativeRow = value as NativeRow;
            if (nativeRow != null)
            {
                NativeRow newRow = new NativeRow(nativeRow.Values.Length);
                for (int index = 0; index < nativeRow.Values.Length; index++)
                {
                                        #if USEDATATYPESINNATIVEROW
                    newRow.DataTypes[index] = nativeRow.DataTypes[index];
                                        #endif
                    newRow.Values[index] = CopyValue(manager, nativeRow.Values[index]);
                }
                return(newRow);
            }

            NativeList nativeList = value as NativeList;
            if (nativeList != null)
            {
                NativeList newList = new NativeList();
                for (int index = 0; index < nativeList.Values.Count; index++)
                {
                    newList.DataTypes.Add(nativeList.DataTypes[index]);
                    newList.Values.Add(CopyValue(manager, nativeList.Values[index]));
                }
                return(newList);
            }

            NativeTable nativeTable = value as NativeTable;
            if (nativeTable != null)
            {
                return(CopyNative(manager, nativeTable.TableType, nativeTable));
            }

            return(value);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// create a TimeStamp from the type returned from SQL server when you ask for a TimeStamp.
 /// </summary>
 /// <param name="stamp"></param>
 public TimeStamp(System.Array stamp)
 {
     m_bytes = (System.Array)stamp.Clone();
 }
Ejemplo n.º 11
0
 public static string[] GetCommandLineArgs()
 {
     return((string[])s_commandLineArgs?.Clone());
 }
Ejemplo n.º 12
0
        /// Makes an independent clone of this field object
        /// (a bit expensive)
        public override Flattenable cloneFlat()
        {
            MessageField clone = new MessageField(_type);

            System.Array newArray;  // this will be a copy of our data array
            switch (_type)
            {
            case B_BOOL_TYPE: newArray = new bool[_numItems]; break;

            case B_INT8_TYPE: newArray = new byte[_numItems]; break;

            case B_INT16_TYPE: newArray = new short[_numItems]; break;

            case B_FLOAT_TYPE: newArray = new float[_numItems]; break;

            case B_INT32_TYPE: newArray = new int[_numItems]; break;

            case B_INT64_TYPE: newArray = new long[_numItems]; break;

            case B_DOUBLE_TYPE: newArray = new double[_numItems]; break;

            case B_STRING_TYPE: newArray = new string[_numItems]; break;

            case B_POINT_TYPE: newArray = new Point[_numItems]; break;

            case B_RECT_TYPE: newArray = new Rect[_numItems]; break;

            case B_MESSAGE_TYPE: newArray = new Message[_numItems]; break;

            default: newArray = new byte[_numItems][]; break;
            }

            newArray = (System.Array)_payload.Clone();

            // If the contents of newArray are modifiable, we need to
            // clone the contents also
            switch (_type)
            {
            case B_POINT_TYPE:
            {
                Point[] points = (Point[])newArray;
                for (int i = 0; i < _numItems; i++)
                {
                    points[i] = (Point)points[i].cloneFlat();
                }
            }
            break;

            case B_RECT_TYPE:
            {
                Rect[] rects = (Rect[])newArray;
                for (int i = 0; i < _numItems; i++)
                {
                    rects[i] = (Rect)rects[i].cloneFlat();
                }
            }
            break;

            case B_MESSAGE_TYPE:
            {
                Message[] messages = (Message[])newArray;
                for (int i = 0; i < _numItems; i++)
                {
                    messages[i] = (Message)messages[i].cloneFlat();
                }
            }
            break;

            default:
            {
                if (newArray is byte[][])
                {
                    // Clone the byte arrays, since they are modifiable
                    byte[][] array = (byte[][])newArray;
                    for (int i = 0; i < _numItems; i++)
                    {
                        byte[] newBuf = (byte[])array[i].Clone();
                        array[i] = newBuf;
                    }
                }
            }
            break;
            }

            clone.setPayload(newArray, _numItems);
            return(clone);
        }