Наша сборка Qt VS Tools
giy
2022-06-13 175679ae608f0b295d761588d332f635b21bdf30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt VS Tools.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Debugger.Interop;
 
namespace QtVsTools.Qml.Debug.AD7
{
    /// <summary>
    /// Abstraction of AD7 enum interfaces, e.g. IEnumDebugPrograms2
    /// (cf. https://docs.microsoft.com/en-us/visualstudio/extensibility/debugger/reference/ienumdebugprograms2)
    /// </summary>
    ///
    class Enum<T, TEnum, IEnum>
        where TEnum : Enum<T, TEnum, IEnum>, new()
        where IEnum : class
    {
        int index;
        IList<T> list;
 
        public static TEnum Create(IEnumerable<T> data)
        {
            return new TEnum
            {
                index = 0,
                list = new List<T>(data)
            };
        }
 
        public static TEnum Create(T singleElement)
        {
            return new TEnum
            {
                index = 0,
                list = new List<T>() { singleElement }
            };
        }
 
        public static TEnum Create()
        {
            return new TEnum
            {
                index = 0,
                list = new List<T>()
            };
        }
 
        protected Enum()
        { }
 
        /// <summary>
        /// Returns the next set of elements from the enumeration.
        /// </summary>
        /// <param name="numElems">The number of elements to retrieve.</param>
        /// <returns>
        /// Collection of retrieved elements.
        /// </returns>
        public IEnumerable<T> Next(uint numElems)
        {
            int oldIndex = index;
            int maxIndex = Math.Min(list.Count, oldIndex + (int)numElems);
            for (; index < maxIndex; ++index)
                yield return list[index];
        }
 
        /// <summary>
        /// Returns the next set of elements from the enumeration.
        /// </summary>
        /// <param name="numElems">
        /// The number of elements to retrieve.
        /// </param>
        /// <param name="elems">
        /// Array of elements to be filled in.
        /// </param>
        /// <param name="numElemsFetched">
        /// Returns the number of elements actually returned in elems.
        /// </param>
        /// <returns>
        /// If successful, returns S_OK. Returns S_FALSE if fewer than the requested number of
        /// elements could be returned.
        /// </returns>
        public int Next(uint numElems, T[] elems, ref uint numElemsFetched)
        {
            var next = Next(numElems).ToArray();
            Array.Copy(next, elems, next.Length);
            numElemsFetched = (uint)next.Length;
            if (numElemsFetched < numElems)
                return VSConstants.S_FALSE;
            return VSConstants.S_OK;
        }
 
        /// <summary>
        /// Skips over the specified number of elements.
        /// </summary>
        /// <param name="numElems">Number of elements to skip.</param>
        /// <returns>
        /// If successful, returns S_OK. Returns S_FALSE if numElems is greater than the number of
        /// remaining elements; otherwise, returns an error code.
        /// </returns>
        /// <remarks>
        /// If numElems specifies a value greater than the number of remaining elements, the
        /// enumeration is set to the end and S_FALSE is returned.
        /// </remarks>
        public int Skip(uint numElems)
        {
            if ((ulong)index + numElems > Int32.MaxValue)
                return VSConstants.E_INVALIDARG;
            if (index + numElems > list.Count) {
                index = list.Count;
                return VSConstants.S_FALSE;
            }
 
            index += (int)numElems;
            return VSConstants.S_OK;
        }
 
        /// <summary>
        /// Resets the enumeration to the first element.
        /// </summary>
        /// <returns>
        /// If successful, returns S_OK; otherwise, returns an error code.
        /// </returns>
        public int Reset()
        {
            index = 0;
            return VSConstants.S_OK;
        }
 
        /// <summary>
        /// Returns the number of elements in the enumeration.
        /// </summary>
        /// <param name="numElems">Returns the number of elements in the enumeration.</param>
        /// <returns>
        /// If successful, returns S_OK; otherwise, returns an error code.
        /// </returns>
        public int GetCount(out uint numElems)
        {
            numElems = (uint)list.Count;
            return VSConstants.S_OK;
        }
 
        /// <summary>
        /// Returns a copy of the current enumeration as a separate object.
        /// </summary>
        /// <param name="clonedEnum">Returns the clone of this enumeration.</param>
        /// <returns>
        /// If successful, returns S_OK; otherwise, returns an error code.
        /// </returns>
        /// <remarks>
        /// The copy of the enumeration has the same state as the original at the time this method
        /// is called. However, the copy's and the original's states are separate and can be
        /// changed individually.
        /// </remarks>
        public int Clone(out IEnum clonedEnum)
        {
            var clone = new TEnum();
            clone.index = index;
            clone.list = new List<T>(list);
            clonedEnum = clone as IEnum;
            return VSConstants.S_OK;
        }
    }
 
    class ProgramEnum :
        Enum<IDebugProgram2, ProgramEnum, IEnumDebugPrograms2>,
        IEnumDebugPrograms2
    { }
 
    class FrameInfoEnum :
        Enum<FRAMEINFO, FrameInfoEnum, IEnumDebugFrameInfo2>,
        IEnumDebugFrameInfo2
    { }
 
    class ThreadEnum :
        Enum<IDebugThread2, ThreadEnum, IEnumDebugThreads2>,
        IEnumDebugThreads2
    { }
 
    class ModuleEnum :
        Enum<IDebugModule2, ModuleEnum, IEnumDebugModules2>,
        IEnumDebugModules2
    { }
 
    class CodeContextEnum :
        Enum<IDebugCodeContext2, CodeContextEnum, IEnumDebugCodeContexts2>,
        IEnumDebugCodeContexts2
    { }
 
    class BoundBreakpointsEnum :
        Enum<IDebugBoundBreakpoint2, BoundBreakpointsEnum, IEnumDebugBoundBreakpoints2>,
        IEnumDebugBoundBreakpoints2
    { }
 
    class ErrorBreakpointsEnum :
        Enum<IDebugErrorBreakpoint2, ErrorBreakpointsEnum, IEnumDebugErrorBreakpoints2>,
        IEnumDebugErrorBreakpoints2
    { }
 
    class PropertyEnum :
        Enum<DEBUG_PROPERTY_INFO, PropertyEnum, IEnumDebugPropertyInfo2>,
        IEnumDebugPropertyInfo2
    {
        public int Next(uint celt, DEBUG_PROPERTY_INFO[] rgelt, out uint pceltFetched)
        {
            pceltFetched = 0;
            return Next(celt, rgelt, ref pceltFetched);
        }
    }
}