Audacity  2.2.2
AutoRecovery.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4  Audacity(R) is copyright (c) 1999-2010 Audacity Team.
5  License: GPL v2. See License.txt.
6 
7  AutoRecovery.h
8 
9 *******************************************************************/
10 
11 #ifndef __AUDACITY_AUTORECOVERY__
12 #define __AUDACITY_AUTORECOVERY__
13 
14 #include "Project.h"
15 
16 #include "xml/XMLTagHandler.h"
17 #include "xml/XMLWriter.h"
18 
19 #include <wx/debug.h>
20 #include <wx/ffile.h>
21 #include <wx/hashmap.h>
22 #include <wx/mstream.h>
23 
24 #include <unordered_map>
25 
26 //
27 // Show auto recovery dialog if there are projects to recover. Should be
28 // called once at Audacity startup.
29 //
30 // This function possibly opens NEW project windows while it recovers all
31 // projects. If so, it will re-use *pproj, if != NULL and set it to NULL.
32 //
33 // Returns: True, if the start of Audacity should continue as normal
34 // False if Audacity should be quit immediately
35 //
36 // The didRecoverAnything param is strictly for a return value.
37 // Any value passed in is ignored.
38 //
40  bool *didRecoverAnything);
41 
42 //
43 // XML Handler for a <recordingrecovery> tag
44 //
46 {
47 public:
49  bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
50  void HandleXMLEndTag(const wxChar *tag) override;
51  XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
52 
53  // This class only knows reading tags
54 
55 private:
56 
57  int FindTrack() const;
58 
60  int mChannel;
63 };
64 
68 
69 // Should be plain ASCII
70 #define AutoSaveIdent "<?xml autosave>"
71 
72 using NameMap = std::unordered_map<wxString, short>;
73 using IdMap = std::unordered_map<short, wxString>;
74 
75 // This class's overrides do NOT throw AudacityException.
76 class AUDACITY_DLL_API AutoSaveFile final : public XMLWriter
77 {
78 public:
79 
80  AutoSaveFile(size_t allocSize = 1024 * 1024);
81  virtual ~AutoSaveFile();
82 
83  void StartTag(const wxString & name) override;
84  void EndTag(const wxString & name) override;
85 
86  void WriteAttr(const wxString & name, const wxString &value) override;
87  void WriteAttr(const wxString & name, const wxChar *value) override;
88 
89  void WriteAttr(const wxString & name, int value) override;
90  void WriteAttr(const wxString & name, bool value) override;
91  void WriteAttr(const wxString & name, long value) override;
92  void WriteAttr(const wxString & name, long long value) override;
93  void WriteAttr(const wxString & name, size_t value) override;
94  void WriteAttr(const wxString & name, float value, int digits = -1) override;
95  void WriteAttr(const wxString & name, double value, int digits = -1) override;
96 
97  void WriteData(const wxString & value) override;
98  void Write(const wxString & data) override;
99 
100  // Non-override functions
101  void WriteSubTree(const AutoSaveFile & value);
102 
103  bool Write(wxFFile & file) const;
104  bool Append(wxFFile & file) const;
105 
106  bool IsEmpty() const;
107 
108  bool Decode(const wxString & fileName);
109 
110 private:
111  void WriteName(const wxString & name);
112  void CheckSpace(wxMemoryOutputStream & buf);
113 
114 private:
115  wxMemoryOutputStream mBuffer;
116  wxMemoryOutputStream mDict;
118  size_t mAllocSize;
119 };
120 
121 
122 #endif
RecordingRecoveryHandler(AudacityProject *proj)
Recording recovery handler.
size_t mAllocSize
Definition: AutoRecovery.h:118
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:78
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:131
wxMemoryOutputStream mDict
Definition: AutoRecovery.h:116
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:101
XMLTagHandler * HandleXMLChild(const wxChar *tag) override
AudacityProject * mProject
Definition: AutoRecovery.h:59
std::unordered_map< wxString, short > NameMap
Definition: AutoRecovery.h:72
virtual void Write(const wxString &data)=0
void HandleXMLEndTag(const wxChar *tag) override
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
virtual void WriteSubTree(const wxString &value)
Definition: XMLWriter.cpp:213
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:70
virtual void WriteData(const wxString &value)
Definition: XMLWriter.cpp:201
NameMap mNames
Definition: AutoRecovery.h:117
const wxChar * name
Definition: Distortion.cpp:94
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override
bool ShowAutoRecoveryDialogIfNeeded(AudacityProject **pproj, bool *didRecoverAnything)
std::unordered_map< short, wxString > IdMap
Definition: AutoRecovery.h:73
wxMemoryOutputStream mBuffer
Definition: AutoRecovery.h:115
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:22
a class wrapping reading and writing of arbitrary data in text or binary format to a file...
Definition: AutoRecovery.h:76