Example #1
0
        public void read_header_order()
        {
            int err = 0;

            do
            {
                //Attach Detail fields template
                oCustomer.dsTmpl(channel, "teacher:c(30),student:c(30*),type:c(3*),prize:c(10*),nro_items:n(10*),retail:n(10*),collected:n(10*),tax:n(10*),printed:n(1*),disc_printed:n(1*),box:c(10*),entry_date:n(10*):date=jul:,phone:c(10*)");
                err = oCustomer.dsReadFldNext(channel, "teacher,student,type,prize,nro_items,retail,collected,tax,printed,entry_date,phone", ref sKey, ref arrValues);
            }while (err == 0);

            arrValues.SetValue(cv_string(arrValues.GetValue(1).ToString()), 1);
            arrValues.SetValue(cv_string(arrValues.GetValue(2).ToString()), 2);

            this.Header.CustomerID = this.sCustomerID;
            this.Header.CompanyID  = this.sCompanyID;
            this.Header.Teacher    = arrValues.GetValue(0).ToString();
            this.Header.Student    = arrValues.GetValue(1).ToString();
            this.Header.Type       = arrValues.GetValue(2).ToString();
            this.Header.Prize      = arrValues.GetValue(3).ToString();
            this.Header.No_Items   = arrValues.GetValue(4).ToString();
            this.Header.Retail     = arrValues.GetValue(5).ToString();
            this.Header.Collected  = arrValues.GetValue(6).ToString();
            this.Header.Tax        = arrValues.GetValue(7).ToString();
            this.Header.Printed    = arrValues.GetValue(8).ToString();
            //	this.Header.Disc_Printed = arrValues.GetValue(9).ToString();
            //	this.Header.Box = arrValues.GetValue(10).ToString();
            this.Header.Date  = this.cv_date(arrValues.GetValue(9).ToString());
            this.Header.Phone = arrValues.GetValue(10).ToString();


            //sKey1 = sKey;
            return;
        }
 /// <summary>
 /// Sort elements in an Array object, using the Order
 /// delegate to determine how items should be sorted.
 /// </summary>
 /// <param name="table">Array to be sorted</param>
 /// <param name="sortHandler">Delegate to manage
 /// sort order.</param>
 public void Sort(Array table, Order sortHandler)
 {
     if(sortHandler == null)
         throw new ArgumentNullException();
     
     bool nothingSwapped = false;
     int pass = 1;
     while(nothingSwapped == false)
     {
         nothingSwapped = true;
         for(int index = 0; index < table.Length - pass; ++index)
         {
             // Use an Order delegate to determine the sort order.
             if(sortHandler(table.GetValue(index),
                 table.GetValue(index + 1)) == false)
             {
                 nothingSwapped = false;
                 object temp = table.GetValue(index);
                 table.SetValue(table.GetValue(index + 1), index);
                 table.SetValue(temp, index + 1);
             }
         }
         ++pass;
     }
 }
Example #3
0
    public static void SwapArrayElements(System.Array array, int i, int j)
    {
        object temp = array.GetValue(i);

        array.SetValue(array.GetValue(j), i);
        array.SetValue(temp, j);
    }
Example #4
0
        private object splitArray(int[] vls, IPixelBlock3 pb3)
        {
            int width  = pb3.Width;
            int height = pb3.Height;
            int cnt    = 0;

            System.Array outArr = (System.Array)pb3.get_PixelData(0);
            rstPixelType rsp    = pb3.get_PixelType(0);

            foreach (int i in vls)
            {
                double div = System.Convert.ToDouble(cnt) / width;
                int    r   = (int)div;
                int    c   = cnt - (r * width);
                try
                {
                    object newvl = rasterUtil.getSafeValue(i, rsp);
                    outArr.SetValue(i, c, r);
                }
                catch
                {
                    object newvl = rasterUtil.getSafeValue(900, rsp);
                    outArr.SetValue(900, c, r);
                }
                cnt++;
            }
            return(outArr);
        }
Example #5
0
 public static void swapTo(float input, Array dest, int pos)
 {
     byte[] tmpIn = BitConverter.GetBytes(input);
      dest.SetValue(tmpIn[3], pos);
      dest.SetValue(tmpIn[2], pos + 1);
      dest.SetValue(tmpIn[1], pos + 2);
      dest.SetValue(tmpIn[0], pos + 3);
 }
 public static void Shuffle(this Random rng, Array array)
 {
     int n = array.Length;
     while (n > 1) {
         int k = rng.Next (n--);
         object temp = array.GetValue (n);
         array.SetValue (array.GetValue (k), n);
         array.SetValue (temp, k);
     }
 }
