Audacity  3.0.3
XMLMethodRegistry.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  XMLMethodRegistry.cpp
6 
7  Paul Licameli
8 
9 **********************************************************************/
10 
11 #include "XMLMethodRegistry.h"
12 
13 #include "Identifier.h"
14 #include <wx/string.h>
15 
18 
20  const wxString &tag, TypeErasedObjectAccessor accessor )
21 {
22  mTagTable[ tag ] = move( accessor );
23 }
24 
26  const wxString &tag, void *p )
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 }
34 
36 {
37  mAccessors.emplace_back( move( accessor ) );
38 }
39 
41  const wxString &tag, TypeErasedMutator mutator )
42 {
43  mMutatorTable[ tag ] = { mAccessors.size() - 1, move( mutator ) };
44 }
45 
47  void *p, const wchar_t *value )
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 }
60 
62 {
63  mWriterTable.emplace_back( move( writer ) );
64 }
65 
66 void XMLMethodRegistryBase::CallWriters( const void *p, XMLWriter &writer )
67 {
68  const auto &table = mWriterTable;
69  for ( auto &fn : table )
70  if (fn)
71  fn( p, writer );
72 }
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
XMLMethodRegistry.h
fn
static const auto fn
Definition: WaveformView.cpp:1108
XMLMethodRegistryBase::mWriterTable
WriterTable mWriterTable
Definition: XMLMethodRegistry.h:68
XMLMethodRegistryBase::~XMLMethodRegistryBase
~XMLMethodRegistryBase()
XMLMethodRegistryBase::TypeErasedWriter
std::function< void(const void *, XMLWriter &) > TypeErasedWriter
Definition: XMLMethodRegistry.h:66
XMLMethodRegistryBase::mAccessors
TypeErasedAccessors mAccessors
Definition: XMLMethodRegistry.h:51
XMLMethodRegistryBase::TypeErasedAccessor
std::function< void *(void *) > TypeErasedAccessor
Definition: XMLMethodRegistry.h:49
XMLMethodRegistryBase::mTagTable
TagTable mTagTable
Definition: XMLMethodRegistry.h:44
Identifier.h
XMLMethodRegistryBase::CallObjectAccessor
XMLTagHandler * CallObjectAccessor(const wxString &tag, void *p)
Definition: XMLMethodRegistry.cpp:25
XMLMethodRegistryBase::PushAccessor
void PushAccessor(TypeErasedAccessor accessor)
Definition: XMLMethodRegistry.cpp:35
XMLMethodRegistryBase::TypeErasedObjectAccessor
std::function< XMLTagHandler *(void *) > TypeErasedObjectAccessor
Definition: XMLMethodRegistry.h:41
XMLTagHandler
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:62
XMLMethodRegistryBase::mMutatorTable
MutatorTable mMutatorTable
Definition: XMLMethodRegistry.h:59
XMLMethodRegistryBase::Register
void Register(const wxString &tag, TypeErasedObjectAccessor accessor)
Definition: XMLMethodRegistry.cpp:19
XMLMethodRegistryBase::CallWriters
void CallWriters(const void *p, XMLWriter &writer)
Definition: XMLMethodRegistry.cpp:66
XMLMethodRegistryBase::XMLMethodRegistryBase
XMLMethodRegistryBase()
XMLMethodRegistryBase::CallAttributeHandler
bool CallAttributeHandler(const wxString &tag, void *p, const wchar_t *value)
Definition: XMLMethodRegistry.cpp:46
XMLMethodRegistryBase::TypeErasedMutator
std::function< void(void *, const wchar_t *) > TypeErasedMutator
Definition: XMLMethodRegistry.h:55