예제 #1
0
 public override void addChild(AbstractNode child)
 {
     if (child.GetType().Equals(typeof(DefineTypeNode)))
     {
         definitions_.Add(child);
     }
 }
예제 #2
0
 /// <summary>
 /// Add or replace a child DimNode to this one, demote its child if available.
 /// </summary>
 /// <remarks>A DimNode can have only one child DimNode node. When this DimNode already has a child DimNode,
 /// the new child DimNode is set as the only child node and the old child node becomes the child node of the
 /// added child node (grandchild of this node). Note that if the given child node already has a child node,
 /// it will be lost in this case.</remarks>
 /// <param name="child"></param>
 public override void addChild(AbstractNode child)
 {
     if (child.GetType().Equals(typeof(DimNode)))
     {
         DimNode c = this.child_;
         this.child_ = (DimNode)child;
         if (c != null)
         {
             this.child_.setChild(c);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Get image index for the node based on data type.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private int getImageIndex(AbstractNode node)
 {
     Type t = node.GetType();
     if (t==typeof(DefinitionsNode))
     {
         return 2;
     }
     else if (t==typeof(DatasetNode))
     {
         return 3;
     }
     else if (t==typeof(PrimitiveNode))
     {
         return 4;
     }
     else if (t==typeof(StructNode))
     {
         return 5;
     }
     else if (t==typeof(ArrayNode))
     {
         return 6;
     }
     else if (t==typeof(UnionNode))
     {
         return 7;
     }
     else if (t==typeof(UseTypeNode))
     {
         return 8;
     }
     else if (t==typeof(DefineTypeNode))
     {
         Type tb = ((DefineTypeNode)node).getBaseType().GetType();
         if (tb==typeof(StructNode))
         {
             return 5;
         }
         else if (tb==typeof(ArrayNode))
         {
             return 6;
         }
         else if (tb==typeof(UnionNode))
         {
             return 7;
         }
     }
     else if (t==typeof(DimNode))
     {
         return 9;
     }
     else if (t==typeof(CaseNode))
     {
         return 10;
     }
     return 0;
 }
예제 #4
0
        /// <summary>
        /// Add a union data element.
        /// </summary>
        /// <param name="parentNode">parent that contains this union element</param>
        /// <param name="at">position where the new node is inserted before</param>
        /// <param name="defineType">if true invokes a define union type window</param>
        public void addUnionTypeNode(DataNode parentNode, int at, bool defineType)
        {
            FormUnion formUnion = new FormUnion();

            if (defineType)
            {
                formUnion.TypeName = "MyUnionType-" + Convert.ToString(++typeUnionCounter_);
            }
            else
            {
                formUnion.Text = "Build a union element";
                formUnion.ChangeLabel("Var Name:");
                formUnion.TypeName = "myUnion-" + Convert.ToString(parentNode.Nodes.Count);                     //TODO: check for duplicate name
            }
            formUnion.setDataTypeSource(document_.getTypeNames());
            DialogResult r = formUnion.ShowDialog(view_);

            if (r == DialogResult.OK)
            {
                string varName          = formUnion.TypeName;
                string discriminantType = formUnion.DiscriminantType;
                string blockSize        = formUnion.BlockSize;
                int    nBlockSize       = 0;
                try
                {
                    nBlockSize = Convert.ToInt32(blockSize);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                UnionNode un = new UnionNode((defineType)?"":varName);
                un.setDiscriminantType(discriminantType);
                if (nBlockSize > 0)
                {
                    un.setBlockSize(nBlockSize);
                }
                AbstractNode aNode = un;
                if (defineType)
                {
                    aNode = new DefineTypeNode(formUnion.TypeName, un);
                }
                DataNode dn = new DataNode(aNode);

                int n = 0;
                foreach (ListViewItem itm in formUnion.getCases())
                {
                    string sval   = itm.Text;
                    string stype  = itm.SubItems[1].Text;
                    string svname = itm.SubItems[2].Text;
                    if (!stype.Equals(""))
                    {
                        //create a CaseNode
                        CaseNode cn = new CaseNode(sval, null);
                        //add data object as child node and case body of the case node
                        DataNode dcn = new DataNode(cn);
                        addChildNode(dcn, stype, svname);
                        addChildNode(dn, dcn, n++);
                    }
                }
                addChildNode(parentNode, dn, at);
                document_.setModified();
                parentNode.ExpandAll();
            }
        }
예제 #5
0
 public void add(AbstractNode node)
 {
     dataset_.Add(node);
 }
예제 #6
0
 public void remove(AbstractNode node)
 {
     dataset_.RemoveAt(node);
 }
예제 #7
0
 public override void insertChild(AbstractNode child, int at)
 {
     definitions_.Insert(at, child);
 }
예제 #8
0
 public override void insertChild(AbstractNode child, int at)
 {
     dataset_.Insert(at, child);
 }
예제 #9
0
        private AbstractNode caseBody_;         //any type

        public CaseNode(string disVal, AbstractNode body) : base("case")
        {
            this.discriminantValue_ = disVal;
            this.caseBody_          = body;
        }
예제 #10
0
 public void setElement(AbstractNode element)
 {
     element_ = element;
 }
예제 #11
0
 /// <summary>
 /// Check to see whether there's variable-sized construct in an array. These include arrayVariable, arrayStreamed, union, string.
 /// </summary>
 /// <remarks>
 /// This check should apply to the following scenarios:
 /// <list>
 /// Arrays contain arrayVariable, arrayStreamed, or union
 /// Arrays contain struct which contains any of the above three elements
 /// Arrays contain a number of embedded structs at least one of which contains any of the above three elements
 /// Arrays contain arrayFixed which contains one of the above as element
 /// Arrays contain a number of embedded arrayFixed any of which contains any of the above three elements
 /// </list>
 /// </remarks>
 /// <param name="node"></param>
 /// <param name="report"></param>
 private static void checkVariableConstruct(AbstractNode node, ArrayList report)
 {
     if (node.GetType().Equals(typeof(StructNode)))
     {
         foreach (AbstractNode aNode in ((StructNode)node).getMembers())
         {
             if (aNode.isComplex())
             {
                 checkVariableConstruct(aNode, report);
             }
         }
     }
     else if (node.GetType().Equals(typeof(UnionNode)))
     {
         report.Add("Warning: BinX library version 1.x does not support arrays containing union ["+node.toNodeText()+"].");
     }
     else if (node.GetType().Equals(typeof(ArrayNode)))
     {
         ArrayNode aNode = (ArrayNode)node;
         if (aNode.isArrayFixed()==false)
         {
             report.Add("Warning: BinX library version 1.x does not support arrays containing variable-sized arrays ["+aNode.toNodeText()+"].");
         }
         else
         {
             checkVariableConstruct(aNode.getElement(), report);
         }
     }
 }
예제 #12
0
 /// <summary>
 /// Check for duplicate variable names.
 /// </summary>
 /// <remarks>
 /// This check should apply to the following two scenarios:
 /// <list>
 /// Two or more data elements have the same variable name in the Dataset section
 /// Two or more data elements in a struct have the same variable name
 /// </list>
 /// </remarks>
 /// <param name="aNode"></param>
 /// <param name="varNames"></param>
 /// <param name="report"></param>
 private static void checkVarNames(AbstractNode aNode, Hashtable varNames, ArrayList report)
 {
     string sVarName = aNode.getVarName();
     if (sVarName!=null && sVarName.Length > 0)
     {
         if (varNames.Contains(sVarName))
         {
             report.Add("Warning: duplicate variable name '" + sVarName + "' in '" + aNode.toNodeText() + "'.");
         }
         else
         {
             varNames.Add(sVarName, sVarName);
         }
     }
 }
예제 #13
0
 /// <summary>
 /// Check useType node for defined-type reference, or call checkComplexType for complex node.
 /// </summary>
 /// <remarks>
 /// This check should apply to the following scenarios:
 /// <list>
 /// Wherever a useType element is found (in struct, array, union, dataset),
 /// Empty typeName attribute is given for a useType element
 /// The typeName given by the useType element is not already defined before this reference in the definitions section
 /// </list>
 /// </remarks>
 /// <param name="aNode"></param>
 /// <param name="defs"></param>
 /// <param name="report"></param>
 private static void checkUseType(AbstractNode aNode, Hashtable defs, ArrayList report)
 {
     if (aNode.GetType().Equals(typeof(UseTypeNode)))
     {
         string sTypeName = aNode.getTypeName();
         if (sTypeName==null || sTypeName.Length < 1)
         {
             report.Add("Error: invalid type name at '" + aNode.toNodeText() + "'.");
         }
         else if (sTypeName.Equals(typeNameJustDefined))
         {
             report.Add("Error: recursively referencing the type for '" + aNode.toNodeText() + "'.");
         }
         else
         {
             if (!defs.Contains(sTypeName))
             {
                 report.Add("Error: type '" + sTypeName + "' used before defined at '" + aNode.toNodeText() + "'.");
             }
         }
     }
     else if (aNode.isComplex())
     {
         checkComplexType((ComplexNode)aNode, defs, report);
     }
 }
예제 #14
0
 /// <summary>
 /// Method to insert an instance of member at a given position
 /// </summary>
 /// <param name="child">member object to be inserted</param>
 /// <param name="at">position to insert the member</param>
 public override void insertChild(AbstractNode child, int at)
 {
     elements_.Insert(at, child);
 }
예제 #15
0
 /// <summary>
 /// Method to add an instance of member as IType derived class
 /// </summary>
 /// <param name="memberType"></param>
 public override void addChild(AbstractNode memberType)
 {
     elements_.Add(memberType);
 }
예제 #16
0
 /// <summary>
 /// Insert child DimNode as the only child node with position ignored, same as addChild.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at">ignored here</param>
 public override void insertChild(AbstractNode child, int at)
 {
     addChild(child);
     //			if (child.GetType().Equals(typeof(DimNode)))
     //			{
     //				setChild((DimNode)child);
     //			}
 }
예제 #17
0
 /// <summary>
 /// Overrided method actually to set the case body node.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at"></param>
 public override void insertChild(AbstractNode child, int at)
 {
     caseBody_ = child;
 }
예제 #18
0
 public virtual void insertChild(AbstractNode child, int at)
 {
 }
예제 #19
0
 /// <summary>
 /// Override insertChild to add only element node, dim node won't be added.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at"></param>
 public override void insertChild(AbstractNode child, int at)
 {
     if (!child.GetType().Equals(typeof(DimNode)))
     {
         setElement(child);
     }
     else
     {
         if (dim_ != null)
         {
             ((DimNode)child).setChild(dim_);
         }
         dim_ = (DimNode)child;
     }
 }
예제 #20
0
 public virtual void addChild(AbstractNode child)
 {
 }
예제 #21
0
 public void setElement(AbstractNode element)
 {
     element_ = element;
 }
예제 #22
0
        private string discriminantValue_; //as a string

        #endregion Fields

        #region Constructors

        public CaseNode(string disVal, AbstractNode body)
            : base("case")
        {
            this.discriminantValue_ = disVal;
            this.caseBody_ = body;
        }
예제 #23
0
 public void setSizeRef(AbstractNode sizeRef)
 {
     sizeRef_ = sizeRef;
 }
예제 #24
0
 public void addDataset(AbstractNode node)
 {
     dataset_.addChild(node);
 }
예제 #25
0
 public ArrayNode(string typeName, string varName, AbstractNode element)
     : base(typeName, varName)
 {
     element_ = element;
 }
예제 #26
0
 public void insert(int index, AbstractNode node)
 {
     dataset_.Insert(index, node);
 }
예제 #27
0
 /// <summary>
 /// Method to add an instance of member as IType derived class
 /// </summary>
 /// <param name="memberType"></param>
 public override void addChild(AbstractNode memberType)
 {
     elements_.Add(memberType);
 }
예제 #28
0
 public void setDataNode(AbstractNode val)
 {
     dataNode_ = val;
     this.Text = dataNode_.toNodeText();
 }
예제 #29
0
 /// <summary>
 /// Method to insert an instance of member at a given position
 /// </summary>
 /// <param name="child">member object to be inserted</param>
 /// <param name="at">position to insert the member</param>
 public override void insertChild(AbstractNode child, int at)
 {
     elements_.Insert(at, child);
 }
예제 #30
0
 public DataNode(AbstractNode dataNode)
 {
     this.dataNode_ = dataNode;
     this.Text = dataNode.toNodeText();
     this.ImageIndex = this.SelectedImageIndex = getImageIndex(dataNode);
 }
예제 #31
0
 public void addDataset(AbstractNode node)
 {
     dataset_.addChild(node);
 }
예제 #32
0
        /// <summary>
        /// Add an array data element.
        /// </summary>
        /// <param name="parentNode">parent node that contains this new node</param>
        /// <param name="at">position before which the new node is inserted</param>
        public void addArrayTypeNode(DataNode parentNode, int at, bool defineType)
        {
            FormArray formArray = new FormArray();

            if (!defineType)
            {
                formArray.Text = "Build an array element";
                formArray.ChangeLabel("Var Name:");
                formArray.TypeName = "myArray-" + Convert.ToString(parentNode.Nodes.Count);                     //TODO: check for duplicate names
            }
            else
            {
                formArray.TypeName = "MyArray-" + Convert.ToString(++typeArrayCounter_);
            }
            formArray.DataTypeSource = document_.getTypeNames();
            DialogResult r = formArray.ShowDialog(view_);

            if (r == DialogResult.OK)
            {
                string    varName   = formArray.TypeName;
                string    arrayType = formArray.ArrayTypeName;
                ArrayNode an        = new ArrayNode(arrayType, (defineType)?"":varName);
                //if variable, add sizeRef
                if (formArray.ArrayType == 2)
                {
                    AbstractNode data = new PrimitiveNode(formArray.SizeRef);
                    an.setSizeRef(data);
                }
                AbstractNode aNode = an;
                if (defineType)
                {
                    aNode = new DefineTypeNode(formArray.TypeName, an);
                }
                DataNode dn = new DataNode(aNode);
                addChildNode(dn, formArray.DataType, "");     //element data type as first child node of array
                if (formArray.ArrayType == 3)                 //arrayStreamed containing only one dim
                {
                    //an.addDimension("", 0);
                    addChildNode(dn, new DataNode(new DimNode("", 0)), 1); //dim as second child node of array
                }
                else                                                       //fixed or variable
                {
                    DataNode tmpNode = dn;
                    foreach (ListViewItem itm in formArray.getDimensions())
                    {
                        string scount   = itm.Text;
                        string sdimname = itm.SubItems[1].Text;
                        if (!scount.Equals(""))
                        {
                            //DataNode dNode = new DataNode(an.addDimension(sdimname, scount));
                            DataNode dNode = new DataNode(new DimNode(sdimname, scount));
                            addChildNode(tmpNode, dNode, 1);
                            tmpNode = dNode;
                        }
                    }
                }
                addChildNode(parentNode, dn, at);
                document_.setModified();
                parentNode.ExpandAll();
            }
        }
예제 #33
0
 public void setDataNode(AbstractNode val)
 {
     dataNode_ = val;
     this.Text = dataNode_.toNodeText();
 }
예제 #34
0
 /// <summary>
 /// Same as insertCase
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at"></param>
 public override void insertChild(AbstractNode child, int at)
 {
     insertCase(at, (CaseNode)child);
 }
예제 #35
0
 public virtual void addChild(AbstractNode child)
 {
 }
예제 #36
0
 public DataNode(AbstractNode dataNode)
 {
     this.dataNode_  = dataNode;
     this.Text       = dataNode.toNodeText();
     this.ImageIndex = this.SelectedImageIndex = getImageIndex(dataNode);
 }
예제 #37
0
 /// <summary>
 /// Same as addCase
 /// </summary>
 /// <param name="child"></param>
 public override void addChild(AbstractNode child)
 {
     addCase((CaseNode)child);
 }
예제 #38
0
 public ArrayNode(string typeName, string varName, AbstractNode element) : base(typeName, varName)
 {
     element_ = element;
 }
예제 #39
0
 public override void insertChild(AbstractNode child, int at)
 {
     definitions_.Insert(at, child);
 }
예제 #40
0
 public void setSizeRef(AbstractNode sizeRef)
 {
     sizeRef_ = sizeRef;
 }
예제 #41
0
 public override void insertChild(AbstractNode child, int at)
 {
     dataset_.Insert(at, child);
 }
예제 #42
0
 public virtual void insertChild(AbstractNode child, int at)
 {
 }
예제 #43
0
 public override void addChild(AbstractNode node)
 {
     dataset_.Add(node);
 }
예제 #44
0
 /// <summary>
 /// Same as insertCase
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at"></param>
 public override void insertChild(AbstractNode child, int at)
 {
     insertCase(at, (CaseNode)child);
 }
예제 #45
0
 /// <summary>
 /// Same as addCase
 /// </summary>
 /// <param name="child"></param>
 public override void addChild(AbstractNode child)
 {
     addCase((CaseNode)child);
 }
예제 #46
0
 /// <summary>
 /// Overrided method actually to set the case body node.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at"></param>
 public override void insertChild(AbstractNode child, int at)
 {
     caseBody_ = child;
 }
예제 #47
0
 public override void addChild(AbstractNode node)
 {
     dataset_.Add(node);
 }