Example #7
0
        //This will contain the data in parsed form.

        public static System.Array resizeArray(System.Array oldArray)  // this function will resize our temporary string array that is used to store the parsed Line.
        {
            int oldSize = oldArray.Length;

            System.Type  elementType = oldArray.GetType().GetElementType();
            System.Array newArray    = System.Array.CreateInstance(elementType, 16);
            //now we'll copy the contents of the old array into the new array
            for (int i = 0; i < oldArray.Length; ++i)
            {
                newArray.SetValue(oldArray.GetValue(i), i);
            }
            newArray.SetValue("", 15);
            return(newArray);
        }
Example #8
0
        protected override void SortGenericArray(Array items, int left, int right)
        {
            int lo = left;
            int hi = right;

            if (lo >= hi)
            {
                return;
            }

            int mid = (lo + hi) / 2;

            // Partition the items into two lists and Sort them recursively
            SortGenericArray(items, lo, mid);
            SortGenericArray(items, mid + 1, hi);

            // Merge the two sorted lists
            int end_lo = mid;
            int start_hi = mid + 1;

            while ((lo <= end_lo) && (start_hi <= hi))
            {

                if (this.comparer.Compare(items.GetValue(lo), items.GetValue(start_hi)) < 0)
                {
                    lo++;
                }
                else
                {
                    /*
                  *  items[lo] >= items[start_hi]
                  *  The next element comes from the second items,
                  *  move the items[start_hi] element into the next
                  *  position and shuffle all the other elements up.
                  */
                    object T = items.GetValue(start_hi);

                    for (int k = start_hi - 1; k >= lo; k--)
                    {
                        items.SetValue(items.GetValue(k), k + 1);
                    }

                    items.SetValue(T, lo);
                    lo++;
                    end_lo++;
                    start_hi++;
                }
            }
        }
Example #9
0
 void ICollection.CopyTo(System.Array array, int index)
 {
     foreach (var kvp in this)
     {
         array.SetValue(new DictionaryEntry(kvp.Key, kvp.Value), index++);
     }
 }
Example #10
0
 public static void ConstrainedCopy(System.Array source, int srcOffset, System.Array destination, int destOffset, int count)
 {
     for (int i = 0; i < count; i++)
     {
         destination.SetValue(source.GetValue(srcOffset + i), destOffset + i);
     }
 }
 public void CopyTo(Array array, int index)
 {
     foreach (object item in this)
     {
         array.SetValue(item, index++);
     }
 }
Example #12
0
    private static int __newindex_Array(ILuaState L)
    {
        System.Array obj = L.ChkUserDataSelf(1, CLASS) as System.Array;

        if (obj == null)
        {
            L.L_Error("trying to newindex an invalid Array reference");
            return(0);
        }

        int    index   = L.ChkInteger(2);
        object val     = L.ToAnyObject(3);
        var    valType = val.GetType();

        System.Type type = obj.GetType().GetElementType();

        if (!type.IsAssignableFrom(valType))
        {
            L.L_Error(string.Format("trying to set object type is not correct: {0} expected, got {1}", type, valType));
            return(0);
        }

        val = System.Convert.ChangeType(val, type);
        obj.SetValue(val, index);

        return(0);
    }
