/// <summary> /// Add cases to a union node in the treeview from loaded document. /// </summary> /// <remarks> /// The TypeNode for UnionCase object node has null reference for DataNode. /// TODO: union containing arrays not supported here /// </remarks> /// <param name="node"></param> /// <param name="t"></param> protected void addUnionNode(TreeNode node, UnionNode t) { foreach (CaseNode c in t.getCases()) { DataNode dt = new DataNode(c); node.Nodes.Add(dt); //node.LastNode.Text = c.toNodeText(); AbstractNode caseBody = c.getCaseBody(); TreeNode caseNode = node.LastNode; caseNode.Nodes.Add(new DataNode(caseBody)); if (caseBody.isComplex()) { if (caseBody.GetType().Equals(typeof(StructNode))) { addStructNode(caseNode.LastNode, (StructNode)caseBody); } else if (caseBody.GetType().Equals(typeof(UnionNode))) { addUnionNode(caseNode.LastNode, (UnionNode)caseBody); } else if (caseBody.GetType().Equals(typeof(ArrayNode))) { addArrayNode(caseNode.LastNode, (ArrayNode)caseBody); } } } }
/// <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); } } }
/// <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); } }
public override void addChild(AbstractNode child) { if (child.GetType().Equals(typeof(DefineTypeNode))) { definitions_.Add(child); } }
/// <summary> /// Add a dim node to array node or another dim node, if one is available, it is replaced. /// </summary> /// <remarks>If parent node is the ArrayNode or DefineTypeNode of ArrayNode, then /// the new DimNode will replace the original DimNode which is then indented (demoted as the grandchild. /// If the parent node is a DimNode, then its child node is replaced and degraded, or if no child node /// exists, the new node is added as the child.</remarks> /// <param name="parentNode"></param> /// <param name="at"></param> public void addDimNode(DataNode parentNode, int at) { AbstractNode dNode = parentNode.getDataNode(); if (dNode.GetType().Equals(typeof(DefineTypeNode))) { dNode = ((DefineTypeNode)dNode).getBaseType(); } FormDim formDim = new FormDim(); DialogResult r = formDim.ShowDialog(view_); if (r == DialogResult.OK) { string sdname = formDim.DimName; string scount = formDim.DimCount; DimNode dimNode = new DimNode(sdname, scount); ((ComplexNode)dNode).insertChild(dimNode, 0); //at irrelevant for array and dim node DataNode d = new DataNode(dimNode); DataNode old = (DataNode)parentNode.LastNode; if (old != null) { parentNode.Nodes.Remove(old); d.Nodes.Add(old); } parentNode.Nodes.Add(d); parentNode.ExpandAll(); } }
/// <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); }
/// <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); } } }
/// <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; } }
public bool isTypeDef() { return((dataNode_ != null)?dataNode_.GetType().Equals(typeof(DefineTypeNode)):false); }
/// <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; }
/// <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); } } }
/// <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); } }