Audacity  2.3.1
Public Member Functions | Public Attributes | List of all members
Shuttle Class Reference

Moves data from one place to another, converting it as required. More...

#include <Shuttle.h>

Inheritance diagram for Shuttle:
ShuttleCli ShuttleParams ShuttlePrefs ShuttleDefaults ShuttleGetAutomation ShuttleGetDefinition ShuttleSetAutomation

Public Member Functions

 Shuttle ()
 
virtual ~Shuttle ()
 
virtual bool TransferBool (const wxString &Name, bool &bValue, const bool &bDefault)
 
virtual bool TransferFloat (const wxString &Name, float &fValue, const float &fDefault)
 
virtual bool TransferDouble (const wxString &Name, double &dValue, const double &dDefault)
 
virtual bool TransferInt (const wxString &Name, int &iValue, const int &iDefault)
 
virtual bool TransferInt (const wxString &Name, wxLongLong_t &iValue, const wxLongLong_t &iDefault)
 
virtual bool TransferLongLong (const wxString &Name, wxLongLong_t &iValue, const wxLongLong_t &iDefault)
 
virtual bool TransferString (const wxString &Name, wxString &strValue, const wxString &strDefault)
 
virtual bool TransferEnum (const wxString &Name, int &iValue, const int nChoices, const wxString *pFirstStr)
 
virtual bool TransferWrappedType (const wxString &Name, WrappedType &W)
 
virtual bool ExchangeWithMaster (const wxString &Name)
 

Public Attributes

bool mbStoreInClient
 
wxString mValueString
 

Detailed Description

Moves data from one place to another, converting it as required.

Shuttle provides a base class for transfering parameter data into and out of clasess into some other structure. This is a common requirement and is needed for:

The 'Master' is the string side of the shuttle transfer, the 'Client' is the binary data side of the transfer.

See Also
ShuttleBase
ShuttleGui

Definition at line 20 of file Shuttle.h.

Constructor & Destructor Documentation

Shuttle::Shuttle ( )

Definition at line 75 of file Shuttle.cpp.

76 {
77 }
virtual Shuttle::~Shuttle ( )
inlinevirtual

Definition at line 24 of file Shuttle.h.

24 {}

Member Function Documentation

bool Shuttle::ExchangeWithMaster ( const wxString &  Name)
virtual

Reimplemented in ShuttleParams, ShuttleCli, and ShuttlePrefs.

Definition at line 259 of file Shuttle.cpp.

Referenced by TransferBool(), TransferDouble(), TransferEnum(), TransferFloat(), TransferInt(), TransferLongLong(), TransferString(), and TransferWrappedType().

260 {
261  // ExchangeWithMaster() will usually be over-ridden
262  // in derived classes. We could have made it an
263  // abstract function.
264  wxASSERT( false );
265  return true;
266 }
bool Shuttle::TransferBool ( const wxString &  Name,
bool &  bValue,
const bool &  bDefault 
)
virtual

Reimplemented in ShuttlePrefs.

Definition at line 79 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, and mValueString.