Example #13
0
 void ICollection.CopyTo(System.Array array, int index)
 {
     foreach (StackItem item in _array)
     {
         array.SetValue(item, index++);
     }
 }
        /// <summary>
        /// Reorders the entities in an entity collection by the keySelector function.
        /// </summary>
        /// <remarks>
        /// This class uses reflection to re-write the slots in the underlying hashset used by the entity
        /// collection to contain the references.
        ///
        /// The only action that should be taken on the entity collection after this method has been called
        /// is via its enumerators, as the hash set is not left in a consistant state.
        /// </remarks>
        /// <typeparam name="TSource">The type of the entity objects.</typeparam>
        /// <typeparam name="TKey">The type of the key to order by.</typeparam>
        /// <param name="source">The entity collection source to re-order.</param>
        /// <param name="keySelector">The key selector function that returns the key to order by.</param>
        public static void ReorderEntities <TSource, TKey>(
            this EntityCollection <TSource> source,
            Func <TSource, TKey> keySelector)
            where TSource : class, IEntityWithRelationships
        {
            HashSet <TSource> relatedEntities = (HashSet <TSource>)
                                                typeof(EntityCollection <TSource>).GetProperty("RelatedEntities", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(source, null);
            // re-order the sets slots to fix the ordering, (but mess up everything else probably)
            Type slotType = typeof(HashSet <TSource>).Assembly.GetType("System.Collections.Generic.HashSet`1+Slot").MakeGenericType(new Type[] { typeof(TSource) });

            FieldInfo slotField = typeof(HashSet <TSource>).GetField("m_slots", BindingFlags.Instance | BindingFlags.NonPublic);
            FieldInfo lastIndex = typeof(HashSet <TSource>).GetField("m_lastIndex", BindingFlags.Instance | BindingFlags.NonPublic);

            System.Array slots = Array.CreateInstance(slotType, relatedEntities.Count);
            int          index = 0;

            foreach (TSource obj in new List <TSource>(relatedEntities).OrderBy(keySelector))
            {
                object test = Activator.CreateInstance(slotType);
                slotType.GetField("hashCode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(test, obj.GetHashCode());
                slotType.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(test, obj);
                slotType.GetField("next", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(test, -1);
                slots.SetValue(test, index++);
            }
            slotField.SetValue(relatedEntities, slots);
            lastIndex.SetValue(relatedEntities, slots.Length);
        }
 void ICollection.CopyTo(Array array, int index)
 {
     foreach (DesignSurface surface in this)
     {
         array.SetValue(surface, index++);
     }
 }
Example #16
0
        public Palette(int randomSeed, int colorX, int colorY)
        {
            _random = new Random(randomSeed);
            ColorList = new List<PaletteColor>();

            Bitmap bmp;
            try
            {
                bmp = Properties.Resources.ColourPalette;
                _colorArr = Array.CreateInstance(typeof(Color), bmp.Height / colorX);

                var y = colorY;
                var ind = 0;
                while (y < bmp.Height)
                {
                    var clr = bmp.GetPixel(colorY, y);
                    y += colorX;

                    _colorArr.SetValue(clr, ind);
                    ind++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #17
0
        void ICollection.CopyTo(System.Array array, int index)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array), "Value cannot be null.");
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index),
                                                      "Number was less than the array's lower bound in the first dimension.");
            }

            int count = Count;

            if (array.Length < (index + count))
            {
                throw new ArgumentException(
                          "Destination array was not long enough. Check destIndex and length, and the array's lower bounds.");
            }

            unsafe
            {
                for (int i = 0; i < count; i++)
                {
                    object obj = Marshaling.ConvertVariantToManagedObject(NativeValue.DangerousSelfRef.Elements[i]);
                    array.SetValue(obj, index);
                    index++;
                }
            }
        }
 public void CopyTo(Array array, int index)
 {
     foreach (MethodData data in this)
     {
         array.SetValue(data, index++);
     }
 }
Example #19
0
 static public void Copy(System.Array src, int lower, int upper, System.Array dest)
 {
     for (int i = lower, j = 0; i != upper; ++i, ++j)
     {
         dest.SetValue(src.GetValue(i), j);
     }
 }
Example #20
0
        // Not ported - ToString( object value, ISessionFactoryImplementor factory )
        // - PesistentCollectionType implementation is able to handle arrays too in .NET

        /// <summary>
        ///
        /// </summary>
        /// <param name="original"></param>
        /// <param name="target"></param>
        /// <param name="session"></param>
        /// <param name="owner"></param>
        /// <param name="copiedAlready"></param>
        /// <returns></returns>
        public override object Copy(object original, object target, ISessionImplementor session, object owner, IDictionary copiedAlready)
        {
            if (original == null)
            {
                return(null);
            }
            if (original == target)
            {
                return(target);
            }

            System.Array orig   = (System.Array)original;
            int          length = orig.Length;

            System.Array result = System.Array.CreateInstance(elementClass, length);

            IType elemType = GetElementType(session.Factory);

            for (int i = 0; i < length; i++)
            {
                result.SetValue(
                    elemType.Copy(orig.GetValue(i), null, session, owner, copiedAlready),
                    i);
            }
            return(result);
        }
Example #21
0
        //DataTable转RecordSet
        public Recordset DsToRs(DataTable table)
        {
            Recordset rs = new RecordsetClass();

            System.Array ArrA = System.Array.CreateInstance(typeof(string), table.Columns.Count);

            foreach (DataColumn dc in table.Columns)
            {
                ArrA.SetValue(dc.ColumnName, dc.Ordinal);
                rs.Fields._Append(dc.ColumnName, GetDataType(dc.DataType), -1, FieldAttributeEnum.adFldIsNullable);
            }
            rs.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockUnspecified, -1);
            //rs.Open(null,null, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic, 0);
            // int i = 0;
            foreach (DataRow dr in table.Rows)
            {
                rs.AddNew(Missing.Value, Missing.Value); //object o;
                                                         // rs.AddNew(rs.Fields.,dr.ItemArray);

                //rs.AddNew(ArrA, dr.ItemArray);
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    rs.Fields[i].Value = dr[i];
                }
            }
            return(rs);
        }
		public void CopyTo(Array array, int index){
			IEnumerator tablecell = this.GetEnumerator();
			while(tablecell.MoveNext()){
				index = index + 1;
				array.SetValue(tablecell.Current, index);
			}
		}
