public void Reset()
        {
            CurrentCollectionItem = RootItem;
            RootItem.ChildItems.Clear();
            RootItem.CollectionType = 0;

            GlobalItemStateStack.Clear();
            GlobalItemStateStack.Add(new Dictionary <GlobalItemTag, EncodedItem>());
            LocalItemState.Clear();
        }
        /// <summary>
        /// Parses a single <see cref="EncodedItem"/>.
        /// Call this repeatedly for every item to completely decode a report descriptor.
        /// </summary>
        /// <param name="item">The item to parse.</param>
        public void Parse(EncodedItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            uint value = item.DataValue;

            switch (item.Type)
            {
            case ItemType.Main:
                ParseMain(item.TagForMain, value);
                LocalItemState.Clear();
                break;

            case ItemType.Local:
                switch (item.TagForLocal)
                {
                case LocalItemTag.Usage:
                case LocalItemTag.UsageMinimum:
                case LocalItemTag.UsageMaximum:
                    if (value <= 0xffff)
                    {
                        value |= GetGlobalItemValue(GlobalItemTag.UsagePage) << 16;
                    }
                    break;
                }
                LocalItemState.Add(new KeyValuePair <LocalItemTag, uint> (item.TagForLocal, value));
                break;

            case ItemType.Global:
                switch (item.TagForGlobal)
                {
                case GlobalItemTag.Push:
                    GlobalItemStateStack.Add(new Dictionary <GlobalItemTag, EncodedItem> (GlobalItemState));
                    break;

                case GlobalItemTag.Pop:
                    GlobalItemStateStack.RemoveAt(GlobalItemState.Count - 1);
                    break;

                default:
                    switch (item.TagForGlobal)
                    {
                    case GlobalItemTag.ReportID:
                        ReportsUseID = true;
                        break;
                    }

                    GlobalItemState[item.TagForGlobal] = item;
                    break;
                }
                break;
            }
        }
        /// <summary>
        /// Resets the parser to its initial state.
        /// </summary>
        public void Clear()
        {
            CurrentCollection = RootCollection;
            RootCollection.Clear();

            GlobalItemStateStack.Clear();
            GlobalItemStateStack.Add(new Dictionary <GlobalItemTag, EncodedItem> ());
            LocalItemState.Clear();
            Reports.Clear();
            ReportsUseID = false;
        }