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 #ifndef __AUDACITY_OLD_STD__
25 #include <unordered_map>
26 #endif
27 
28 //
29 // Show auto recovery dialog if there are projects to recover. Should be
30 // called once at Audacity startup.
31 //
32 // This function possibly opens NEW project windows while it recovers all
33 // projects. If so, it will re-use *pproj, if != NULL and set it to NULL.
34 //
35 // Returns: True, if the start of Audacity should continue as normal
36 // False if Audacity should be quit immediately
37 //
38 // The didRecoverAnything param is strictly for a return value.
39 // Any value passed in is ignored.
40 //
42  bool *didRecoverAnything);
43 
44 //
45 // XML Handler for a <recordingrecovery> tag
46 //
48 {
49 public:
51  bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
52  void HandleXMLEndTag(const wxChar *tag) override;
53  XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
54 
55  // This class only knows reading tags
56 
57 private:
58 
59  int FindTrack() const;
60 
62  int mChannel;
65 };
66 
70 
71 // Should be plain ASCII
72 #define AutoSaveIdent "<?xml autosave>"
73 
74 using NameMap = std::unordered_map<wxString, short>;
75 using IdMap = std::unordered_map<short, wxString>;
76 
77 // This class's overrides do NOT throw AudacityException.
78 class AUDACITY_DLL_API AutoSaveFile final : public XMLWriter
79 {
80 public:
81 
82  AutoSaveFile(size_t allocSize = 1024 * 1024);
83  virtual ~AutoSaveFile();
84 
85  void StartTag(const wxString & name) override;
86  void EndTag(const wxString & name) override;
87 
88  void WriteAttr(const wxString & name, const wxString &value) override;
89  void WriteAttr(const wxString & name, const wxChar *value) override;
90 
91  void WriteAttr(const wxString & name, int value) override;
92  void WriteAttr(const wxString & name, bool value) override;
93  void WriteAttr(const wxString & name, long value) override;
94  void WriteAttr(const wxString & name, long long value) override;
95  void WriteAttr(const wxString & name, size_t value) override;
96  void WriteAttr(const wxString & name, float value, int digits = -1) override;
97  void WriteAttr(const wxString & name, double value, int digits = -1) override;
98 
99  void WriteData(const wxString & value) override;
100  void Write(const wxString & data) override;
101 
102  // Non-override functions
103  void WriteSubTree(const AutoSaveFile & value);
104 
105  bool Write(wxFFile & file) const;
106  bool Append(wxFFile & file) const;
107 
108  bool IsEmpty() const;
109 
110  bool Decode(const wxString & fileName);
111 
112 private:
113  void WriteName(const wxString & name);
114  void CheckSpace(wxMemoryOutputStream & buf);
115 
116 private:
117  wxMemoryOutputStream mBuffer;
118  wxMemoryOutputStream mDict;
120  size_t mAllocSize;
121 };
122 
123 
124 #endif
RecordingRecoveryHandler(AudacityProject *proj)
Recording recovery handler.
size_t mAllocSize
Definition: AutoRecovery.h:120
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:118
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:101
XMLTagHandler * HandleXMLChild(const wxChar *tag) override
AudacityProject * mProject
Definition: AutoRecovery.h:61
std::unordered_map< wxString, short > NameMap
Definition: AutoRecovery.h:74
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:158
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:119
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:75
wxMemoryOutputStream mBuffer
Definition: AutoRecovery.h:117
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:78