| 289 | } |
| 290 | |
| 291 | bool Dispatch() |
| 292 | { |
| 293 | if ( GetError() ) |
| 294 | // Don't repeatedly indicate error |
| 295 | // Do nothing |
| 296 | return false; |
| 297 | |
| 298 | if ( !IsReplaying() ) |
| 299 | return false; |
| 300 | |
| 301 | // This will throw if no lines remain. A proper journal should exit the |
| 302 | // program before that happens. |
| 303 | auto words = GetTokens(); |
| 304 | |
| 305 | // Lookup dispatch function by the first field of the line |
| 306 | auto &table = GetDictionary(); |
| 307 | auto &name = words[0]; |
| 308 | auto iter = table.find( name ); |
| 309 | if (iter == table.end()) |
| 310 | throw SyncException( |
| 311 | wxString::Format("unknown command: %s", name.ToStdString().c_str())); |
| 312 | |
| 313 | // Pass all the fields including the command name to the function |
| 314 | if (!iter->second(words)) |
| 315 | throw SyncException(wxString::Format( |
| 316 | "command '%s' has failed", wxJoin(words, ',').ToStdString().c_str())); |
| 317 | |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | void Sync( const wxString &string ) |
| 322 | { |