mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-17 09:07:41 +02:00
CommandDirectory.cpp has fewer dependencies...
... This involved populating it with a new registration system. BatchEvalCommand, HelpCommand, MessageCommand escape from cycles and move higher in the dependency graph, and CommandDirectory moves lower.
This commit is contained in:
parent
13713aab67
commit
016e1949ae
@ -17,6 +17,11 @@
|
||||
#include "BatchEvalCommand.h"
|
||||
|
||||
#include "CommandContext.h"
|
||||
#include "CommandDirectory.h"
|
||||
|
||||
static CommandDirectory::RegisterType sRegisterType{
|
||||
std::make_unique<BatchEvalCommandType>()
|
||||
};
|
||||
|
||||
ComponentInterfaceSymbol BatchEvalCommandType::BuildName()
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ system by constructing BatchCommandEval objects.
|
||||
#include "CommandBuilder.h"
|
||||
|
||||
#include "CommandDirectory.h"
|
||||
#include "BatchEvalCommand.h"
|
||||
#include "Command.h"
|
||||
#include "ScriptCommandRelay.h"
|
||||
#include "CommandContext.h"
|
||||
#include "CommandTargets.h"
|
||||
|
@ -17,10 +17,6 @@ functions to look up a command by name.
|
||||
#include "../Audacity.h"
|
||||
#include "CommandDirectory.h"
|
||||
|
||||
#include "HelpCommand.h"
|
||||
#include "MessageCommand.h"
|
||||
#include "BatchEvalCommand.h"
|
||||
|
||||
std::unique_ptr<CommandDirectory> CommandDirectory::mInstance;
|
||||
|
||||
CommandDirectory::CommandDirectory()
|
||||
@ -28,7 +24,8 @@ CommandDirectory::CommandDirectory()
|
||||
// Create the command map.
|
||||
// First we have commands which return information
|
||||
//AddCommand(std::make_unique<MessageCommandType>());
|
||||
AddCommand(std::make_unique<BatchEvalCommandType>());
|
||||
|
||||
// AddCommand(std::make_unique<BatchEvalCommandType>());
|
||||
|
||||
|
||||
// Legacy adapter commands that previously was needed to
|
||||
@ -68,24 +65,30 @@ CommandDirectory::~CommandDirectory()
|
||||
|
||||
OldStyleCommandType *CommandDirectory::LookUp(const wxString &cmdName) const
|
||||
{
|
||||
CommandMap::const_iterator iter = mCmdMap.find(cmdName);
|
||||
if (iter == mCmdMap.end())
|
||||
auto iter = sCmdMap().find(cmdName);
|
||||
if (iter == sCmdMap().end())
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
void CommandDirectory::AddCommand(std::unique_ptr<OldStyleCommandType> &&type)
|
||||
CommandMap &CommandDirectory::sCmdMap()
|
||||
{
|
||||
static CommandMap theMap;
|
||||
return theMap;
|
||||
}
|
||||
|
||||
void CommandDirectory::AddCommand(std::unique_ptr<OldStyleCommandType> type)
|
||||
{
|
||||
wxASSERT(type != NULL);
|
||||
// Internal string is shown but only in assertion message
|
||||
auto cmdName = type->GetSymbol().Internal();
|
||||
wxASSERT_MSG(mCmdMap.find(cmdName) == mCmdMap.end()
|
||||
wxASSERT_MSG(sCmdMap().find(cmdName) == sCmdMap().end()
|
||||
, wxT("A command named ") + cmdName
|
||||
+ wxT(" already exists."));
|
||||
|
||||
mCmdMap[cmdName] = std::move(type);
|
||||
sCmdMap()[cmdName] = std::move(type);
|
||||
}
|
||||
|
||||
CommandDirectory *CommandDirectory::Get()
|
||||
|
@ -31,8 +31,17 @@ class CommandDirectory
|
||||
{
|
||||
private:
|
||||
static std::unique_ptr<CommandDirectory> mInstance;
|
||||
CommandMap mCmdMap;
|
||||
static CommandMap &sCmdMap();
|
||||
|
||||
static void AddCommand(std::unique_ptr<OldStyleCommandType> type);
|
||||
public:
|
||||
/// Register a type of command with the directory with a statically
|
||||
/// constructed instance of this class.
|
||||
struct RegisterType{
|
||||
RegisterType( std::unique_ptr<OldStyleCommandType> type )
|
||||
{ AddCommand( std::move( type ) ); }
|
||||
};
|
||||
|
||||
~CommandDirectory();
|
||||
|
||||
/// If a command with the given name has been registered in the directory,
|
||||
@ -40,9 +49,6 @@ public:
|
||||
/// Otherwise return NULL.
|
||||
OldStyleCommandType *LookUp(const wxString &cmdName) const;
|
||||
|
||||
/// Register a type of command with the directory.
|
||||
void AddCommand(std::unique_ptr<OldStyleCommandType> &&type);
|
||||
|
||||
/// Get a pointer to the singleton instance
|
||||
static CommandDirectory *Get();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user