예제 #1
0
 /// <summary>
 ///   Remove an inner element to this CppElement
 /// </summary>
 /// <param name = "element"></param>
 public void Remove(CppElement element)
 {
     element.Parent = null;
     if (Items != null)
     {
         Items.Remove(element);
     }
 }
예제 #2
0
 /// <summary>
 ///   Add an inner element to this CppElement
 /// </summary>
 /// <param name = "element"></param>
 public void Add(CppElement element)
 {
     if (element.Parent != null)
     {
         element.Parent.Remove(element);
     }
     element.Parent = this;
     GetSafeItems().Add(element);
 }
예제 #3
0
        /// <summary>
        ///   Add an inner element to this CppElement
        /// </summary>
        /// <param name = "element"></param>
        public void Add(CppElement element)
        {
            if (element.Parent != null)
            {
                element.Parent.Remove(element);
            }
            element.Parent = this;
            if (Items == null)
            {
                Items = new List <CppElement>();
            }

            Items.Add(element);
        }
예제 #4
0
        /// <summary>
        /// Finds the specified elements by regex.
        /// </summary>
        /// <typeparam name="T">The type of element to find</typeparam>
        /// <param name="currentNode">The current node in the search.</param>
        /// <param name="regex">The regex.</param>
        /// <param name="mode">The selection mode.</param>
        /// <returns>The selected elements.</returns>
        private IEnumerable <T> Find <T>(CppElement currentNode, Regex regex, SelectionMode mode) where T : CppElement
        {
            var path = currentNode.FullName;

            CppElement selectedElement;

            switch (mode)
            {
            case SelectionMode.MatchedElement:
                selectedElement = currentNode;
                break;

            case SelectionMode.Parent:
                selectedElement = currentNode.Parent;
                break;

            default:
                throw new ArgumentException("Invalid selection mode.", nameof(mode));
            }

            if (path != null && (selectedElement is T cppElement) && regex.Match(path).Success)
            {
                yield return(cppElement);
            }

            if (currentNode == Root && CurrentContexts.Count != 0)
            {
                // Optimized version with context attributes
                foreach (var innerElement in currentNode.AllItems.Where(element => CurrentContexts.Contains(element.Name)))
                {
                    foreach (var item in Find <T>(innerElement, regex, mode))
                    {
                        yield return(item);
                    }
                }
            }
            else
            {
                foreach (var innerElement in currentNode.AllItems)
                {
                    foreach (var item in Find <T>(innerElement, regex, mode))
                    {
                        yield return(item);
                    }
                }
            }
        }
예제 #5
0
 public CppElementFinder(CppElement root)
 {
     Root = root;
 }
예제 #6
0
 /// <summary>
 ///   Remove an inner element to this CppElement
 /// </summary>
 /// <param name = "element"></param>
 public void Remove(CppElement element)
 {
     element.Parent = null;
     GetSafeItems().Remove(element);
 }