Example #23
0
 void ICollection.CopyTo(System.Array array, int index)
 {
     foreach (KeyValuePair <StackItem, StackItem> item in dictionary)
     {
         array.SetValue(item, index++);
     }
 }
    public void Init()
    {
        checkVals  = new int[collectionSize];
        arrayInt   = new int[collectionSize];
        listInt    = new List <int>(collectionSize);
        hashset    = new HashSet <int>();
        dict       = new Dictionary <int, int>(collectionSize);
        linkedList = new LinkedList <int>();
        stack      = new Stack <int>(collectionSize);
        q          = new Queue <int>(collectionSize);
        fastList   = new FastListInt(collectionSize);
        arrayClass = System.Array.CreateInstance(typeof(int), collectionSize);

        for (int i = 0; i < numCheckVals; i++)
        {
            checkVals[i] = UnityEngine.Random.Range(0, collectionSize);
        }
        for (int i = 0; i < collectionSize; i++)
        {
            arrayInt[i] = i;
            listInt.Add(i);
            hashset.Add(i);
            dict[i] = i;
            linkedList.AddLast(i);
            stack.Push(i);
            q.Enqueue(i);
            fastList.Add(i);
            arrayClass.SetValue(i, i);
        }
    }
Example #25
0
        public bool delete_log()
        {
            String Record = new string(' ', 200);

            //oCustomer.dsReadFld(cust_channel,cust_sKey,0,"id,flag,company_id",ref arrCustomers);
            arrCustomers.SetValue("3", 1);

            oCustomer.dsExtractRec(cust_channel, cust_sKey, 0, ref Record);
            //oCustomer.dsExtractFld(cust_channel,cust_sKey,0,"id,flag,company_id",ref arrCustomers);

            /*int Update = oCustomer.dsWriteFld(cust_channel,cust_sKey,Record,"id,flag,company_id",ref arrCustomers);
             * if (Update==13)
             *  MessageBox.Show("It couldn't update the file (log)");
             */
            int err = oCustomer.dsRemoveRec(cust_channel, cust_sKey);

            if (err != -1)
            {
                MessageBox.Show(err.ToString());
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #26
0
        /// <summary>
        /// Modifies the specified array by applying the specified function to each element.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="func">object delegate(object o){}</param>
        /// <returns></returns>
        public static void ForEach(Array a, ForEachFunction func)
        {
            long[] ix = new long[a.Rank];
            //Init index
            for (int i = 0; i < ix.Length; i++) ix[i] = a.GetLowerBound(i);

            //Loop through all items
            for (long i = 0; i < a.LongLength; i++)
            {
                a.SetValue(func(a.GetValue(ix)), ix);

                //Increment ix, the index
                for (int j = 0; j < ix.Length; j++)
                {
                    if (ix[j] < a.GetUpperBound(j))
                    {
                        ix[j]++;
                        break; //We're done incrementing.
                    }
                    else
                    {
                        //Ok, reset this one and increment the next.
                        ix[j] = a.GetLowerBound(j);
                        //If this is the last dimension, assert
                        //that we are at the last element
                        if (j == ix.Length - 1)
                        {
                            if (i < a.LongLength - 1) throw new Exception();
                        }
                        continue;
                    }
                }
            }
            return;
        }
		public virtual void CopyTo(Array array, int index)
		{
			foreach (object k in keys)
			{
				array.SetValue(hash[k], index++);
			}
		}
Example #28
0
 public void CopyTo(System.Array array, int index)
 {
     foreach (Resource r in this)
     {
         array.SetValue(r, index++);
     }
 }
Example #29
0
        private void setPixelData(int p, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbIn, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbInBig)
        {
            System.Array pbArr = (System.Array)pbIn.get_PixelData(p);
            for (int r = 0; r < pbIn.Height; r++)
            {
                for (int c = 0; c < pbIn.Width; c++)
                {
                    HashSet <float> hash = new HashSet <float>();
                    for (int rb = 0; rb < rws; rb++)
                    {
                        int nrb = r + rb;
                        for (int cb = 0; cb < clms; cb++)
                        {
                            int    ncb   = c + cb;
                            object objVl = pbInBig.GetVal(p, ncb, nrb);
                            if (objVl != null)
                            {
                                float vl = System.Convert.ToSingle(objVl);
                                hash.Add(vl);
                            }
                        }
                    }

                    pbArr.SetValue(hash.Count, c, r);
                }
            }
            pbIn.set_PixelData(p, pbArr);
        }
Example #30
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //System.Array noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;
                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //Console.WriteLine("After Read");
                int  pBHeight = pPixelBlock.Height;
                int  pBWidth  = pPixelBlock.Width;
                IPnt pbSize   = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)inrsBandsCoef.CreatePixelBlock(pbSize);//independent variables
                inrsBandsCoef.Read(pTlc, (IPixelBlock)outPb);
                int          pBRowIndex   = 0;
                int          pBColIndex   = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                //System.Array[] pArr = new System.Array[outPb.Planes];
                //for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                //{
                //    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                //    pArr[coefnBand] = pixelValues;
                //}
                System.Array pValues = (System.Array)ipPixelBlock.get_PixelData(0);//(System.Array)(td);
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        double[] xVls = new double[outPb.Planes];
                        bool     ndT  = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(coefnBand));
                            object pObj = outPb.GetVal(coefnBand, k, i);

                            if (pObj == null)
                            {
                                ndT = false;
                                break;
                            }
                            float pixelValue = Convert.ToSingle(pObj);
                            xVls[coefnBand] = pixelValue;
                        }
                        if (ndT)
                        {
                            int c = cluster.computNew(xVls);
                            pValues.SetValue(c, k, i);
                        }
                    }
                }
                ipPixelBlock.set_PixelData(0, pValues);
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Cluster Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
Example #31
0
    public void Init()
    {
        arrayInt   = new int[numItems];
        listInt    = new List <int>(numItems);
        hashset    = new HashSet <int>();
        dict       = new Dictionary <int, int>(numItems);
        linkedList = new LinkedList <int>();
        stack      = new Stack <int>(numItems);
        q          = new Queue <int>(numItems);
        fastList   = new FastListInt(numItems);
        arrayClass = System.Array.CreateInstance(typeof(int), numItems);

        for (int i = 0; i < numItems; i++)
        {
            arrayInt[i] = i;
            listInt.Add(i);
            hashset.Add(i);
            dict[i] = i;
            linkedList.AddLast(i);
            stack.Push(i);
            q.Enqueue(i);
            fastList.Add(i);
            arrayClass.SetValue(i, i);
        }
    }
 /// <summary>
 /// Fills the array with an specific value from an specific index to an specific index.
 /// </summary>
 /// <param name="array">The array to be filled.</param>
 /// <param name="fromindex">The first index to be filled.</param>
 /// <param name="toindex">The last index to be filled.</param>
 /// <param name="val">The value to fill the array with.</param>
 public static void Fill(System.Array array, System.Int32 fromindex, System.Int32 toindex, System.Object val)
 {
     System.Object Temp_Object = val;
     System.Type   elementtype = array.GetType().GetElementType();
     if (elementtype != val.GetType())
     {
         Temp_Object = Convert.ChangeType(val, elementtype);
     }
     if (array.Length == 0)
     {
         throw (new System.NullReferenceException());
     }
     if (fromindex > toindex)
     {
         throw (new System.ArgumentException());
     }
     if ((fromindex < 0) || ((System.Array)array).Length < toindex)
     {
         throw (new System.IndexOutOfRangeException());
     }
     for (int index = (fromindex > 0) ? fromindex-- : fromindex; index < toindex; index++)
     {
         array.SetValue(Temp_Object, index);
     }
 }