80 {
81  if( mbStoreInClient )
82  {
83  bValue = bDefault;
84  if( ExchangeWithMaster( Name ))
85  {
86  if( !mValueString.IsEmpty() )
87  bValue = mValueString.GetChar(0) == wxT('y');
88  }
89  }
90  else
91  {
92  mValueString = (bValue==0) ? wxT("no"):wxT("yes");
93  return ExchangeWithMaster( Name );
94  }
95  return true;
96 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28
bool Shuttle::TransferDouble ( const wxString &  Name,
double &  dValue,
const double &  dDefault 
)
virtual

Reimplemented in ShuttlePrefs.

Definition at line 117 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, and mValueString.

118 {
119  if( mbStoreInClient )
120  {
121  dValue = dDefault;
122  if( ExchangeWithMaster( Name ))
123  {
124  if( !mValueString.IsEmpty() )
125  dValue = wxAtof( mValueString );
126  }
127  }
128  else
129  {
130  //%f is format string for double
131  mValueString = wxString::Format(wxT("%f"),dValue);
132  return ExchangeWithMaster( Name );
133  }
134  return true;
135 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28
bool Shuttle::TransferEnum ( const wxString &  Name,
int &  iValue,
const int  nChoices,
const wxString *  pFirstStr 
)
virtual

Definition at line 181 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, and mValueString.

183 {
184  if( mbStoreInClient )
185  {
186  iValue = 0;// default index if none other selected.
187  if( ExchangeWithMaster( Name ))
188  {
189  wxString str = mValueString;
190  if( str.Left( 1 ) == wxT('"') && str.Right( 1 ) == wxT('"') )
191  {
192  str = str.Mid( 2, str.Length() - 2 );
193  }
194 
195  for( int i = 0; i < nChoices; i++ )
196  {
197  if( str.IsSameAs( pFirstStr[i] ))
198  {
199  iValue = i;
200  break;
201  }
202  }
203  }
204  }
205  else
206  {
207  //TIDY-ME: Out of range configuration values are silently discarded...
208  if( iValue > nChoices )
209  iValue = 0;
210  if( iValue < 0 )
211  iValue = 0;
212  mValueString = pFirstStr[iValue];
213  if( mValueString.Find( wxT(' ') ) != wxNOT_FOUND )
214  {
215  mValueString = wxT('"') + pFirstStr[iValue] + wxT('"'); //strings have quotes around them
216  }
217  return ExchangeWithMaster( Name );
218  }
219  return true;
220 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28
bool Shuttle::TransferFloat ( const wxString &  Name,
float &  fValue,
const float &  fDefault 
)
virtual

Definition at line 98 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, and mValueString.

99 {
100  if( mbStoreInClient )
101  {
102  fValue = fDefault;
103  if( ExchangeWithMaster( Name ))
104  {
105  if( !mValueString.IsEmpty() )
106  fValue = wxAtof( mValueString );
107  }
108  }
109  else
110  {
111  mValueString = wxString::Format(wxT("%f"),fValue);
112  return ExchangeWithMaster( Name );
113  }
114  return true;
115 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28
bool Shuttle::TransferInt ( const wxString &  Name,
int &  iValue,
const int &  iDefault 
)
virtual

Reimplemented in ShuttlePrefs.

Definition at line 137 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, and mValueString.

138 {
139  if( mbStoreInClient )
140  {
141  iValue = iDefault;
142  if( ExchangeWithMaster( Name ))
143  {
144  iValue = wxAtoi( mValueString );
145  }
146  }
147  else
148  {
149  mValueString = wxString::Format(wxT("%i"),iValue);
150  return ExchangeWithMaster( Name );
151  }
152  return true;
153 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28
bool Shuttle::TransferInt ( const wxString &  Name,
wxLongLong_t &  iValue,
const wxLongLong_t &  iDefault 
)
virtual

Definition at line 156 of file Shuttle.cpp.

References TransferLongLong().

157 {
158  return TransferLongLong(Name, iValue, iDefault);
159 }
virtual bool TransferLongLong(const wxString &Name, wxLongLong_t &iValue, const wxLongLong_t &iDefault)
Definition: Shuttle.cpp:161
bool Shuttle::TransferLongLong ( const wxString &  Name,
wxLongLong_t &  iValue,
const wxLongLong_t &  iDefault 
)
virtual
Todo:
Fix for long long values.

Definition at line 161 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, and mValueString.

Referenced by TransferInt().

162 {
163  if( mbStoreInClient )
164  {
165  iValue = iDefault;
166  if( ExchangeWithMaster( Name ))
167  {
168  iValue = wxAtoi( mValueString );
169  }
170  }
171  else
172  {
174  mValueString = wxString::Format(wxT("%lld"), (long long) iValue);
175  return ExchangeWithMaster( Name );
176  }
177  return true;
178 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28
bool Shuttle::TransferString ( const wxString &  Name,
wxString &  strValue,
const wxString &  strDefault 
)
virtual

Reimplemented in ShuttlePrefs.

Definition at line 222 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, and mValueString.

Referenced by CommandBuilder::BuildCommand().

223 {
224  if( mbStoreInClient )
225  {
226  if( ExchangeWithMaster( Name ))
227  {
228  strValue = mValueString;
229  }
230  else
231  return false;
232  }
233  else
234  {
235  mValueString = wxT('"') + strValue + wxT('"'); //strings have quotes around them
236  return ExchangeWithMaster( Name );
237  }
238  return true;
239 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28
bool Shuttle::TransferWrappedType ( const wxString &  Name,
WrappedType W 
)
virtual

Reimplemented in ShuttlePrefs.

Definition at line 241 of file Shuttle.cpp.

References ExchangeWithMaster(), mbStoreInClient, mValueString, WrappedType::ReadAsString(), and WrappedType::WriteToAsString().

242 {
243  if( mbStoreInClient )
244  {
245  if( ExchangeWithMaster( Name ))
246  {
248  }
249  }
250  else
251  {
253  return ExchangeWithMaster( Name );
254  }
255  return true;
256 }
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:259
wxString ReadAsString()
void WriteToAsString(const wxString &InStr)
bool mbStoreInClient
Definition: Shuttle.h:27
wxString mValueString
Definition: Shuttle.h:28

Member Data Documentation

bool Shuttle::mbStoreInClient
wxString Shuttle::mValueString

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