Audacity  2.2.0
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/dynarray.h>
21 #include <wx/ffile.h>
22 #include <wx/hashmap.h>
23 #include <wx/mstream.h>
24 
25 //
26 // Show auto recovery dialog if there are projects to recover. Should be
27 // called once at Audacity startup.
28 //
29 // This function possibly opens NEW project windows while it recovers all
30 // projects. If so, it will re-use *pproj, if != NULL and set it to NULL.
31 //
32 // Returns: True, if the start of Audacity should continue as normal
33 // False if Audacity should be quit immediately
34 //
35 // The didRecoverAnything param is strictly for a return value.
36 // Any value passed in is ignored.
37 //
39  bool *didRecoverAnything);
40 
41 //
42 // XML Handler for a <recordingrecovery> tag
43 //
45 {
46 public:
48  bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
49  void HandleXMLEndTag(const wxChar *tag) override;
50  XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
51 
52  // This class only knows reading tags
53 
54 private:
55 
56  int FindTrack() const;
57 
59  int mChannel;
62 };
63 
67 
68 // Should be plain ASCII
69 #define AutoSaveIdent "<?xml autosave>"
70 
71 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(short, NameMap, class AUDACITY_DLL_API);
72 WX_DECLARE_HASH_MAP_WITH_DECL(short, wxString, wxIntegerHash, wxIntegerEqual, IdMap, class AUDACITY_DLL_API);
73 WX_DECLARE_OBJARRAY_WITH_DECL(IdMap, IdMapArray, class AUDACITY_DLL_API);
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;
117  NameMap mNames;
118  size_t mAllocSize;
119 };
120 
121 
122 #endif
RecordingRecoveryHandler(AudacityProject *proj)
Recording recovery handler.
Definition: AutoRecovery.cpp:272
size_t mAllocSize
Definition: AutoRecovery.h:118
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:68
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:121
wxMemoryOutputStream mDict
Definition: AutoRecovery.h:116
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:91
int mChannel
Definition: AutoRecovery.h:59
XMLTagHandler * HandleXMLChild(const wxChar *tag) override
Definition: AutoRecovery.cpp:419
int FindTrack() const
Definition: AutoRecovery.cpp:279
int mAutoSaveIdent
Definition: AutoRecovery.h:61
AudacityProject * mProject
Definition: AutoRecovery.h:58
int mNumChannels
Definition: AutoRecovery.h:60
virtual void Write(const wxString &data)=0
Definition: AutoRecovery.h:44
void HandleXMLEndTag(const wxChar *tag) override
Definition: AutoRecovery.cpp:395
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:161
virtual void WriteSubTree(const wxString &value)
Definition: XMLWriter.cpp:203
WX_DECLARE_OBJARRAY_WITH_DECL(IdMap, IdMapArray, class AUDACITY_DLL_API)
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:69
virtual void WriteData(const wxString &value)
Definition: XMLWriter.cpp:191
NameMap mNames
Definition: AutoRecovery.h:117
WX_DECLARE_HASH_MAP_WITH_DECL(short, wxString, wxIntegerHash, wxIntegerEqual, IdMap, class AUDACITY_DLL_API)
const wxChar * name
Definition: Distortion.cpp:93
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override
Definition: AutoRecovery.cpp:301
bool ShowAutoRecoveryDialogIfNeeded(AudacityProject **pproj, bool *didRecoverAnything)
Definition: AutoRecovery.cpp:225
wxMemoryOutputStream mBuffer
Definition: AutoRecovery.h:115
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(short, NameMap, class AUDACITY_DLL_API)
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:22
Definition: AutoRecovery.h:76