Example #33
0
 public void CopyTo(int index, System.Array array, int arrayIndex, int count)
 {
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     if (index < 0)
     {
         throw new ArgumentOutOfRangeException("index", "Value is less than zero");
     }
     if (arrayIndex < 0)
     {
         throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
     }
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException("count", "Value is less than zero");
     }
     if (array.Rank > 1)
     {
         throw new ArgumentException("Multi dimensional array.");
     }
     if (index + count > this.Count || arrayIndex + count > array.Length)
     {
         throw new ArgumentException("Number of elements to copy is too large.");
     }
     for (int i = 0; i < count; i++)
     {
         array.SetValue(getitemcopy(index + i), arrayIndex + i);
     }
 }
Example #34
0
        /// <summary>
        /// Creates a System.Array.
        /// </summary>
        /// <param name="serializableData">Reference SerializableData.</param>
        /// <returns>Created array.</returns>
        virtual protected object CreateArray(SerializableData serializableData)
        {
            object data = null;

            try
            {
                Type         type  = GetType(serializableData.SerializableDataCollection[0]);
                System.Array array = System.Array.CreateInstance(type, serializableData.SerializableDataCollection.Count);

                for (int i = 0; i < serializableData.SerializableDataCollection.Count; i++)
                {
                    object internalData = null;
                    if (!IsBaseType(type))
                    {
                        internalData = Compose(serializableData.SerializableDataCollection[i]);
                    }
                    else
                    {
                        internalData = ConvertType(serializableData.SerializableDataCollection[i]);
                    }

                    array.SetValue(internalData, i);
                }

                data = array;

                FillObject(ref data, serializableData);
            }
            catch
            {
                throw new XmlSerializationException(data, serializableData);
            }

            return(data);
        }
