File: CommandContext.cpp

package info (click to toggle)
audacity 3.7.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 134,800 kB
  • sloc: cpp: 366,277; ansic: 198,323; lisp: 7,761; sh: 3,414; python: 1,501; xml: 1,385; perl: 854; makefile: 125
file content (134 lines) | stat: -rw-r--r-- 3,001 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**********************************************************************

   Audacity - A Digital Audio Editor
   Copyright 1999-2017 Audacity Team
   License: wxwidgets

   Dan Horgan
   James Crook

******************************************************************//**

\file CommandContext.cpp
\brief Contains definitions for CommandContext

\class CommandContext
\brief CommandContext provides additional information to an
'Apply()' command.  It provides the project, and provides output
channels for Error, Progress and Status.  Status is used for general
messaging from a command back to its invoker.

*//*******************************************************************/
#include "CommandContext.h"

#include <map>
#include <wx/log.h>
#include <wx/variant.h>
#include <wx/arrstr.h>

#include "CommandTargets.h"

CommandContext::CommandContext(
      AudacityProject &p
      , const wxEvent *e
      , int ii
      , const CommandParameter &param
   )
      : project{ p }
      // No target specified?  Use the special interactive one that pops up a dialog.
      , pOutput{ TargetFactory::Call() }
      , pEvt{ e }
      , index{ ii }
      , parameter{ param }
{
}
   
CommandContext::CommandContext(
      AudacityProject &p,
      std::unique_ptr<CommandOutputTargets> target)
      : project{ p }
      // Revisit and use std_unique pointer for pOutput??
      , pOutput( std::move( target) )
      , pEvt{ nullptr }
      , index{ 0 }
      , parameter{ CommandParameter{}}
{
}

CommandContext::~CommandContext() = default;

void CommandContext::Status( const wxString & message, bool bFlush ) const
{
   if( pOutput )
      pOutput->Status( message, bFlush );
   else
   {
      wxLogDebug("Status:%s", message );
   }
}

void CommandContext::Error(  const wxString & message ) const
{
   if( pOutput )
      pOutput->Error( message );
   else
   {
      wxLogDebug("Error:%s", message );
   }
}

void CommandContext::Progress( double d ) const
{
   if( pOutput )
      pOutput->Progress( d );
}

void CommandContext::StartArray() const
{
   if( pOutput )
      pOutput->StartArray();
}
void CommandContext::EndArray() const
{
   if( pOutput )
      pOutput->EndArray();
}
void CommandContext::StartStruct() const
{
   if( pOutput )
      pOutput->StartStruct();
}
void CommandContext::EndStruct() const
{
   if( pOutput )
      pOutput->EndStruct();
}
void CommandContext::StartField(const wxString &name) const
{
   if( pOutput )
      pOutput->StartField(name);
}
void CommandContext::EndField() const
{
   if( pOutput )
      pOutput->EndField();
}
void CommandContext::AddItem(const wxString &value , const wxString &name ) const
{
   if( pOutput )
      pOutput->AddItem( value, name );
}
void CommandContext::AddBool(const bool value      , const wxString &name ) const
{
   if( pOutput )
      pOutput->AddItem( value, name );
}
void CommandContext::AddItem(const double value    , const wxString &name ) const
{
   if( pOutput )
      pOutput->AddItem( value, name );
}