Audacity  3.0.3
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 wchar_t *) >
 A helper type alias for a function taking a structure and a string value. More...
 
template<typename Substructure >
using Mutators = std::vector< std::pair< wxString, 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< wxString, TypeErasedObjectAccessor >
 
using TypeErasedAccessor = std::function< void *(void *) >
 
using TypeErasedAccessors = std::vector< TypeErasedAccessor >
 
using TypeErasedMutator = std::function< void(void *, const wchar_t *) >
 
using MutatorTable = std::unordered_map< wxString, 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 (const wxString &tag, TypeErasedObjectAccessor accessor)
 
XMLTagHandlerCallObjectAccessor (const wxString &tag, void *p)
 
void PushAccessor (TypeErasedAccessor accessor)
 
void Register (const wxString &tag, TypeErasedMutator mutator)
 
bool CallAttributeHandler (const wxString &tag, void *p, const wchar_t *value)
 
void Register (TypeErasedWriter writer)
 
void CallWriters (const void *p, XMLWriter &writer)
 

Protected Attributes

TagTable mTagTable
 
TypeErasedAccessors mAccessors
 
MutatorTable mMutatorTable
 
WriterTable mWriterTable
 

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 27 of file XMLMethodRegistry.h.

Member Typedef Documentation

◆ Mutator

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

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

Definition at line 32 of file XMLMethodRegistry.h.

◆ Mutators

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

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

Definition at line 36 of file XMLMethodRegistry.h.

◆ MutatorTable

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

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

Definition at line 57 of file XMLMethodRegistry.h.

◆ TagTable

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

Definition at line 42 of file XMLMethodRegistry.h.

◆ TypeErasedAccessor

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

Definition at line 49 of file XMLMethodRegistry.h.

◆ TypeErasedAccessors

Definition at line 50 of file XMLMethodRegistry.h.

◆ TypeErasedMutator

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

Definition at line 55 of file XMLMethodRegistry.h.

◆ TypeErasedObjectAccessor

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

Definition at line 41 of file XMLMethodRegistry.h.

◆ TypeErasedWriter

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

Definition at line 66 of file XMLMethodRegistry.h.

◆ WriterTable

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

Definition at line 67 of file XMLMethodRegistry.h.

Constructor & Destructor Documentation

◆ XMLMethodRegistryBase()

XMLMethodRegistryBase::XMLMethodRegistryBase ( )
default

◆ ~XMLMethodRegistryBase()

XMLMethodRegistryBase::~XMLMethodRegistryBase ( )
default

Member Function Documentation

◆ CallAttributeHandler()

bool XMLMethodRegistryBase::CallAttributeHandler ( const wxString &  tag,
void *  p,
const wchar_t *  value 
)
protected

Definition at line 46 of file XMLMethodRegistry.cpp.

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

References mAccessors, and mMutatorTable.

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

Here is the caller graph for this function:

◆ CallObjectAccessor()

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

Definition at line 25 of file XMLMethodRegistry.cpp.

27 {
28  const auto &table = mTagTable;
29  if (auto iter = table.find( tag ); iter != table.end())
30  if (auto &fn = iter->second)
31  return fn( p );
32  return nullptr;
33 }

References fn, and mTagTable.

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

Here is the caller graph for this function:

◆ CallWriters()

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

Definition at line 66 of file XMLMethodRegistry.cpp.

67 {
68  const auto &table = mWriterTable;
69  for ( auto &fn : table )
70  if (fn)
71  fn( p, writer );
72 }

References fn, and mWriterTable.

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

Here is the caller graph for this function:

◆ PushAccessor()

void XMLMethodRegistryBase::PushAccessor ( TypeErasedAccessor  accessor)
protected

Definition at line 35 of file XMLMethodRegistry.cpp.

36 {
37  mAccessors.emplace_back( move( accessor ) );
38 }

References mAccessors.

◆ Register() [1/3]

void XMLMethodRegistryBase::Register ( const wxString &  tag,
TypeErasedMutator  mutator 
)
protected

Definition at line 40 of file XMLMethodRegistry.cpp.

42 {
43  mMutatorTable[ tag ] = { mAccessors.size() - 1, move( mutator ) };
44 }

References mAccessors, and mMutatorTable.

◆ Register() [2/3]

void XMLMethodRegistryBase::Register ( const wxString &  tag,
TypeErasedObjectAccessor  accessor 
)
protected

Definition at line 19 of file XMLMethodRegistry.cpp.

21 {
22  mTagTable[ tag ] = move( accessor );
23 }

References mTagTable.

Referenced by XMLMethodRegistry< Host >::ObjectReaderEntry::ObjectReaderEntry(), and XMLMethodRegistry< Host >::WriterEntry::WriterEntry().

Here is the caller graph for this function:

◆ Register() [3/3]

void XMLMethodRegistryBase::Register ( TypeErasedWriter  writer)
protected

Definition at line 61 of file XMLMethodRegistry.cpp.

62 {
63  mWriterTable.emplace_back( move( writer ) );
64 }

References mWriterTable.

Member Data Documentation

◆ mAccessors

TypeErasedAccessors XMLMethodRegistryBase::mAccessors
protected

Definition at line 51 of file XMLMethodRegistry.h.

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

◆ mMutatorTable

MutatorTable XMLMethodRegistryBase::mMutatorTable
protected

Definition at line 59 of file XMLMethodRegistry.h.

Referenced by CallAttributeHandler(), and Register().

◆ mTagTable

TagTable XMLMethodRegistryBase::mTagTable
protected

Definition at line 44 of file XMLMethodRegistry.h.

Referenced by CallObjectAccessor(), and Register().

◆ mWriterTable

WriterTable XMLMethodRegistryBase::mWriterTable
protected

Definition at line 68 of file XMLMethodRegistry.h.

Referenced by CallWriters(), and Register().


The documentation for this class was generated from the following files:
fn
static const auto fn
Definition: WaveformView.cpp:1108
XMLMethodRegistryBase::mWriterTable
WriterTable mWriterTable
Definition: XMLMethodRegistry.h:68
XMLMethodRegistryBase::mAccessors
TypeErasedAccessors mAccessors
Definition: XMLMethodRegistry.h:51
XMLMethodRegistryBase::mTagTable
TagTable mTagTable
Definition: XMLMethodRegistry.h:44
XMLMethodRegistryBase::mMutatorTable
MutatorTable mMutatorTable
Definition: XMLMethodRegistry.h:59