/// <summary> /// Tertiary constructor used for twin/duplicate XML Definitions within a file. /// </summary> /// <param name="xmlElement">The differing XML Element for this twin.</param> /// <param name="parentTree">he parent XML tree.</param> /// <param name="twinTree">The original XML tree.</param> private XmlCookedTree(XmlCookedElement xmlElement, XmlCookedTree parentTree, XmlCookedTree twinTree) { _element = xmlElement; Parent = parentTree; Definition = twinTree.Definition; _twinTree = twinTree; }
/// <summary> /// Secondary constructor used for child node types. /// </summary> /// <param name="xmlDefinition">The child tree XML Definition.</param> /// <param name="xmlElement">The XML Element type (should be of .ElementType = Table or TableCount).</param> /// <param name="parentTree">The parent XML tree.</param> /// <param name="elementCount">Count of elements in this definition in this XML File.</param> public XmlCookedTree(XmlCookedDefinition xmlDefinition, XmlCookedElement xmlElement, XmlCookedTree parentTree, int elementCount) { Definition = xmlDefinition; _element = xmlElement; Parent = parentTree; Count = elementCount; _elements = new Dictionary <uint, Branch>(); }
/// <summary> /// Secondary constructor used for child node types. /// </summary> /// <param name="xmlDefinition">The child tree XML Definition.</param> /// <param name="xmlElement">The XML Element type (should be of .ElementType = Table or TableCount).</param> /// <param name="parentTree">The parent XML tree.</param> /// <param name="elementCount">Count of elements in this definition in this XML File.</param> public XmlCookedTree(XmlCookedDefinition xmlDefinition, XmlCookedElement xmlElement, XmlCookedTree parentTree, int elementCount) { Definition = xmlDefinition; _element = xmlElement; Parent = parentTree; Count = elementCount; _elements = new Dictionary<uint, Branch>(); }
/// <summary> /// Replaces last added element with tree. Automatically links the XML Element to tree. /// </summary> /// <param name="definitionHash">The element name hash of the existing tree.</param> public void AddExistingTree(UInt32 definitionHash) { XmlCookedTree tree = _GetExistingTree(Root, definitionHash); Debug.Assert(tree != null, "AddExistingTree: tree not found!"); tree = tree.TwinRoot; Debug.Assert(tree != null, "AddExistingTree: tree not found!"); XmlCookedElement xmlElement = _elements.Last().Value.Element; XmlCookedTree newTree = new XmlCookedTree(xmlElement, this, tree); AddTree(newTree); }
/// <summary> /// Get an already defined definition. /// </summary> /// <param name="xmlTree"></param> /// <param name="elementHash"></param> /// <returns></returns> private static XmlCookedTree _GetExistingTree(XmlCookedTree xmlTree, UInt32 elementHash) { foreach (Branch branch in xmlTree._elements.Select(keyValuePair => keyValuePair.Value)) { if (branch.Tree == null) { continue; } if (branch.Tree.DefinitionHash == elementHash) { return(branch.Tree); } XmlCookedTree existingTree = _GetExistingTree(branch.Tree, elementHash); if (existingTree != null) { return(existingTree); } } return(null); }
public Branch(XmlCookedElement element, XmlCookedTree tree = null) { Element = element; Tree = tree; }
/// <summary> /// Replaces last added element with tree. /// </summary> /// <param name="xmlCookedFileTree">The tree to the previous element.</param> public void AddTree(XmlCookedTree xmlCookedFileTree) { _elements[_elements.Last().Key] = new Branch(xmlCookedFileTree._element, xmlCookedFileTree); }
public Branch(XmlCookedElement element, XmlCookedTree tree=null) { Element = element; Tree = tree; }
/// <summary> /// Get an already defined definition. /// </summary> /// <param name="xmlTree"></param> /// <param name="elementHash"></param> /// <returns></returns> private static XmlCookedTree _GetExistingTree(XmlCookedTree xmlTree, UInt32 elementHash) { foreach (Branch branch in xmlTree._elements.Select(keyValuePair => keyValuePair.Value)) { if (branch.Tree == null) continue; if (branch.Tree.DefinitionHash == elementHash) return branch.Tree; XmlCookedTree existingTree = _GetExistingTree(branch.Tree, elementHash); if (existingTree != null) return existingTree; } return null; }