public override void addChild(AbstractNode child) { if (child.GetType().Equals(typeof(DefineTypeNode))) { definitions_.Add(child); } }
/// <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> /// 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 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(); } }
public void add(AbstractNode node) { dataset_.Add(node); }
public void remove(AbstractNode node) { dataset_.RemoveAt(node); }
public override void insertChild(AbstractNode child, int at) { definitions_.Insert(at, child); }
public override void insertChild(AbstractNode child, int at) { dataset_.Insert(at, child); }
private AbstractNode caseBody_; //any type public CaseNode(string disVal, AbstractNode body) : base("case") { this.discriminantValue_ = disVal; this.caseBody_ = body; }
public void setElement(AbstractNode element) { element_ = element; }
/// <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 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); } } }
/// <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); } }
/// <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); }
/// <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); }
/// <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); // } }
/// <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; }
public virtual void insertChild(AbstractNode child, int at) { }
/// <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 virtual void addChild(AbstractNode child) { }
private string discriminantValue_; //as a string #endregion Fields #region Constructors public CaseNode(string disVal, AbstractNode body) : base("case") { this.discriminantValue_ = disVal; this.caseBody_ = body; }
public void setSizeRef(AbstractNode sizeRef) { sizeRef_ = sizeRef; }
public void addDataset(AbstractNode node) { dataset_.addChild(node); }
public ArrayNode(string typeName, string varName, AbstractNode element) : base(typeName, varName) { element_ = element; }
public void insert(int index, AbstractNode node) { dataset_.Insert(index, node); }
public void setDataNode(AbstractNode val) { dataNode_ = val; this.Text = dataNode_.toNodeText(); }
public DataNode(AbstractNode dataNode) { this.dataNode_ = dataNode; this.Text = dataNode.toNodeText(); this.ImageIndex = this.SelectedImageIndex = getImageIndex(dataNode); }
/// <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(); } }
/// <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); }
/// <summary> /// Same as addCase /// </summary> /// <param name="child"></param> public override void addChild(AbstractNode child) { addCase((CaseNode)child); }
public override void addChild(AbstractNode node) { dataset_.Add(node); }