private void AddNewObject(ImportObject newEntry) // will set current and add to m_opennodes hash { #if TracingOutput System.Diagnostics.Debug.WriteLine("Mgr::AddNewObject: " + newEntry.AncestorLongNames()); #endif // make sure there aren't any children nodes of the new entry at the same level as the newEntry RemoveChildrenForNewImportObject(newEntry.Parent, newEntry.Name, m_converter.m_HierarchyChildren, newEntry); // make sure there aren't any open like nodes at the same level foreach (ImportObject child in newEntry.Parent.Children) { if (child == newEntry) // don't close the one we just added! continue; if (child.Name == newEntry.Name) { if (!child.Closed) CloseImportObject(child); } } m_current = newEntry; #if TracingOutput System.Diagnostics.Debug.WriteLine(" Mgr::Current = " + m_current.AncestorLongNames()); #endif if (m_OpenNodes.ContainsKey(newEntry.Name)) { ArrayList nodes = m_OpenNodes[newEntry.Name] as ArrayList; nodes.Add(newEntry); } else { ArrayList nodes = new ArrayList(); nodes.Add(newEntry); m_OpenNodes.Add(newEntry.Name, nodes); } }
/// ------------------------------------------------------------------ /// Rules for knowing where to add new classes (Entry, Sense, ...) /// This set of rules is for adding a new entry (sfm was begin marker) /// ------------------------------------------------------------------- /// 1 - if the current entry starts with this sfm /// + if it doesn't have one then use it here as this must have been 'guessed' to start. /// else the current entry can't take this sfm, close it and add a new one /// 2 - find all possible parents for this element /// 3 - if one or more of the parents are open in the tree /// + use the parent with the largest depth and add the child there /// else /// + create a parent tree for this entry (root:entry:sense:...) /// + use the current open entries and remove from root as far as possible /// what remains should be added and the child added at the end /// /// Rules for determining where to add a marker when it isn't a begin marker /// ------------------------------------------------------------------ /// 1 - if the current entry can take the marker, add it here /// 2 - starting at the deepest level, look for an entry that can take the marker /// + if an entry is found, add it here /// else /// pretend it starts an entry and process as a begin marker /// /// ------------------------------------------------------------------ public bool CanUseBeginMarkerOnExistingEntry(string entryName, string sfm, byte[] sfmData, int line, bool isUnique) { if (m_OpenNodes.ContainsKey(entryName)) { ImportObject rval = null; ArrayList objs = m_OpenNodes[entryName] as ArrayList; foreach (ImportObject posParent in objs) { if (posParent.Closed) continue; // just to make sure there aren't any closed items in the open list if (rval == null || rval.Depth < posParent.Depth) rval = posParent; } if (rval != null && rval.CanAddBeginSFM(sfm, m_converter)) { rval.AddBeginSFM(sfm,sfmData, line, m_converter); m_current = rval; #if TracingOutput System.Diagnostics.Debug.WriteLine(" Mgr::Current = " + m_current.AncestorLongNames()); #endif return true; } } return false; }
private Hashtable m_OpenNodes; // hash of nodes currently open on the tree: key="name"(ex:"entry") value="arraylist of ImportObjects" // private bool m_outputHasStarted = false; public ImportObjectManager(string rootName, Converter conv) { m_root = new ImportObject(rootName, null); m_current = m_root; #if TracingOutput System.Diagnostics.Debug.WriteLine(" Mgr::Current = " + m_current.AncestorLongNames()); #endif m_converter = conv; m_OpenNodes = new Hashtable(); ArrayList rootLevel = new ArrayList(); rootLevel.Add(m_root); m_OpenNodes.Add(rootName, rootLevel); }