Audacity  3.0.3
JournalOutput.cpp
Go to the documentation of this file.
1 /*!********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  @file JournalOutput.cpp
6 
7  Paul Licameli
8 
9 **********************************************************************/
10 
11 #include "JournalOutput.h"
12 
13 #include <wx/textfile.h>
14 #include "wxArrayStringEx.h"
15 
16 namespace Journal {
17 
18 namespace {
19 
20 struct FlushingTextFile : wxTextFile {
21  // Flush output when the program quits, even if that makes an incomplete
22  // journal file without an exit
23  ~FlushingTextFile() { if ( IsOpened() ) { Write(); Close(); } }
25 
26 }
27 
29 {
30  return sFileOut.IsOpened();
31 }
32 
33 bool OpenOut( const wxString &fullPath )
34 {
35  sFileOut.Open( fullPath );
36  if ( sFileOut.IsOpened() )
37  sFileOut.Clear();
38  else {
39  sFileOut.Create();
40  sFileOut.Open( fullPath );
41  }
42  return sFileOut.IsOpened();
43 }
44 
45 void Output( const wxString &string )
46 {
47  if ( IsRecording() )
48  sFileOut.AddLine( string );
49 }
50 
51 void Output( const wxArrayString &strings )
52 {
53  if ( IsRecording() )
54  Output( ::wxJoin( strings, SeparatorCharacter, EscapeCharacter ) );
55 }
56 
57 void Output( std::initializer_list< const wxString > strings )
58 {
59  return Output( wxArrayStringEx( strings ) );
60 }
61 
62 void Comment( const wxString &string )
63 {
64  if ( IsRecording() )
65  sFileOut.AddLine( CommentCharacter + string );
66 }
67 
68 }
Journal
Facilities for recording and playback of sequences of user interaction.
Journal::anonymous_namespace{JournalOutput.cpp}::FlushingTextFile
Definition: JournalOutput.cpp:20
Journal::OpenOut
bool OpenOut(const wxString &fullPath)
Definition: JournalOutput.cpp:33
Journal::CommentCharacter
constexpr auto CommentCharacter
Definition: JournalOutput.h:24
Journal::SeparatorCharacter
constexpr auto SeparatorCharacter
Definition: JournalOutput.h:22
Journal::anonymous_namespace{JournalOutput.cpp}::sFileOut
Journal::anonymous_namespace{JournalOutput.cpp}::FlushingTextFile sFileOut
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
Journal::Output
void Output(const wxString &string)
Definition: JournalOutput.cpp:45
Journal::IsRecording
bool IsRecording()
Definition: JournalOutput.cpp:28
Journal::Comment
void Comment(const wxString &string)
Definition: JournalOutput.cpp:62
wxArrayStringEx.h
Journal::EscapeCharacter
constexpr auto EscapeCharacter
Definition: JournalOutput.h:23
JournalOutput.h
The output stream of the journal system.
Journal::anonymous_namespace{JournalOutput.cpp}::FlushingTextFile::~FlushingTextFile
~FlushingTextFile()
Definition: JournalOutput.cpp:23