Audacity  2.2.2
CommandDirectory.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity - A Digital Audio Editor
4  Copyright 1999-2009 Audacity Team
5  License: wxWidgets
6 
7  Dan Horgan
8 
9 ******************************************************************//*******************************************************************/
16 
17 #include "../Audacity.h"
18 #include "CommandDirectory.h"
19 #include "CommandMisc.h"
20 
21 #include "ScreenshotCommand.h"
22 #include "BatchEvalCommand.h"
23 #include "ExecMenuCommand.h"
24 #include "AutomationCommands.h"
25 #include "MessageCommand.h"
26 #include "GetTrackInfoCommand.h"
27 #include "GetProjectInfoCommand.h"
28 #include "HelpCommand.h"
29 #include "SelectCommand.h"
30 #include "CompareAudioCommand.h"
31 #include "SetTrackInfoCommand.h"
32 #include "SetProjectInfoCommand.h"
33 #include "PreferenceCommands.h"
34 #include "ImportExportCommands.h"
35 #include "OpenSaveCommands.h"
36 
37 std::unique_ptr<CommandDirectory> CommandDirectory::mInstance;
38 
40 {
41  // Create the command map.
42  // Adding an entry here is the easiest way to register a Command class.
43  AddCommand(make_movable<ScreenshotCommandType>());
44  AddCommand(make_movable<BatchEvalCommandType>());
45  AddCommand(make_movable<ExecMenuCommandType>());
46  AddCommand(make_movable<MessageCommandType>());
47  AddCommand(make_movable<GetTrackInfoCommandType>());
48  AddCommand(make_movable<GetProjectInfoCommandType>());
49 
50  // AutomationCommandsType will be renamed GenericCommand
51  // It can be customised in the constructor and so
52  // appear as many distinct commands.
53  AddCommand(make_movable<AutomationCommandsType>("GetAll"));
54  AddCommand(make_movable<AutomationCommandsType>("GetMenus"));
55  AddCommand(make_movable<AutomationCommandsType>("GetMenusPlus"));
56  AddCommand(make_movable<AutomationCommandsType>("GetBoxes"));
57  AddCommand(make_movable<AutomationCommandsType>("GetClips"));
58 
59  AddCommand(make_movable<HelpCommandType>());
60  AddCommand(make_movable<SelectCommandType>());
61  AddCommand(make_movable<CompareAudioCommandType>());
62  AddCommand(make_movable<SetTrackInfoCommandType>());
63  AddCommand(make_movable<SetProjectInfoCommandType>());
64 
65  AddCommand(make_movable<SetPreferenceCommandType>());
66  AddCommand(make_movable<GetPreferenceCommandType>());
67  AddCommand(make_movable<ImportCommandType>());
68  AddCommand(make_movable<ExportCommandType>());
69  AddCommand(make_movable<OpenProjectCommandType>());
70  AddCommand(make_movable<SaveProjectCommandType>());
71 }
72 
74 {
75 }
76 
77 CommandType *CommandDirectory::LookUp(const wxString &cmdName) const
78 {
79  CommandMap::const_iterator iter = mCmdMap.find(cmdName);
80  if (iter == mCmdMap.end())
81  {
82  return NULL;
83  }
84  return iter->second.get();
85 }
86 
88 {
89  wxASSERT(type != NULL);
90  wxString cmdName = type->GetName();
91  wxASSERT_MSG(mCmdMap.find(cmdName) == mCmdMap.end()
92  , wxT("A command named ") + cmdName
93  + wxT(" already exists."));
94 
95  mCmdMap[cmdName] = std::move(type);
96 }
97 
99 {
100  if (!mInstance)
102  return mInstance.get();
103 }
static CommandDirectory * Get()
Get a pointer to the singleton instance.
std::unique_ptr< T > movable_ptr
Definition: MemoryX.h:713
static std::unique_ptr< CommandDirectory > mInstance
Declarations of GetProjectInfoCommand and GetProjectInfoCommandType classes.
Contains declaration of CompareAudioCommand and CompareAudioCommandType classes.
Contains declarations for CommandDirectory class.
#define safenew
Definition: Audacity.h:223
Allows registration and lookup (by name) of command types.
Declarations of SetProjectInfoCommand and SetProjectInfoCommandType classes.
CommandType * LookUp(const wxString &cmdName) const
Contains declaration of ExecMenuCommand class.
Base class for containing data common to all commands of a given type. Also acts as a factory...
Definition: CommandType.h:29
Declarations of SetTrackInfoCommand and SetTrackInfoCommandType classes.
Contains definition of MessageCommand class.
Declarations for SelectCommand and SelectCommandType classes.
void AddCommand(movable_ptr< CommandType > &&type)
Register a type of command with the directory.
Declarations of GetTrackInfoCommand and GetTrackInfoCommandType classes.
Contains declaration of AutomationCommands class.