Audacity 3.2.0
ExportPluginRegistry.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <functional>
5
6#include <wx/string.h>
7
8#include "Registry.h"
9
10class ExportPlugin;
11struct FormatInfo;
12
13class IMPORT_EXPORT_API ExportPluginRegistry final
14{
16
18
19public:
20
21 std::vector<bool>::const_iterator a;
22
23 using ExportPlugins = std::vector<std::unique_ptr<ExportPlugin>>;
24
25 class IMPORT_EXPORT_API ConstIterator final
26 {
27 ExportPlugins::const_iterator mPluginIt;
29 public:
30 using value_type = const std::tuple<ExportPlugin*, int>;//proxy type
31
32 struct ProxyPtr final
33 {
34 explicit ProxyPtr(std::remove_const_t<value_type> value) : mValue(std::move(value)) { }
35 value_type* operator->() const { return &mValue; }
36 private:
38 };
39
40 using iterator_category = std::input_iterator_tag;
41 using difference_type = int;
44
45 ConstIterator(ExportPlugins::const_iterator pluginIt, int formatIndex)
46 : mPluginIt(std::move(pluginIt)), mFormatIndex(formatIndex) { }
47
48 reference operator*() const { return std::make_tuple(mPluginIt->get(), mFormatIndex); }
49
50 pointer operator->() const { return ProxyPtr { std::make_tuple(mPluginIt->get(), mFormatIndex) }; }
51
52 ConstIterator& operator++();
53
55 {
56 auto prev = *this;
57 ++*this;
58 return prev;
59 }
60
61 friend bool operator==(const ConstIterator& a, const ConstIterator& b)
62 {
63 return a.mPluginIt == b.mPluginIt && a.mFormatIndex == b.mFormatIndex;
64 }
65
66 friend bool operator!=(const ConstIterator& a, const ConstIterator& b)
67 {
68 return a.mPluginIt != b.mPluginIt || a.mFormatIndex != b.mFormatIndex;
69 }
70 };
71
72 using Factory =
73 std::function< std::unique_ptr< ExportPlugin >() >;
74
77
79
80 // Objects of this type are statically constructed in files implementing
81 // subclasses of ExportPlugin
82 // Register factories, not plugin objects themselves, which allows them
83 // to have some fresh state variables each time export begins again
84 // and to compute translated strings for the current locale
85 struct IMPORT_EXPORT_API RegisteredPlugin
86 : Registry::RegisteredItem<ExportPluginRegistryItem>
87 {
89 const Identifier &id, // an internal string naming the plug-in
90 const Factory&,
91 const Registry::Placement &placement = { wxEmptyString, {} } );
92 };
93
94 static ExportPluginRegistry& Get();
95
96 void Initialize();
97
98 ConstIterator cbegin() const noexcept { return { mPlugins.begin(), 0 }; }
99 ConstIterator cend() const noexcept { return { mPlugins.end(), 0 }; }
100 ConstIterator begin() const noexcept { return cbegin(); }
101 ConstIterator end() const noexcept { return cend(); }
102
107 std::tuple<ExportPlugin*, int> FindFormat(const wxString& format, bool compareWithCase = false) const;
108
109private:
112 };
113 struct IMPORT_EXPORT_API ExportPluginRegistryItem final : Registry::SingleItem {
117 };
118
120};
121
static RegisteredToolbarFactory factory
ConstIterator(ExportPlugins::const_iterator pluginIt, int formatIndex)
std::input_iterator_tag iterator_category
const std::tuple< ExportPlugin *, int > value_type
ExportPlugins::const_iterator mPluginIt
friend bool operator==(const ConstIterator &a, const ConstIterator &b)
friend bool operator!=(const ConstIterator &a, const ConstIterator &b)
std::vector< bool >::const_iterator a
ConstIterator cend() const noexcept
ConstIterator end() const noexcept
ExportPluginRegistry(ExportPluginRegistry &)=delete
ConstIterator cbegin() const noexcept
std::function< std::unique_ptr< ExportPlugin >() > Factory
ConstIterator begin() const noexcept
std::vector< std::unique_ptr< ExportPlugin > > ExportPlugins
ExportPluginRegistry(ExportPluginRegistry &&)=delete
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Generates classes whose instances register items at construction.
Definition: Registry.h:388
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
STL namespace.
ProxyPtr(std::remove_const_t< value_type > value)
Common abstract base class for items that are not groups.
Definition: Registry.h:224
Primary template for a list of arbitrary types.
Definition: TypeList.h:61