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 53 of file XMLMethodRegistry.cpp.

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

75{
76 const auto &table = mAttributeWriterTable;
77 for ( auto &fn : table )
78 if (fn)
79 fn( p, writer );
80}
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 30 of file XMLMethodRegistry.cpp.

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

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 87 of file XMLMethodRegistry.cpp.

89{
90 const auto &table = mObjectWriterTable;
91 for ( auto &fn : table )
92 if (fn)
93 fn( p, writer );
94}
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 40 of file XMLMethodRegistry.cpp.

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

References mAccessors.

◆ Register() [1/2]

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

Definition at line 45 of file XMLMethodRegistry.cpp.

47{
48 // Similar to the other overload of Register
49 auto &newtag = mMutatorTags.emplace_front(move(tag));
50 mMutatorTable[ newtag ] = { mAccessors.size() - 1, move( mutator ) };
51}
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 19 of file XMLMethodRegistry.cpp.

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

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

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 82 of file XMLMethodRegistry.cpp.

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

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: