@@ -130,6 +130,16 @@ template <typename FormatterImpl> class TieredFormatterContainer {
130130 return lldb::TypeNameSpecifierImplSP ();
131131 }
132132
133+ // / Iterates through tiers in order, running `callback` on each element of
134+ // / each tier.
135+ void ForEach (std::function<bool (const TypeMatcher &,
136+ const std::shared_ptr<FormatterImpl> &)>
137+ callback) {
138+ for (auto sc : m_subcontainers) {
139+ sc->ForEach (callback);
140+ }
141+ }
142+
133143 private:
134144 std::array<std::shared_ptr<Subcontainer>, lldb::eLastFormatterMatchType + 1 >
135145 m_subcontainers;
@@ -146,120 +156,36 @@ class TypeCategoryImpl {
146156 typedef uint16_t FormatCategoryItems;
147157 static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
148158
149- template <typename T> class ForEachCallbacks {
150- public:
151- ForEachCallbacks () = default ;
152- ~ForEachCallbacks () = default ;
153-
154- template <typename U = TypeFormatImpl>
155- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
156- SetExact (FormatContainer::ForEachCallback callback) {
157- m_format_exact = std::move (callback);
158- return *this ;
159- }
160- template <typename U = TypeFormatImpl>
161- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
162- SetWithRegex (FormatContainer::ForEachCallback callback) {
163- m_format_regex = std::move (callback);
164- return *this ;
165- }
166-
167- template <typename U = TypeSummaryImpl>
168- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
169- SetExact (SummaryContainer::ForEachCallback callback) {
170- m_summary_exact = std::move (callback);
171- return *this ;
172- }
173- template <typename U = TypeSummaryImpl>
174- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
175- SetWithRegex (SummaryContainer::ForEachCallback callback) {
176- m_summary_regex = std::move (callback);
177- return *this ;
178- }
179-
180- template <typename U = TypeFilterImpl>
181- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
182- SetExact (FilterContainer::ForEachCallback callback) {
183- m_filter_exact = std::move (callback);
184- return *this ;
185- }
186- template <typename U = TypeFilterImpl>
187- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
188- SetWithRegex (FilterContainer::ForEachCallback callback) {
189- m_filter_regex = std::move (callback);
190- return *this ;
191- }
192-
193- template <typename U = SyntheticChildren>
194- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
195- SetExact (SynthContainer::ForEachCallback callback) {
196- m_synth_exact = std::move (callback);
197- return *this ;
198- }
199- template <typename U = SyntheticChildren>
200- typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
201- SetWithRegex (SynthContainer::ForEachCallback callback) {
202- m_synth_regex = std::move (callback);
203- return *this ;
204- }
205-
206- FormatContainer::ForEachCallback GetFormatExactCallback () const {
207- return m_format_exact;
208- }
209- FormatContainer::ForEachCallback GetFormatRegexCallback () const {
210- return m_format_regex;
211- }
212-
213- SummaryContainer::ForEachCallback GetSummaryExactCallback () const {
214- return m_summary_exact;
215- }
216- SummaryContainer::ForEachCallback GetSummaryRegexCallback () const {
217- return m_summary_regex;
218- }
219-
220- FilterContainer::ForEachCallback GetFilterExactCallback () const {
221- return m_filter_exact;
222- }
223- FilterContainer::ForEachCallback GetFilterRegexCallback () const {
224- return m_filter_regex;
225- }
226-
227- SynthContainer::ForEachCallback GetSynthExactCallback () const {
228- return m_synth_exact;
229- }
230- SynthContainer::ForEachCallback GetSynthRegexCallback () const {
231- return m_synth_regex;
232- }
233-
234- private:
235- FormatContainer::ForEachCallback m_format_exact;
236- FormatContainer::ForEachCallback m_format_regex;
237-
238- SummaryContainer::ForEachCallback m_summary_exact;
239- SummaryContainer::ForEachCallback m_summary_regex;
240-
241- FilterContainer::ForEachCallback m_filter_exact;
242- FilterContainer::ForEachCallback m_filter_regex;
243-
244- SynthContainer::ForEachCallback m_synth_exact;
245- SynthContainer::ForEachCallback m_synth_regex;
159+ // TypeFilterImpl inherits from SyntheticChildren, so we can't simply overload
160+ // ForEach on the type of the callback because it would result in "call to
161+ // member function 'ForEach' is ambiguous" errors. Instead we use this
162+ // templated struct to hold the formatter type and the callback.
163+ template <typename T>
164+ struct ForEachCallback {
165+ // Make it constructible from any callable that fits. This allows us to use
166+ // lambdas a bit more easily at the call site. For example:
167+ // ForEachCallback<TypeFormatImpl> callback = [](...) {...};
168+ template <typename Callable> ForEachCallback (Callable c) : callback(c) {}
169+ std::function<bool (const TypeMatcher &, const std::shared_ptr<T> &)>
170+ callback;
246171 };
247172
248173 TypeCategoryImpl (IFormatChangeListener *clist, ConstString name);
249174
250- template < typename T> void ForEach (const ForEachCallbacks<T> &foreach ) {
251- GetTypeFormatsContainer ()-> ForEach (foreach. GetFormatExactCallback () );
252- GetRegexTypeFormatsContainer ()-> ForEach (foreach. GetFormatRegexCallback ());
175+ void ForEach (ForEachCallback<TypeFormatImpl> callback ) {
176+ m_format_cont. ForEach (callback. callback );
177+ }
253178
254- GetTypeSummariesContainer ()-> ForEach (foreach. GetSummaryExactCallback ());
255- GetRegexTypeSummariesContainer ()-> ForEach (
256- foreach. GetSummaryRegexCallback ());
179+ void ForEach (ForEachCallback<TypeSummaryImpl> callback) {
180+ m_summary_cont. ForEach (callback. callback );
181+ }
257182
258- GetTypeFiltersContainer ()->ForEach (foreach.GetFilterExactCallback ());
259- GetRegexTypeFiltersContainer ()->ForEach (foreach.GetFilterRegexCallback ());
183+ void ForEach (ForEachCallback<TypeFilterImpl> callback) {
184+ m_filter_cont.ForEach (callback.callback );
185+ }
260186
261- GetTypeSyntheticsContainer ()-> ForEach (foreach. GetSynthExactCallback ());
262- GetRegexTypeSyntheticsContainer ()-> ForEach (foreach. GetSynthRegexCallback () );
187+ void ForEach (ForEachCallback<SyntheticChildren> callback) {
188+ m_synth_cont. ForEach (callback. callback );
263189 }
264190
265191 FormatContainer::SubcontainerSP GetTypeFormatsContainer () {
0 commit comments