Example #35
0
 static public void Copy(System.Array src, int srcLower, int srcUpper, System.Array dest, int destLower, int destUpper)
 {
     for (int i = srcLower, j = destLower; i != srcUpper && j != destUpper; ++i, ++j)
     {
         dest.SetValue(src.GetValue(i), j);
     }
 }
        private void fillHeftArray(int spaceDimension, int histogramResolution, Array array, Array heftArray)
        {
            int cellNO = (int)Math.Pow(histogramResolution, spaceDimension);
            int[] outerIndicesArray = new int[spaceDimension];
            int[] innerIndicesArray = new int[spaceDimension];
            int[] windowIndicesArray = new int[spaceDimension];
            for (int outerCellIdx = 0; outerCellIdx < cellNO; outerCellIdx++)
            {
                transformator.transformCellIdxToIndicesArray(histogramResolution, outerIndicesArray, outerCellIdx);

                for (int innerCellIdx = outerCellIdx; innerCellIdx < cellNO; innerCellIdx++)
                {
                    transformator.transformCellIdxToIndicesArray(histogramResolution, innerIndicesArray, innerCellIdx);
                    int[] heftArrayIndeces;
                    int cellPoints;
                    bool validHeftArrayIndeces = transformator.mergeIndicesArrays(spaceDimension, outerIndicesArray,
                        innerIndicesArray, out heftArrayIndeces, out cellPoints);
                    if (validHeftArrayIndeces)
                    {
                        int cellValue = 0;
                        for (int windowIdx = outerCellIdx; windowIdx <= innerCellIdx; windowIdx++)
                        {
                            transformator.transformCellIdxToIndicesArray(histogramResolution, windowIndicesArray, windowIdx);
                            bool validSummableArrayIndeces = transformator.validateIndicesArrays(spaceDimension,
                                outerIndicesArray, innerIndicesArray, windowIndicesArray);
                            if (validSummableArrayIndeces)
                            {
                                cellValue += (int)array.GetValue(windowIndicesArray);
                            }
                        }
                        heftArray.SetValue(cellValue, heftArrayIndeces);
                    }
                }
            }
        }
Example #37
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object value = environment.GetValue(this.typename);

            Type type = null;

            // TODO create a typed array for IClass instances, not IClassicObject array
            if (!(value is IClass))
            {
                type = TypeUtilities.GetType(environment, this.typename);
            }
            else
            {
                type = typeof(IClassicObject);
            }

            List <object> elements = new List <object>();

            if (this.values != null && this.values.Count > 0)
            {
                foreach (IExpression argument in this.values)
                {
                    elements.Add(argument.Evaluate(environment));
                }
            }

            System.Array array = System.Array.CreateInstance(type, elements.Count);

            for (int k = 0; k < elements.Count; k++)
            {
                array.SetValue(elements[k], k);
            }

            return(array);
        }
Example #38
0
        /// <summary>
        /// Copy the *values* from this list to the given array.
        /// It's not clear from the .Net docs wether this should be
        /// entries or values, so I chose values.
        /// </summary>
        /// <param name="array">The array to copy into</param>
        /// <param name="arrayIndex">The index to start at</param>
        public void CopyTo(System.Array array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (array.Rank != 1)
            {
                throw new ArgumentException("Array must be single dimensional", "array");
            }
            if (arrayIndex < 0)
            {
                throw new ArgumentOutOfRangeException("arrayIndex", "starting index may not be negative");
            }
            if (array.Length - arrayIndex < m_count)
            {
                throw new ArgumentException("Array too small", "array");
            }

            int count = arrayIndex;

            foreach (DictionaryEntry e in this)
            {
                array.SetValue(e.Value, count++);
            }
        }
