Audacity  3.0.3
LoadCommands.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  LoadCommands.h
6 
7  Dominic Mazzoni
8  James Crook
9 
10 **********************************************************************/
11 
12 #ifndef __AUDACITY_LOAD_COMMANDS__
13 #define __AUDACITY_LOAD_COMMANDS__
14 
15 #include "ModuleInterface.h"
16 
17 #include <functional>
18 #include <memory>
19 #include <unordered_map>
20 #include <memory>
21 
22 class AudacityCommand;
23 
25 //
26 // BuiltinCommandsModule
27 //
29 
30 class AUDACITY_DLL_API BuiltinCommandsModule final : public ModuleInterface
31 {
32 public:
34  virtual ~BuiltinCommandsModule();
35 
36  using Factory = std::function< std::unique_ptr<AudacityCommand> () >;
37 
38  // Typically you make a static object of this type in the .cpp file that
39  // also implements the Command subclass.
40  template< typename Subclass >
41  struct Registration final { Registration() {
42  DoRegistration(
43  Subclass::Symbol, []{ return std::make_unique< Subclass >(); } );
44  } };
45 
46  // ComponentInterface implementation
47 
48  PluginPath GetPath() override;
50  VendorSymbol GetVendor() override;
51  wxString GetVersion() override;
53 
54  // ModuleInterface implementation
55 
56  bool Initialize() override;
57  void Terminate() override;
59 
60  const FileExtensions &GetFileExtensions() override;
61  FilePath InstallPath() override { return {}; }
62 
63  bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
65  unsigned DiscoverPluginsAtPath(
66  const PluginPath & path, TranslatableString &errMsg,
67  const RegistrationCallback &callback)
68  override;
69 
70  bool IsPluginValid(const PluginPath & path, bool bFast) override;
71 
72  std::unique_ptr<ComponentInterface>
73  CreateInstance(const PluginPath & path) override;
74 
75 private:
76  // BuiltinEffectModule implementation
77 
78  std::unique_ptr<AudacityCommand> Instantiate(const PluginPath & path);
79 
80 private:
81  struct Entry;
82 
83  static void DoRegistration(
84  const ComponentInterfaceSymbol &name, const Factory &factory );
85 
86  using CommandHash = std::unordered_map< wxString, const Entry* > ;
88 };
89 
90 #endif
ModuleInterface::AutoRegisterPlugins
virtual bool AutoRegisterPlugins(PluginManagerInterface &pluginManager)=0
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
BuiltinCommandsModule
Internal module to auto register all built in commands. It is closely modelled on BuiltinEffectsModul...
Definition: LoadCommands.h:31
ComponentInterface::GetSymbol
virtual ComponentInterfaceSymbol GetSymbol()=0
PluginPath
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
ModuleInterface.h
BuiltinCommandsModule::Factory
std::function< std::unique_ptr< AudacityCommand >() > Factory
Definition: LoadCommands.h:36
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
Entry
Definition: EditToolBar.cpp:225
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
ComponentInterface::GetVendor
virtual VendorSymbol GetVendor()=0
ModuleInterface
Definition: ModuleInterface.h:70
ModuleInterface::FindPluginPaths
virtual PluginPaths FindPluginPaths(PluginManagerInterface &pluginManager)=0
ModuleInterface::CreateInstance
virtual std::unique_ptr< ComponentInterface > CreateInstance(const PluginPath &path)=0
FilePath
wxString FilePath
Definition: Project.h:20
PluginManagerInterface
Definition: PluginInterface.h:55
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:806
ModuleInterface::Initialize
virtual bool Initialize()=0
ComponentInterface::GetPath
virtual PluginPath GetPath()=0
AudacityCommand
Base class for command in Audacity.
Definition: AudacityCommand.h:41
name
const TranslatableString name
Definition: Distortion.cpp:98
ComponentInterface::GetDescription
virtual TranslatableString GetDescription()=0
BuiltinCommandsModule::CommandHash
std::unordered_map< wxString, const Entry * > CommandHash
Definition: LoadCommands.h:86
PluginPaths
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
ModuleInterface::GetOptionalFamilySymbol
virtual EffectFamilySymbol GetOptionalFamilySymbol()=0
ModuleInterface::DiscoverPluginsAtPath
virtual unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback)=0
BuiltinCommandsModule::Registration::Registration
Registration()
Definition: LoadCommands.h:41
ComponentInterface::GetVersion
virtual wxString GetVersion()=0
BuiltinCommandsModule::mCommands
CommandHash mCommands
Definition: LoadCommands.h:87
ModuleInterface::Terminate
virtual void Terminate()=0
BuiltinCommandsModule::InstallPath
FilePath InstallPath() override
Definition: LoadCommands.h:61
ModuleInterface::GetFileExtensions
virtual const FileExtensions & GetFileExtensions()=0
ModuleInterface::IsPluginValid
virtual bool IsPluginValid(const PluginPath &path, bool bFast)=0