Audacity 3.2.0
NumericConverterRegistry.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 @file NumericConverterRegistry.cpp
7
8 Dmitry Vedenko
9
10 **********************************************************************/
12
13namespace
14{
15const auto PathStart = L"NumericConverterRegistry";
16}
17
19 const Identifier& internalName, const NumericFormatSymbol& _symbol,
21 : SingleItem { internalName }
22 , symbol { _symbol }
23 , factory { std::move(_factory) }
24{
25}
26
28 const Identifier& internalName, const NumericFormatSymbol& _symbol,
29 const TranslatableString& _fractionLabel,
31 : SingleItem { internalName }
32 , symbol { _symbol }
33 , fractionLabel { _fractionLabel }
34 , factory { std::move(_factory) }
35 {
36 }
37
39 {
40 }
41
44{
46 registry { PathStart };
47 return registry;
48}
49
51 const FormatterContext& context, const NumericConverterType& type,
52 Visitor visitor)
53{
56 { { L"", L"parsedTime,beats,parsedFrequency,parsedBandwith" } },
57 };
58
60 bool inMatchingGroup = false;
61 Registry::Visit(std::tuple{
62 [&](const NumericConverterRegistryGroup &group, auto&) {
63 inMatchingGroup = group.GetType() == type; },
64 [&](const NumericConverterRegistryItem &item, auto&) {
65 if (!inMatchingGroup)
66 return;
67 // Skip the items that are not acceptable in this context
68 if (!item.factory->IsAcceptableInContext(context))
69 return;
70 visitor(item);
71 },
72 [&](const NumericConverterRegistryGroup &, auto&) {
73 inMatchingGroup = false; }
74 }, &top, &Registry());
75}
76
78 const FormatterContext& context,
79 const NumericConverterType& type, const NumericFormatID& symbol)
80{
81 const NumericConverterRegistryItem* result = nullptr;
82
83 Visit(
84 context,
85 type,
86 [&result, symbol](const NumericConverterRegistryItem& item)
87 {
88 if (item.symbol.Internal() == symbol)
89 result = &item;
90 });
91
92 return result;
93}
94
96{
97}
static RegisteredToolbarFactory factory
std::unique_ptr< NumericConverterFormatterFactory > NumericConverterFormatterFactoryPtr
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString & Internal() const
A context in which formatter operates.
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Holds a msgid for the translation catalog; may also bind format arguments.
void Visit(const Visitors &visitors, const GroupItem< RegistryTraits > *pTopItem, const GroupItem< RegistryTraits > *pRegistry={}, typename RegistryTraits::ComputedItemContextType &computedItemContext=RegistryTraits::ComputedItemContextType::Instance)
Definition: Registry.h:609
STL namespace.
std::function< void(const NumericConverterRegistryItem &)> Visitor
static const NumericConverterRegistryItem * Find(const FormatterContext &context, const NumericConverterType &type, const NumericFormatID &symbol)
static void Visit(const FormatterContext &context, const NumericConverterType &type, Visitor visitor)
static Registry::GroupItem< NumericConverterRegistryTraits > & Registry()
const NumericConverterFormatterFactoryPtr factory
const NumericFormatSymbol symbol
NumericConverterRegistryItem(const Identifier &internalName, const NumericFormatSymbol &symbol, NumericConverterFormatterFactoryPtr factory)