//============================================================================
 /// <summary>
 ///
 /// </summary>
 /// <param name="aParent"></param>
 /// <param name="aSpecifier"></param>
 //============================================================================
 public TValTree(TValTree aParent, TMainOutputSpecifier aSpecifier)
 {
     parent    = aParent;
     specifier = aSpecifier;
     varId     = -1;
     colNo     = -1;
     index     = 0;
     subTrees  = new List <TValTree>();
 }
Example #2
0
 ////============================================================================
 /// <summary>
 ///
 /// </summary>
 /// <param name="valTree"></param>
 /// <param name="sortOrder"></param>
 /// <param name="colI"></param>
 ////============================================================================
 private void AddSortedIndexes(TValTree valTree, ref List <int> sortOrder, ref int colI)
 {
     if (valTree.colNumber >= 0)
     {
         sortOrder.Add(valTree.colNumber);
         colI++;
     }
     for (int i = 0; i <= valTree.subTrees.Count - 1; i++)
     {
         AddSortedIndexes(valTree.subTrees[i], ref sortOrder, ref colI);
     }
 }
        //==============================================================================
        /// <summary>
        /// Recursive logic for the AggregateValues routine
        /// For a scalar value, finds the corresponding output column and updates it.
        /// For an array or collection, recurses into each element or member.
        /// </summary>
        /// <param name="aValue"></param>
        /// <param name="aTree"></param>
        //==============================================================================
        private void aggregateValue(TTypedValue aValue, TValTree aTree)
        {
            int iColNo;
            int i;
            int oldLen;
            int parentId;

            if (aTree.varId < 0)
            { // Hasn't been defined yet...
                if (aTree.parent != null)
                {
                    parentId = aTree.parent.varId;
                }
                else
                {
                    parentId = -1;
                }
                aTree.varId = defineVariable(aTree.FullColumnName(), (TDDMLValue)aValue, parentId, (int)aTree.index, aTree.specifier);
            }

            if (aValue.isScalar())     // Scalar - we store or summarise the
            {                          //  data
                if (aTree.colNo < 0)   // Doesn't have a column number yet...
                {
                    aTree.colNo = FColumns.Count;
                    TOutputScalar aScalar = new TOutputScalar(aValue, aTree.specifier.Aggreg, aTree.specifier.iDecPl);
                    aScalar.Name = aTree.FullColumnName();
                    FColumns.Add(aScalar);
                }
                iColNo = aTree.colNo;
                FColumns[iColNo].Update(aValue);
            }
            else       // Array or collection - recurse
            {
                if (aValue.count() > aTree.subTrees.Count)
                {  // Need to add new subTrees
                    oldLen = aTree.subTrees.Count;
                    //SetLength(aTree.subTrees, aValue.count());
                    for (i = oldLen; i < aValue.count(); i++)
                    //for (i = oldLen; i <= aTree.subTrees.Count - 1; i++)
                    {
                        aTree.subTrees.Add(new TValTree(aTree, aTree.specifier));
                        aTree.subTrees[i].index = (uint)i + 1;
                        if (aValue.isArray())
                        {
                            aTree.subTrees[i].columnName = "[" + aTree.subTrees[i].index.ToString() + "]";
                        }
                        else
                        {
                            if (aValue.isRecord())
                            {
                                aTree.subTrees[i].columnName = ":" + aValue.item((uint)aTree.subTrees[i].index).Name;
                            }
                        }
                        aTree.subTrees[i].varId = defineVariable(aTree.subTrees[i].FullColumnName(),
                                                                 (TDDMLValue)(aValue.item(aTree.subTrees[i].index)),
                                                                 aTree.varId, (int)aTree.subTrees[i].index,
                                                                 aTree.subTrees[i].specifier);
                    }
                }
                for (i = 1; i <= aValue.count(); i++)
                {
                    aggregateValue(aValue.item((uint)i), aTree.subTrees[i - 1]);
                }
            }
        }