11#ifndef __AUDACITY_XML_METHOD_REGISTRY__
12#define __AUDACITY_XML_METHOD_REGISTRY__
14#include <forward_list>
19#include <unordered_map>
34template<
typename Substructure >
38template<
typename Substructure >
39using Mutators = std::vector< std::pair< std::string, Mutator<Substructure> > >;
46 std::unordered_map< std::string_view, TypeErasedObjectAccessor >;
48 std::forward_list<std::string>
mTags;
51 XMLTagHandler *CallObjectAccessor(
const std::string_view &tag,
void *p );
62 std::pair<size_t, TypeErasedMutator>>;
68 bool CallAttributeHandler(
const std::string_view& tag,
76 void CallAttributeWriters(
const void *p,
XMLWriter &writer );
80 void CallObjectWriters(
const void *p,
XMLWriter &writer );
86template<
typename Host >
98 typename ObjectAccessor
106 return fn( *
static_cast<Host *
>(p) );
128 typename Substructure
129 = std::remove_reference_t<
decltype(
130 std::declval<Accessor>()( std::declval<Host &>() )
136 auto ®istry =
Get();
137 registry.PushAccessor(
138 [
fn = std::move(
fn) ] (
void *p ) {
140 return &
fn( *
static_cast<Host *
>(p) ); }
142 for (
auto &pair : pairs)
143 registry.Register( pair.first,
144 [
fn = move(pair.second) ](
auto p,
auto value ){
145 fn( *
static_cast<Substructure*
>(p), value ); }
174 [
fn = std::move(
fn) ] (
const void *p,
XMLWriter &writer ) {
176 return fn( *
static_cast<const Host *
>(p), writer );
198 [
fn = std::move(
fn) ] (
const void *p,
XMLWriter &writer ) {
200 return fn( *
static_cast<const Host *
>(p), writer );
218#define DECLARE_XML_METHOD_REGISTRY(DECLSPEC, Name) \
219 template<> auto DECLSPEC Name::Get() -> Name &;
222#define DEFINE_XML_METHOD_REGISTRY(Name) \
223 template<> auto Name::Get() -> Name & \
225 static Name registry; \
A view into an attribute value. The class does not take the ownership of the data.
Implementation helper for ProjectFileIORegistry.
WriterTable mObjectWriterTable
MutatorTable mMutatorTable
std::vector< TypeErasedAccessor > TypeErasedAccessors
TypeErasedAccessors mAccessors
void CallAttributeWriters(const void *p, XMLWriter &writer)
std::function< void(const void *, XMLWriter &) > TypeErasedWriter
std::forward_list< std::string > mMutatorTags
std::unordered_map< std::string_view, std::pair< size_t, TypeErasedMutator > > MutatorTable
From attribute name, to index in accessor table with a mutator.
std::vector< std::pair< std::string, Mutator< Substructure > > > Mutators
A helper type alias for a list of mutators, associated with tag strings.
std::vector< TypeErasedWriter > WriterTable
void RegisterObjectWriter(TypeErasedWriter writer)
void RegisterAttributeWriter(TypeErasedWriter writer)
std::function< XMLTagHandler *(void *) > TypeErasedObjectAccessor
std::function< void *(void *) > TypeErasedAccessor
bool CallAttributeHandler(const std::string_view &tag, void *p, const XMLAttributeValueView &value)
std::function< void(Substructure &, const XMLAttributeValueView &) > Mutator
A helper type alias for a function taking a structure and a string value.
std::unordered_map< std::string_view, TypeErasedObjectAccessor > TagTable
void CallObjectWriters(const void *p, XMLWriter &writer)
std::forward_list< std::string > mTags
std::function< void(void *, const XMLAttributeValueView &) > TypeErasedMutator
WriterTable mAttributeWriterTable
XMLTagHandler * CallObjectAccessor(const std::string_view &tag, void *p)
void Register(std::string tag, TypeErasedObjectAccessor accessor)
XMLTagHandler * CallObjectAccessor(const std::string_view &tag, Host &host)
bool CallAttributeHandler(const std::string_view &tag, Host &host, const XMLAttributeValueView &value)
static XMLMethodRegistry & Get()
Get the unique instance.
void CallWriters(const Host &host, XMLWriter &writer)
This class is an interface which should be implemented by classes which wish to be able to load and s...
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
AttributeReaderEntries(Accessor fn, Mutators< Substructure > pairs)
Typically statically constructed.
AttributeWriterEntry(Writer fn)
ObjectReaderEntry(const std::string &tag, ObjectAccessor fn)
Typically statically constructed.
ObjectWriterEntry(Writer fn)