2010-07-06 21:39:08 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
Audacity(R) is copyright (c) 1999-2010 Audacity Team.
|
|
|
|
License: GPL v2. See License.txt.
|
|
|
|
|
2020-07-10 05:50:52 +00:00
|
|
|
ProjectSerializer.h
|
2010-07-06 21:39:08 +00:00
|
|
|
|
|
|
|
*******************************************************************/
|
|
|
|
|
2020-07-10 05:50:52 +00:00
|
|
|
#ifndef __AUDACITY_PROJECTSERIALIZER__
|
|
|
|
#define __AUDACITY_PROJECTSERIALIZER__
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
#include "xml/XMLTagHandler.h"
|
|
|
|
|
2018-11-14 16:48:46 +00:00
|
|
|
#include <wx/mstream.h> // member variables
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2020-07-23 16:17:29 +00:00
|
|
|
#include <unordered_set>
|
2018-01-08 21:38:52 +00:00
|
|
|
#include <unordered_map>
|
2021-05-23 03:20:14 +00:00
|
|
|
#include "Identifier.h"
|
2018-01-08 21:38:52 +00:00
|
|
|
|
2020-07-09 18:14:12 +00:00
|
|
|
// From SampleBlock.h
|
|
|
|
using SampleBlockID = long long;
|
|
|
|
|
2015-04-17 21:42:30 +00:00
|
|
|
///
|
2020-07-10 05:50:52 +00:00
|
|
|
/// ProjectSerializer
|
2015-04-17 21:42:30 +00:00
|
|
|
///
|
|
|
|
|
2020-07-18 04:59:27 +00:00
|
|
|
using NameMap = std::unordered_map<wxString, unsigned short>;
|
|
|
|
using IdMap = std::unordered_map<unsigned short, wxString>;
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2016-12-01 22:03:40 +00:00
|
|
|
// This class's overrides do NOT throw AudacityException.
|
2020-07-10 05:50:52 +00:00
|
|
|
class AUDACITY_DLL_API ProjectSerializer final : public XMLWriter
|
2015-04-17 21:42:30 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2019-12-07 19:30:07 +00:00
|
|
|
static TranslatableString FailureMessage( const FilePath &filePath );
|
2019-04-29 00:51:24 +00:00
|
|
|
|
2020-07-10 05:50:52 +00:00
|
|
|
ProjectSerializer(size_t allocSize = 1024 * 1024);
|
|
|
|
virtual ~ProjectSerializer();
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void StartTag(const wxString & name) override;
|
|
|
|
void EndTag(const wxString & name) override;
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void WriteAttr(const wxString & name, const wxString &value) override;
|
|
|
|
void WriteAttr(const wxString & name, const wxChar *value) override;
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void WriteAttr(const wxString & name, int value) override;
|
|
|
|
void WriteAttr(const wxString & name, bool value) override;
|
|
|
|
void WriteAttr(const wxString & name, long value) override;
|
|
|
|
void WriteAttr(const wxString & name, long long value) override;
|
|
|
|
void WriteAttr(const wxString & name, size_t value) override;
|
|
|
|
void WriteAttr(const wxString & name, float value, int digits = -1) override;
|
|
|
|
void WriteAttr(const wxString & name, double value, int digits = -1) override;
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void WriteData(const wxString & value) override;
|
|
|
|
void Write(const wxString & data) override;
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
// Non-override functions
|
2020-07-10 05:50:52 +00:00
|
|
|
void WriteSubTree(const ProjectSerializer & value);
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2020-07-01 05:45:17 +00:00
|
|
|
const wxMemoryBuffer &GetDict() const;
|
|
|
|
const wxMemoryBuffer &GetData() const;
|
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
bool IsEmpty() const;
|
2020-07-01 05:45:17 +00:00
|
|
|
bool DictChanged() const;
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2020-07-05 19:13:30 +00:00
|
|
|
// Returns empty string if decoding fails
|
2020-09-01 15:54:36 +00:00
|
|
|
static wxString Decode(const wxMemoryBuffer &buffer);
|
2015-04-17 21:42:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void WriteName(const wxString & name);
|
|
|
|
|
|
|
|
private:
|
2020-07-01 05:45:17 +00:00
|
|
|
wxMemoryBuffer mBuffer;
|
|
|
|
bool mDictChanged;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2020-07-01 05:45:17 +00:00
|
|
|
static NameMap mNames;
|
|
|
|
static wxMemoryBuffer mDict;
|
|
|
|
};
|
2015-04-17 21:42:30 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
#endif
|