Example #39
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            double vl         = 0;
            float  pixelValue = 0f;

            try
            {
                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
                #region Load log object
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    float        noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                    System.Array dArr        = (System.Array)pb3.get_PixelData(nBand);
                    for (int r = 0; r < pPixelBlock.Height; r++)
                    {
                        for (int c = 0; c < pPixelBlock.Width; c++)
                        {
                            vl = System.Convert.ToDouble(dArr.GetValue(c, r));
                            if (rasterUtil.isNullData(System.Convert.ToSingle(vl), noDataValue))
                            {
                                continue;
                            }
                            pixelValue = System.Convert.ToSingle(getFunctionValue(vl));
                            dArr.SetValue(pixelValue, c, r);
                        }
                    }
                    pb3.set_PixelData(nBand, dArr);
                    //unsafe
                    //{
                    //    System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
                    //    int lng = dArr.Length;
                    //    fixed (float* dValue = (float[,])dArr)
                    //    {
                    //        for (int i = 0; i < lng; i++)
                    //        {
                    //            pixelValue = *(dValue + i);
                    //            if (rasterUtil.isNullData(pixelValue, noDataValue))
                    //            {
                    //                continue;
                    //            }
                    //            pixelValue = System.Convert.ToSingle(getFunctionValue(pixelValue));
                    //            *(dValue + i) = pixelValue;

                    //        }
                    //        pb3.set_PixelData(nBand, dArr);
                    //    }
                    //}
                }
                #endregion
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method math Function. " + exc.Message, exc);
                throw myExc;
            }
        }
 public virtual void CopyTo(Array array, int index)
 {
     int cElem = this._obj.Length;
     for (int i = 0; i < cElem; ++i)
     {
         array.SetValue(this[i], i + index);
     }
 }
Example #41
0
 internal static void CopyTo(this Dictionary<object, object>.ValueCollection source, Array a, int index)
 {
     int arrayIndex = index;
     foreach (object value in source)
     {
         a.SetValue(value, arrayIndex++);
     }
 }
 public override void CopyTo(Array array, int index)
 {
     if (array == null) throw new ArgumentNullException("array");
     for (var i = 0; i < _parameters.Count; i++)
     {
         array.SetValue(_parameters[i], index + i);
     }
 }
		public void CopyTo(Array array, int index)
		{
			int i = index;
			foreach(MethodInfo mi in this)
			{
				array.SetValue(mi,i++);	
			}
		}
Example #44
0
 static public object Fill <T>(System.Array a, T value)
 {
     for (long i = 0, len = a.GetLongLength(0); i != len; ++i)
     {
         a.SetValue(value, i);
     }
     return(a);
 }
 void ICollection.CopyTo(Array myArr, int index)
 {
     foreach (BlockHistoryObject bho in _collectionArray)
     {
         myArr.SetValue(bho, index);
         index++;
     }
 }
Example #46
0
 static public object Fill <T>(System.Array a, T[] values)
 {
     for (long i = 0; i != values.LongLength; ++i)
     {
         a.SetValue(values[i], i);
     }
     return(a);
 }
        protected override void SortGenericArray(Array items, int left, int right)
        {
            int j;
            int limit = items.Length;
            int st = -1;

            while (st < limit)
            {
                bool flipped = false;
                st++;
                limit--;

                for (j = st; j < limit; j++)
                {
                    if (this.comparer.Compare(items.GetValue(j), items.GetValue(j + 1)) > 0)
                    {
                        object T = items.GetValue(j);
                        items.SetValue(items.GetValue(j + 1), j);
                        items.SetValue(T,j + 1);
                        flipped = true;

                    }
                } // end for

                if (!flipped)
                {
                    return;
                }

                for (j = limit; --j >= st; )
                {
                    if (this.comparer.Compare(items.GetValue(j), items.GetValue(j + 1)) > 0)
                    {
                        object T = items.GetValue(j);
                        items.SetValue(items.GetValue(j + 1), j);
                        items.SetValue(T, j + 1);
                        flipped = true;
                    }
                }

                if (!flipped)
                {
                    return;
                }
            }
        }
Example #48
0
 static public object Fill <T>(System.Array a, int lwr, int upr, T value)
 {
     for (long i = lwr, len = a.GetLongLength(0); i < len && i < upr; ++i)
     {
         a.SetValue(value, i);
     }
     return(a);
 }
 void ICollection.CopyTo(Array array, int index)
 {
     IEnumerator enumerator = ((IEnumerable) this).GetEnumerator();
     while (enumerator.MoveNext())
     {
         array.SetValue(enumerator.Current, index++);
     }
 }
 void ICollection.CopyTo(Array dest, int index)
 {
     int count = this.Count;
     for (int i = 0; i < count; i++)
     {
         dest.SetValue(this[i], index++);
     }
 }
 public void CopyTo(Array array, int index)
 {
     IEnumerator enumerator = this.GetEnumerator();
     while (enumerator.MoveNext())
     {
         array.SetValue(enumerator.Current, index++);
     }
 }
 public virtual void CopyTo(Array array, int index)
 {
     IDictionaryEnumerator enumerator1 = this.ObjectTable.GetEnumerator();
     int num1 = index;
     while (enumerator1.MoveNext())
     {
         array.SetValue(enumerator1.Key, num1++);
     }
 }
