Audacity 3.2.0
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
XMLMethodRegistryBase Class Reference

Implementation helper for ProjectFileIORegistry. More...

#include <XMLMethodRegistry.h>

Inheritance diagram for XMLMethodRegistryBase:
[legend]
Collaboration diagram for XMLMethodRegistryBase:
[legend]

Public Types

template<typename Substructure >
using Mutator = std::function< void(Substructure &, const XMLAttributeValueView &) >
 A helper type alias for a function taking a structure and a string value. More...
 
template<typename Substructure >
using Mutators = std::vector< std::pair< std::string, Mutator< Substructure > > >
 A helper type alias for a list of mutators, associated with tag strings. More...
 

Public Member Functions

 XMLMethodRegistryBase ()
 
 ~XMLMethodRegistryBase ()
 

Protected Types

using TypeErasedObjectAccessor = std::function< XMLTagHandler *(void *) >
 
using TagTable = std::unordered_map< std::string_view, TypeErasedObjectAccessor >
 
using TypeErasedAccessor = std::function< void *(void *) >
 
using TypeErasedAccessors = std::vector< TypeErasedAccessor >
 
using TypeErasedMutator = std::function< void(void *, const XMLAttributeValueView &) >
 
using MutatorTable = std::unordered_map< std::string_view, std::pair< size_t, TypeErasedMutator > >
 From attribute name, to index in accessor table with a mutator. More...
 
using TypeErasedWriter = std::function< void(const void *, XMLWriter &) >
 
using WriterTable = std::vector< TypeErasedWriter >
 

Protected Member Functions

void Register (std::string tag, TypeErasedObjectAccessor accessor)
 
XMLTagHandlerCallObjectAccessor (const std::string_view &tag, void *p)
 
void PushAccessor (TypeErasedAccessor accessor)
 
void Register (std::string tag, TypeErasedMutator mutator)
 
bool CallAttributeHandler (const std::string_view &tag, void *p, const XMLAttributeValueView &value)
 
void RegisterAttributeWriter (TypeErasedWriter writer)
 
void CallAttributeWriters (const void *p, XMLWriter &writer)
 
void RegisterObjectWriter (TypeErasedWriter writer)
 
void CallObjectWriters (const void *p, XMLWriter &writer)
 

Protected Attributes

TagTable mTagTable
 
std::forward_list< std::string > mTags
 
TypeErasedAccessors mAccessors
 
MutatorTable mMutatorTable
 
std::forward_list< std::string > mMutatorTags
 
WriterTable mAttributeWriterTable
 
WriterTable mObjectWriterTable
 

Detailed Description

Implementation helper for ProjectFileIORegistry.

It makes most of the work non-inline and is used by derived classes that supply thin inline type-erasing wrappers.

Definition at line 30 of file XMLMethodRegistry.h.

Member Typedef Documentation

◆ Mutator

template<typename Substructure >
using XMLMethodRegistryBase::Mutator = std::function< void(Substructure&, const XMLAttributeValueView &) >

A helper type alias for a function taking a structure and a string value.

Definition at line 35 of file XMLMethodRegistry.h.

◆ Mutators

template<typename Substructure >
using XMLMethodRegistryBase::Mutators = std::vector< std::pair< std::string, Mutator<Substructure> > >

A helper type alias for a list of mutators, associated with tag strings.

Definition at line 39 of file XMLMethodRegistry.h.

◆ MutatorTable

using XMLMethodRegistryBase::MutatorTable = std::unordered_map<std::string_view, std::pair<size_t, TypeErasedMutator> >
protected

From attribute name, to index in accessor table with a mutator.

Definition at line 61 of file XMLMethodRegistry.h.

◆ TagTable

using XMLMethodRegistryBase::TagTable = std::unordered_map< std::string_view, TypeErasedObjectAccessor >
protected

Definition at line 45 of file XMLMethodRegistry.h.

◆ TypeErasedAccessor

using XMLMethodRegistryBase::TypeErasedAccessor = std::function< void*( void* ) >
protected

