Audacity  2.3.1
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CommandDirectory Class Reference

Allows registration and lookup (by name) of command types. More...

#include <CommandDirectory.h>

Public Member Functions

 ~CommandDirectory ()
 
OldStyleCommandTypeLookUp (const wxString &cmdName) const
 
void AddCommand (std::unique_ptr< OldStyleCommandType > &&type)
 Register a type of command with the directory. More...
 

Static Public Member Functions

static CommandDirectoryGet ()
 Get a pointer to the singleton instance. More...
 

Private Member Functions

 CommandDirectory ()
 

Private Attributes

CommandMap mCmdMap
 

Static Private Attributes

static std::unique_ptr
< CommandDirectory
mInstance
 

Detailed Description

Allows registration and lookup (by name) of command types.

A singleton. This fulfills a similar purpose to CommandManager, but for general Commands rather than menu items. Eventually they could be unified but for now they are kept separate to make things simpler.

Definition at line 33 of file CommandDirectory.h.

Constructor & Destructor Documentation

CommandDirectory::~CommandDirectory ( )

Definition at line 66 of file CommandDirectory.cpp.

67 {
68 }
CommandDirectory::CommandDirectory ( )
private

Definition at line 27 of file CommandDirectory.cpp.

References AddCommand().

Referenced by Get().

28 {
29  // Create the command map.
30  // First we have commands which return information
31  //AddCommand(std::make_unique<MessageCommandType>());
32  AddCommand(std::make_unique<BatchEvalCommandType>());
33 
34 
35  // Legacy adapter commands that previously was needed to
36  // access menu items.
37  //AddCommand(std::make_unique<ExecMenuCommandType>());
38 
39  // Not needed. Sets selected/solo/mute on multiple tracks.
40  //AddCommand(std::make_unique<SetProjectInfoCommandType>());
41 
42 // Moved to AudacityCommand
43 // AddCommand(std::make_unique<OpenProjectCommandType>());
44 // AddCommand(std::make_unique<SaveProjectCommandType>());
45 // AddCommand(std::make_unique<ImportCommandType>());
46 // AddCommand(std::make_unique<ExportCommandType>());
47 // AddCommand(std::make_unique<HelpCommandType>());
48 // AddCommand(std::make_unique<GetInfoCommandType>("GetAll"));
49 // AddCommand(std::make_unique<GetInfoCommandType>("GetCommands"));
50 // AddCommand(std::make_unique<GetInfoCommandType>("GetMenus"));
51 // AddCommand(std::make_unique<GetInfoCommandType>("GetMenusPlus"));
52 // AddCommand(std::make_unique<GetInfoCommandType>("GetBoxes"));
53 // AddCommand(std::make_unique<GetInfoCommandType>("GetClips"));
54 
55 // AddCommand(std::make_unique<GetTrackInfoCommandType>());
56 // AddCommand(std::make_unique<GetProjectInfoCommandType>());
57 // AddCommand(std::make_unique<CompareAudioCommandType>());
58 // AddCommand(std::make_unique<GetPreferenceCommandType>());
59 // AddCommand(std::make_unique<SetPreferenceCommandType>());
60 // AddCommand(std::make_unique<ScreenshotCommandType>());
61 // AddCommand(std::make_unique<SelectCommandType>());
62 // AddCommand(std::make_unique<SetTrackInfoCommandType>());
63 
64 }
void AddCommand(std::unique_ptr< OldStyleCommandType > &&type)
Register a type of command with the directory.

Member Function Documentation

void CommandDirectory::AddCommand ( std::unique_ptr< OldStyleCommandType > &&  type)

Register a type of command with the directory.

Definition at line 80 of file CommandDirectory.cpp.

References mCmdMap.

Referenced by CommandDirectory().

81 {
82  wxASSERT(type != NULL);
83  // Internal string is shown but only in assertion message
84  auto cmdName = type->GetSymbol().Internal();
85  wxASSERT_MSG(mCmdMap.find(cmdName) == mCmdMap.end()
86  , wxT("A command named ") + cmdName
87  + wxT(" already exists."));
88 
89  mCmdMap[cmdName] = std::move(type);
90 }
const wxString & Internal() const
IdentInterfaceSymbol GetSymbol() override
Definition: CommandType.cpp:34
CommandDirectory * CommandDirectory::Get ( )
static

Get a pointer to the singleton instance.

Definition at line 92 of file CommandDirectory.cpp.

References CommandDirectory(), mInstance, and safenew.

Referenced by CommandBuilder::BuildCommand().

93 {
94  if (!mInstance)
96  return mInstance.get();
97 }
static std::unique_ptr< CommandDirectory > mInstance
#define safenew
Definition: Audacity.h:230
OldStyleCommandType * CommandDirectory::LookUp ( const wxString &  cmdName) const

If a command with the given name has been registered in the directory, return a pointer to the factory for commands of that type. Otherwise return NULL.

Definition at line 70 of file CommandDirectory.cpp.

References mCmdMap.

Referenced by CommandBuilder::BuildCommand().

71 {
72  CommandMap::const_iterator iter = mCmdMap.find(cmdName);
73  if (iter == mCmdMap.end())
74  {
75  return NULL;
76  }
77  return iter->second.get();
78 }

Member Data Documentation

CommandMap CommandDirectory::mCmdMap
private

Definition at line 37 of file CommandDirectory.h.

Referenced by AddCommand(), and LookUp().

std::unique_ptr< CommandDirectory > CommandDirectory::mInstance
staticprivate

Definition at line 36 of file CommandDirectory.h.

Referenced by Get().


The documentation for this class was generated from the following files: