Audacity  3.0.3
ProjectSerializer.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  ProjectSerializer.h
8 
9 *******************************************************************/
10 
11 #ifndef __AUDACITY_PROJECTSERIALIZER__
12 #define __AUDACITY_PROJECTSERIALIZER__
13 
14 #include "XMLTagHandler.h"
15 
16 #include <wx/mstream.h> // member variables
17 
18 #include <unordered_set>
19 #include <unordered_map>
20 #include "Identifier.h"
21 
22 // From SampleBlock.h
23 using SampleBlockID = long long;
24 
28 
29 using NameMap = std::unordered_map<wxString, unsigned short>;
30 using IdMap = std::unordered_map<unsigned short, wxString>;
31 
32 // This class's overrides do NOT throw AudacityException.
33 class AUDACITY_DLL_API ProjectSerializer final : public XMLWriter
34 {
35 public:
36 
37  static TranslatableString FailureMessage( const FilePath &filePath );
38 
39  ProjectSerializer(size_t allocSize = 1024 * 1024);
40  virtual ~ProjectSerializer();
41 
42  void StartTag(const wxString & name) override;
43  void EndTag(const wxString & name) override;
44 
45  void WriteAttr(const wxString & name, const wxString &value) override;
46  void WriteAttr(const wxString & name, const wxChar *value) override;
47 
48  void WriteAttr(const wxString & name, int value) override;
49  void WriteAttr(const wxString & name, bool value) override;
50  void WriteAttr(const wxString & name, long value) override;
51  void WriteAttr(const wxString & name, long long value) override;
52  void WriteAttr(const wxString & name, size_t value) override;
53  void WriteAttr(const wxString & name, float value, int digits = -1) override;
54  void WriteAttr(const wxString & name, double value, int digits = -1) override;
55 
56  void WriteData(const wxString & value) override;
57  void Write(const wxString & data) override;
58 
59  // Non-override functions
60  void WriteSubTree(const ProjectSerializer & value);
61 
62  const wxMemoryBuffer &GetDict() const;
63  const wxMemoryBuffer &GetData() const;
64 
65  bool IsEmpty() const;
66  bool DictChanged() const;
67 
68  // Returns empty string if decoding fails
69  static wxString Decode(const wxMemoryBuffer &buffer);
70 
71 private:
72  void WriteName(const wxString & name);
73 
74 private:
75  wxMemoryBuffer mBuffer;
77 
78  static NameMap mNames;
79  static wxMemoryBuffer mDict;
80 };
81 
82 #endif
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
XMLWriter::EndTag
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:99
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
ProjectSerializer::mNames
static NameMap mNames
Definition: ProjectSerializer.h:78
ProjectSerializer::mDict
static wxMemoryBuffer mDict
Definition: ProjectSerializer.h:79
SampleBlockID
long long SampleBlockID
Definition: ProjectFileIO.h:39
XMLTagHandler.h
FilePath
wxString FilePath
Definition: Project.h:20
IdMap
std::unordered_map< unsigned short, wxString > IdMap
Definition: ProjectSerializer.h:30
name
const TranslatableString name
Definition: Distortion.cpp:98
Identifier.h
ProjectSerializer::mDictChanged
bool mDictChanged
Definition: ProjectSerializer.h:76
NameMap
std::unordered_map< wxString, unsigned short > NameMap
Definition: ProjectSerializer.h:29
XMLWriter::Write
virtual void Write(const wxString &data)=0
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
XMLWriter::WriteSubTree
virtual void WriteSubTree(const wxString &value)
Definition: XMLWriter.cpp:211
ProjectSerializer::mBuffer
wxMemoryBuffer mBuffer
Definition: ProjectSerializer.h:75
XMLWriter::WriteData
virtual void WriteData(const wxString &value)
Definition: XMLWriter.cpp:199
ProjectSerializer
a class used to (de)serialize the project catalog
Definition: ProjectSerializer.h:34
XMLWriter::StartTag
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:76