Definition at line 53 of file XMLMethodRegistry.h.

◆ TypeErasedAccessors

Definition at line 54 of file XMLMethodRegistry.h.

◆ TypeErasedMutator

using XMLMethodRegistryBase::TypeErasedMutator = std::function< void( void*, const XMLAttributeValueView& ) >
protected

Definition at line 59 of file XMLMethodRegistry.h.

◆ TypeErasedObjectAccessor

using XMLMethodRegistryBase::TypeErasedObjectAccessor = std::function< XMLTagHandler *( void* ) >
protected

Definition at line 44 of file XMLMethodRegistry.h.

◆ TypeErasedWriter

using XMLMethodRegistryBase::TypeErasedWriter = std::function< void(const void *, XMLWriter &) >
protected

Definition at line 71 of file XMLMethodRegistry.h.

◆ WriterTable

using XMLMethodRegistryBase::WriterTable = std::vector< TypeErasedWriter >
protected

Definition at line 72 of file XMLMethodRegistry.h.

Constructor & Destructor Documentation

◆ XMLMethodRegistryBase()

XMLMethodRegistryBase::XMLMethodRegistryBase ( )
default

◆ ~XMLMethodRegistryBase()

XMLMethodRegistryBase::~XMLMethodRegistryBase ( )
default

Member Function Documentation

◆ CallAttributeHandler()

bool XMLMethodRegistryBase::CallAttributeHandler ( const std::string_view &  tag,
void *  p,
const XMLAttributeValueView value 
)
protected

Definition at line 52 of file XMLMethodRegistry.cpp.

54{
55 const auto &table = mMutatorTable;
56 if (auto iter = table.find(tag); iter != table.end())
57 // Tag is known
58 if (auto &pair = iter->second;
59 pair.second && pair.first < mAccessors.size() )
60 // Mutator is not null and accessor exists
61 if (auto &accessor = mAccessors[pair.first])
62 // Accessor is not null; compose accessor and mutator
63 return pair.second( accessor( p ), value ), true;
64 return false;
65}
TypeErasedAccessors mAccessors

References mAccessors, and mMutatorTable.

Referenced by XMLMethodRegistry< Host >::CallAttributeHandler().

Here is the caller graph for this function:

◆ CallAttributeWriters()

void XMLMethodRegistryBase::CallAttributeWriters ( const void *  p,
XMLWriter writer 
)
protected

Definition at line 72 of file XMLMethodRegistry.cpp.

74{
75 const auto &table = mAttributeWriterTable;
76 for ( auto &fn : table )
77 if (fn)
78 fn( p, writer );
79}
static const auto fn
WriterTable mAttributeWriterTable

References fn, and mAttributeWriterTable.

Referenced by XMLMethodRegistry< Host >::CallWriters().

Here is the caller graph for this function:

◆ CallObjectAccessor()

XMLTagHandler * XMLMethodRegistryBase::CallObjectAccessor ( const std::string_view &  tag,
void *  p 
)
protected

Definition at line 29 of file XMLMethodRegistry.cpp.

31{
32 const auto &table = mTagTable;
33 if (auto iter = table.find( tag ); iter != table.end())
34 if (auto &fn = iter->second)
35 return fn( p );
36 return nullptr;
37}

References fn, and mTagTable.

Referenced by XMLMethodRegistry< Host >::CallObjectAccessor().

Here is the caller graph for this function:

◆ CallObjectWriters()

void XMLMethodRegistryBase::CallObjectWriters ( const void *  p,
XMLWriter writer 
)
protected

Definition at line 86 of file XMLMethodRegistry.cpp.

88{
89 const auto &table = mObjectWriterTable;
90 for ( auto &fn : table )
91 if (fn)
92 fn( p, writer );
93}
WriterTable mObjectWriterTable

References fn, and mObjectWriterTable.

Referenced by XMLMethodRegistry< Host >::CallWriters().

Here is the caller graph for this function:

◆ PushAccessor()

void XMLMethodRegistryBase::PushAccessor ( TypeErasedAccessor  accessor)
protected

