6
6
//
7
7
// Copyright (c) 2023 Vinnie Falco ([email protected] )
8
8
// Copyright (c) 2023 Krystian Stasiowski ([email protected] )
9
+ // Copyright (c) 2024 Alan de Freitas ([email protected] )
9
10
//
10
11
// Official repository: https://github.com/cppalliance/mrdocs
11
12
//
@@ -160,6 +161,32 @@ class MRDOCS_VISIBLE
160
161
}
161
162
}
162
163
164
+ /* * Visit the members of specified Info in a stable order.
165
+
166
+ @param I The Info to visit.
167
+ @param info The Info to visit.
168
+ @param f The function to invoke.
169
+ @param args The arguments to pass to the function.
170
+ */
171
+ template <InfoParent T, class F , class ... Args>
172
+ void
173
+ orderedTraverse (
174
+ T const & I, F&& f, Args&&... args) const
175
+ {
176
+ std::vector<SymbolID> members (I.Members .begin (), I.Members .end ());
177
+ std::stable_sort (members.begin (), members.end (), [this ](SymbolID const & lhs, SymbolID const & rhs)
178
+ {
179
+ auto const & lhsInfo = get (lhs);
180
+ auto const & rhsInfo = get (rhs);
181
+ return lhsInfo < rhsInfo;
182
+ });
183
+ for (auto const & id : members)
184
+ {
185
+ visit (get (id), std::forward<F>(f),
186
+ std::forward<Args>(args)...);
187
+ }
188
+ }
189
+
163
190
/* * Visit the member overloads of specified ScopeInfo.
164
191
165
192
This function iterates the members of the
@@ -184,6 +211,14 @@ class MRDOCS_VISIBLE
184
211
F&& f,
185
212
Args&&... args) const ;
186
213
214
+ /* * Visit the member overloads of specified ScopeInfo in stable order
215
+ */
216
+ template <class F , class ... Args>
217
+ void orderedTraverseOverloads (
218
+ ScopeInfo const & S,
219
+ F&& f,
220
+ Args&&... args) const ;
221
+
187
222
// --------------------------------------------
188
223
189
224
/* * Return the fully qualified name of the specified Info.
@@ -238,25 +273,20 @@ get(
238
273
239
274
template <class F , class ... Args>
240
275
void
241
- Corpus::
242
- traverseOverloads (
276
+ traverseOverloadsImpl (
277
+ Corpus const & c,
278
+ std::vector<SymbolID> const & members0,
243
279
ScopeInfo const & S,
244
- F&& f, Args&&... args) const
280
+ F&& f, Args&&... args)
245
281
{
246
- MRDOCS_ASSERT (S.Members .empty () == S.Lookups .empty ());
247
- for (const SymbolID& id : S.Members )
282
+ for (const SymbolID& id : members0)
248
283
{
249
- const Info& member = get (id);
284
+ const Info& member = c. get (id);
250
285
const auto & members = S.Lookups .at (member.Name );
251
286
auto first_func = std::ranges::find_if (
252
- members, [this ](const SymbolID& elem)
287
+ members, [&c ](const SymbolID& elem)
253
288
{
254
- #if 0
255
- const Info& I = get(elem);
256
- return I.isFunction() || I.isGuide();
257
- #else
258
- return get (elem).isFunction ();
259
- #endif
289
+ return c.get (elem).isFunction ();
260
290
});
261
291
bool const nonOverloadedFunction = members.size () == 1 ;
262
292
bool const notFunction = first_func == members.end ();
@@ -278,6 +308,40 @@ traverseOverloads(
278
308
}
279
309
}
280
310
311
+ template <class F , class ... Args>
312
+ void
313
+ Corpus::
314
+ traverseOverloads (
315
+ ScopeInfo const & S,
316
+ F&& f, Args&&... args) const
317
+ {
318
+ MRDOCS_ASSERT (S.Members .empty () == S.Lookups .empty ());
319
+ return traverseOverloadsImpl (
320
+ *this , S.Members , S, std::forward<F>(f), std::forward<Args>(args)...);
321
+
322
+ }
323
+
324
+ template <class F , class ... Args>
325
+ void
326
+ Corpus::
327
+ orderedTraverseOverloads (
328
+ ScopeInfo const & S,
329
+ F&& f,
330
+ Args&&... args) const
331
+ {
332
+ MRDOCS_ASSERT (S.Members .empty () == S.Lookups .empty ());
333
+ std::vector<SymbolID> members (S.Members .begin (), S.Members .end ());
334
+ std::stable_sort (members.begin (), members.end (), [this ](SymbolID const & lhs, SymbolID const & rhs)
335
+ {
336
+ auto const & lhsInfo = get (lhs);
337
+ auto const & rhsInfo = get (rhs);
338
+ return lhsInfo < rhsInfo;
339
+ });
340
+ return traverseOverloadsImpl (
341
+ *this , members, S, std::forward<F>(f), std::forward<Args>(args)...);
342
+ }
343
+
344
+
281
345
class Corpus ::iterator
282
346
{
283
347
const Corpus* corpus_;
0 commit comments