Example #53
0
 public RawAnalysisReport(NCCReporter.LMLoggers.LognLM ctrllog)
     : base(ctrllog)
 {
     selectedReportSections = Array.CreateInstance(typeof(bool), System.Enum.GetValues(typeof(RawReportSections)).Length);
     foreach (ValueType v in System.Enum.GetValues(typeof(RawReportSections)))
     {
         selectedReportSections.SetValue(true, (int)v);
     }
 }
Example #54
0
 public override void CopyTo(Array array, int arrayIndex) {
     if (hasNullKey) {
         base.CopyTo(array, arrayIndex + 1);
         array.SetValue(new DictionaryEntry(null, valueOfNullKey), arrayIndex);
     }
     else {
         base.CopyTo(array, arrayIndex);            
     }
 }
Example #55
0
        protected override void SortGenericArray(Array items, int left, int right)
        {
            bool flipped = false;
            int gap, top;
            int i, j;

            gap = items.Length;
            do
            {
                gap = (int)((float)gap / SHRINKFACTOR);

                switch (gap)
                {
                    case 0: /* the smallest gap is 1 - bubble Sort */
                        gap = 1;
                        break;
                    case 9: /* this is what makes this Combsort11 */
                    case 10:
                        gap = 11;
                        break;
                    default: break;
                }

                flipped = false;
                top = items.Length - gap;

                for (i = 0; i < top; i++)
                {

                    j = i + gap;

                    if (this.comparer.Compare(items.GetValue(i), items.GetValue(j)) > 0)
                    {
                        object T = items.GetValue(i);
                        items.SetValue(items.GetValue(j), i);
                        items.SetValue(T, j);
                        flipped = true;
                    }
                }
            } while (flipped || (gap > 1));
            /* like the bubble and shell sorts we check for items clean pass */
        }
 public virtual void CopyTo(Array array, int index)
 {
     for (int i = 0; i < this._keys.Length; i++)
     {
         array.SetValue(this.GetMessageValue(i), (int) (index + i));
     }
     if (this._dict != null)
     {
         this._dict.CopyTo(array, index + this._keys.Length);
     }
 }
Example #57
0
        public void Sirala(Array dizi)
        {
            for (int i = 0; i < dizi.Length - 1; i++)
            {
                for (int j = 0; j < dizi.Length - i - 1; j++)
                {
                    object x = dizi.GetValue(j); // dizi[j]
                    object y = dizi.GetValue(j+1); // dizi[j+1]

                    if (Karsilastir(x, y))
                    {
                        object z = x;
                        x = y;
                        y = z;

                        dizi.SetValue(x, j); // dizi[j] = x;
                        dizi.SetValue(y, j+1); // dizi[j+1] = y;
                    }
                }
            }
        }
 public void CopyTo(Array array, int index)
 {
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     IEnumerator enumerator = this.GetEnumerator();
     while (enumerator.MoveNext())
     {
         array.SetValue(enumerator.Current, index++);
     }
 }
Example #59
0
        protected override void SortGenericArray(Array items, int left, int right)
        {
            int h = 1;
            int length = items.Length;

            // find the largest h value possible
            while ((h * 3 + 1) < length)
            {
                h = 3 * h + 1;
            }

            // while h remains larger than 0
            while (h > 0)
            {

                // for each set of elements (there are h sets)
                for (int i = h - 1; i < length; i++)
                {
                    // pick the last element in the set
                    object B = items.GetValue(i);
                    int j = i;

                    // compare the element at B to the one before it in the set
                    // if they are out of order continue this loop, moving
                    // elements "back" to make room for B to be inserted.
                    for (j = i; (j >= h) && (this.comparer.Compare(items.GetValue(j - h), B) > 0); j -= h)
                    {
                        items.SetValue(items.GetValue(j - h), j);
                    }

                    // insert B into the correct place
                    items.SetValue(B, j);

                } // end for

                // all sets h-sorted, now decrease set size
                h = h / 3;
            }
        }
 public void CopyTo(Array array, int arrayIndex)
 {
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     int index = arrayIndex;
     for (int i = 0; i < this.Count; i++)
     {
         array.SetValue(this[i], index);
         index++;
     }
 }