Definition at line 39 of file XMLMethodRegistry.cpp.

40{
41 mAccessors.emplace_back( move( accessor ) );
42}

References mAccessors.

◆ Register() [1/2]

void XMLMethodRegistryBase::Register ( std::string  tag,
TypeErasedMutator  mutator 
)
protected

Definition at line 44 of file XMLMethodRegistry.cpp.

46{
47 // Similar to the other overload of Register
48 auto &newtag = mMutatorTags.emplace_front(move(tag));
49 mMutatorTable[ newtag ] = { mAccessors.size() - 1, move( mutator ) };
50}
std::forward_list< std::string > mMutatorTags

References mAccessors, mMutatorTable, and mMutatorTags.

◆ Register() [2/2]

void XMLMethodRegistryBase::Register ( std::string  tag,
TypeErasedObjectAccessor  accessor 
)
protected

Definition at line 18 of file XMLMethodRegistry.cpp.

20{
21 // Store string in a separate container from the map, so the map
22 // can be keyed by string_view.
23 // Beware small-string optimization! Be sure strings don't relocate for
24 // growth of the container. Use a list, not a vector.
25 auto &newtag = mTags.emplace_front(move(tag));
26 mTagTable[ newtag ] = move( accessor );
27}
std::forward_list< std::string > mTags

References mTags, and mTagTable.

Referenced by XMLMethodRegistry< Host >::ObjectReaderEntry::ObjectReaderEntry().

Here is the caller graph for this function:

◆ RegisterAttributeWriter()

void XMLMethodRegistryBase::RegisterAttributeWriter ( TypeErasedWriter  writer)
protected

Definition at line 67 of file XMLMethodRegistry.cpp.

68{
69 mAttributeWriterTable.emplace_back( move( writer ) );
70}

References mAttributeWriterTable.

Referenced by XMLMethodRegistry< Host >::AttributeWriterEntry::AttributeWriterEntry().

Here is the caller graph for this function:

◆ RegisterObjectWriter()

void XMLMethodRegistryBase::RegisterObjectWriter ( TypeErasedWriter  writer)
protected

Definition at line 81 of file XMLMethodRegistry.cpp.

82{
83 mObjectWriterTable.emplace_back( move( writer ) );
84}

References mObjectWriterTable.

Referenced by XMLMethodRegistry< Host >::ObjectWriterEntry::ObjectWriterEntry().

Here is the caller graph for this function:

Member Data Documentation

◆ mAccessors

TypeErasedAccessors XMLMethodRegistryBase::mAccessors
protected

Definition at line 55 of file XMLMethodRegistry.h.

Referenced by CallAttributeHandler(), PushAccessor(), and Register().

◆ mAttributeWriterTable

WriterTable XMLMethodRegistryBase::mAttributeWriterTable
protected

Definition at line 74 of file XMLMethodRegistry.h.

Referenced by CallAttributeWriters(), and RegisterAttributeWriter().

◆ mMutatorTable

MutatorTable XMLMethodRegistryBase::mMutatorTable
protected

Definition at line 63 of file XMLMethodRegistry.h.

Referenced by CallAttributeHandler(), and Register().

◆ mMutatorTags

std::forward_list<std::string> XMLMethodRegistryBase::mMutatorTags
protected

Definition at line 64 of file XMLMethodRegistry.h.

Referenced by Register().

◆ mObjectWriterTable

WriterTable XMLMethodRegistryBase::mObjectWriterTable
protected

Definition at line 78 of file XMLMethodRegistry.h.

Referenced by CallObjectWriters(), and RegisterObjectWriter().

◆ mTags

std::forward_list<std::string> XMLMethodRegistryBase::mTags
protected

Definition at line 48 of file XMLMethodRegistry.h.

Referenced by Register().

◆ mTagTable

TagTable XMLMethodRegistryBase::mTagTable
protected

Definition at line 47 of file XMLMethodRegistry.h.

Referenced by CallObjectAccessor(), and Register().


The documentation for this class was generated from the following files: