Move the XML writer to its own file

This commit is contained in:
Jean Pierre Cimalando 2020-09-16 16:36:33 +02:00
parent f0dd146361
commit 3e0549e4c9
3 changed files with 34 additions and 18 deletions

View file

@ -29,6 +29,7 @@ set (SFIZZ_HEADERS
sfizz/Debug.h
sfizz/utility/NumericId.h
sfizz/utility/SpinMutex.h
sfizz/utility/XmlHelpers.h
sfizz/modulations/ModId.h
sfizz/modulations/ModKey.h
sfizz/modulations/ModKeyHash.h

View file

@ -19,6 +19,7 @@
#include "modulations/sources/Controller.h"
#include "modulations/sources/LFO.h"
#include "modulations/sources/FlexEnvelope.h"
#include "utility/XmlHelpers.h"
#include "pugixml.hpp"
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
@ -1301,25 +1302,9 @@ std::string sfz::Synth::exportMidnam(absl::string_view model) const
}
}
///
struct string_writer : pugi::xml_writer {
std::string result;
string_writer()
{
result.reserve(8192);
}
void write(const void* data, size_t size) override
{
result.append(static_cast<const char*>(data), size);
}
};
///
string_writer writer;
string_xml_writer writer;
doc.save(writer);
return std::move(writer.result);
return std::move(writer.str());
}
const sfz::Region* sfz::Synth::getRegionView(int idx) const noexcept

View file

@ -0,0 +1,30 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
#include <pugixml.hpp>
#include <string>
class string_xml_writer : public pugi::xml_writer {
public:
explicit string_xml_writer(size_t capacity = 8192)
{
result_.reserve(capacity);
}
void write(const void* data, size_t size) override
{
result_.append(static_cast<const char*>(data), size);
}
std::string& str() noexcept
{
return result_;
}
private:
std::string result_;
};