Esempio n. 1
0
        /// <summary>
        /// Returns an array of the indicies of the locations of desired attributes
        /// </summary>
        /// <param name="attr">The attributes for which we are finding the indicies</param>
        /// <param name="elements">The GBase elements that show the structure of data</param>
        /// <returns>An array of indicies parallel to the desired attributes, specifying where they are in the structure</returns>
        public int[] GetIndiciesOfAttributesFromGBaseElements(String[] attr, GBaseElement[] elements)
        {
            int[] result = new int[attr.Length];            // Make a new array that will store the indicies

            for (int k = 0; k < attr.Length; k++)           // For all elements in attributes
                for (int i = 0; i < elements.Length; i++)   // For all elements in elements
                    if (elements[i].Name == attr[k])        // If we find the location of the corrisponding element in the structure
                        result[k] = i;                      // Then add it to the array

            return result;                                  // Return the array
        }
Esempio n. 2
0
        /// <summary>
        /// Converts an array of GBaseElements into a string (by element name)
        /// </summary>
        /// <param name="elements">What to convert</param>
        /// <returns>An array of strings converted from the GBase elements</returns>
        private String[] GBaseElementsToStrings(GBaseElement[] elements)
        {
            String[] temp = new String[elements.Length];        // Make a new string array to hold the values
            for (int i = 0; i < elements.Length; i++)           // For each thing in elements
                temp[i] = elements[i].Name;                     // Add that thing to the temp string array

            return temp;                                        // Return the temp string array
        }
Esempio n. 3
0
 /// <summary>
 /// Makes sure that the passed attributes are a subset of the passed elements
 /// </summary>
 /// <param name="attr">What will be checked as a subset</param>
 /// <param name="elements">What will be checked as a parent set</param>
 /// <returns>True if the attributes are a subset, false elsewise</returns>
 public bool AttrsSubsetOfFieldNames(String[] attr, GBaseElement[] elements)
 {
     return !attr.Except(GBaseElementsToStrings(elements)).Any();    // If the set difference doesn't have any elements (they are same) return true, else fails
 }
Esempio n. 4
0
        /// <summary>
        /// Sorts a given array of values in the order of the matching elements
        /// </summary>
        /// <param name="attrs">The attributes that corrispond to the values</param>
        /// <param name="values">The values to be sorted</param>
        /// <param name="elements">What is being sorted with dues to</param>
        public void SortValuesDueToFieldNames(String[] attrs, ref String[] values, GBaseElement[] elements)
        {
            String[] temp = new String[elements.Length];        // Will store the values
            for (int i = 0; i < elements.Length; i++)           // Loop each element
            {
                for (int k = 0; k < attrs.Length; k++)      // Foreach element find where it ought to go
                {
                    if (attrs[k] == elements[i].Name)
                        temp[i] = values[k];                // Put it there (in temp)
                }
            }

            values = temp;                                  // Values becomes temp
        }