Audacity 3.2.0
Classes | Typedefs | Functions | Variables
Registry::detail Namespace Reference

Classes

struct  BaseItem
 
struct  Builder
 
struct  ComputedItem
 
struct  ComputedItemBase
 
struct  ConsUnique
 
struct  GroupItemBase
 Common abstract base class for items that group other items. More...
 
struct  IndirectItem
 An item that delegates to another held in a shared pointer. More...
 
struct  IndirectItemBase
 
struct  Visitor
 Type-erasing adapter class (with no std::function overhead) More...
 
class  VisitorBase
 

Typedefs

using BaseItemPtr = std::unique_ptr< BaseItem >
 
using BaseItemSharedPtr = std::shared_ptr< BaseItem >
 
template<typename Type , typename List >
using ConsUnique_t = typename ConsUnique< Type, List >::type
 
template<typename RegistryTraits >
using VisitedNodeTypes = ConsUnique_t< const GroupItem< RegistryTraits >, Map_t< Fn< std::add_const_t >, typename RegistryTraits::NodeTypes > >
 
template<typename RegistryTraits >
using VisitedLeafTypes = ConsUnique_t< const SingleItem, Map_t< Fn< std::add_const_t >, typename RegistryTraits::LeafTypes > >
 
template<typename Types >
using VisitorFunction = std::function< void(Head_t< Types > &, const Path &)>
 
template<typename RegistryTraits >
using NodeVisitorFunction = VisitorFunction< VisitedNodeTypes< RegistryTraits > >
 
template<typename RegistryTraits >
using LeafVisitorFunction = VisitorFunction< VisitedLeafTypes< RegistryTraits > >
 
template<typename RegistryTraits >
using VisitorFunctionTriple = std::tuple< NodeVisitorFunction< RegistryTraits >, LeafVisitorFunction< RegistryTraits >, NodeVisitorFunction< RegistryTraits > >
 

Functions

REGISTRIES_API void RegisterItem (GroupItemBase &registry, const Placement &placement, BaseItemPtr pItem)
 Type-erased implementation details, don't call directly. More...
 
template<typename V >
auto ForwardTuple_ (const V &visitor, std::false_type)
 
template<typename V >
auto ForwardTuple_ (const V &visitor, std::true_type)
 
template<typename V >
auto ForwardTuple (const V &visitor)
 
template<typename V >
auto MakeTuple_ (const V &visitor, std::false_type)
 
template<typename V >
auto MakeTuple_ (const V &visitor, std::true_type)
 
template<typename V >
auto MakeTuple (const V &visitor)
 
template<typename V >
auto CaptureTuple_ (const V &visitor, std::true_type)
 
template<typename V >
auto CaptureTuple_ (const V &visitor, std::false_type)
 
template<bool Reference, typename V >
auto CaptureTuple (const V &visitor)
 
template<typename Types , bool Reference, typename Visitor >
VisitorFunction< Types > MakeVisitorFunction (const Visitor &visitor)
 Capture a callable for Visit() in a std::function wrapper. More...
 
REGISTRIES_API void Visit (VisitorBase &visitor, const GroupItemBase *pTopItem, const GroupItemBase *pRegistry, void *pComputedItemContext)
 

Variables

template<typename Visitors >
static constexpr auto TupleSize
 How large a tuple to make from Visitors. More...
 

Typedef Documentation

◆ BaseItemPtr

using Registry::detail::BaseItemPtr = typedef std::unique_ptr<BaseItem>

Definition at line 91 of file Registry.h.

◆ BaseItemSharedPtr

using Registry::detail::BaseItemSharedPtr = typedef std::shared_ptr<BaseItem>

Definition at line 93 of file Registry.h.

◆ ConsUnique_t

template<typename Type , typename List >
using Registry::detail::ConsUnique_t = typedef typename ConsUnique<Type, List>::type

Definition at line 116 of file Registry.h.

◆ LeafVisitorFunction

template<typename RegistryTraits >
using Registry::detail::LeafVisitorFunction = typedef VisitorFunction<VisitedLeafTypes<RegistryTraits> >

Definition at line 460 of file Registry.h.

◆ NodeVisitorFunction

template<typename RegistryTraits >
using Registry::detail::NodeVisitorFunction = typedef VisitorFunction<VisitedNodeTypes<RegistryTraits> >

Definition at line 458 of file Registry.h.

◆ VisitedLeafTypes

template<typename RegistryTraits >
using Registry::detail::VisitedLeafTypes = typedef ConsUnique_t<const SingleItem, Map_t<Fn<std::add_const_t>, typename RegistryTraits::LeafTypes> >

Definition at line 122 of file Registry.h.

◆ VisitedNodeTypes

template<typename RegistryTraits >
using Registry::detail::VisitedNodeTypes = typedef ConsUnique_t<const GroupItem<RegistryTraits>, Map_t<Fn<std::add_const_t>, typename RegistryTraits::NodeTypes> >

Definition at line 119 of file Registry.h.

◆ VisitorFunction

template<typename Types >
using Registry::detail::VisitorFunction = typedef std::function<void(Head_t<Types> &, const Path &)>

Definition at line 125 of file Registry.h.

◆ VisitorFunctionTriple

template<typename RegistryTraits >
using Registry::detail::VisitorFunctionTriple = typedef std::tuple< NodeVisitorFunction<RegistryTraits>, LeafVisitorFunction<RegistryTraits>, NodeVisitorFunction<RegistryTraits> >

Definition at line 462 of file Registry.h.

Function Documentation

◆ CaptureTuple()

template<bool Reference, typename V >
auto Registry::detail::CaptureTuple ( const V &  visitor)

Definition at line 434 of file Registry.h.

434 {
435 return CaptureTuple_(visitor, std::bool_constant<Reference>{});
436 }
auto CaptureTuple_(const V &visitor, std::false_type)
Definition: Registry.h:430

References CaptureTuple_().

Here is the call graph for this function:

◆ CaptureTuple_() [1/2]

template<typename V >
auto Registry::detail::CaptureTuple_ ( const V &  visitor,
std::false_type   
)

Definition at line 430 of file Registry.h.

430 {
431 // Capture by value
432 return MakeTuple(visitor);
433 }
auto MakeTuple(const V &visitor)
Definition: Registry.h:421

References MakeTuple().

Here is the call graph for this function:

◆ CaptureTuple_() [2/2]

template<typename V >
auto Registry::detail::CaptureTuple_ ( const V &  visitor,
std::true_type   
)

Definition at line 426 of file Registry.h.

426 {
427 // Capture by reference
428 return ForwardTuple(visitor);
429 }
auto ForwardTuple(const V &visitor)
Definition: Registry.h:408

References ForwardTuple().

Referenced by CaptureTuple().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ForwardTuple()

template<typename V >
auto Registry::detail::ForwardTuple ( const V &  visitor)

Definition at line 408 of file Registry.h.

408 {
409 return ForwardTuple_(visitor,
410 std::bool_constant<Tuple::is_tuple_like_v<V>>{});
411 }
auto ForwardTuple_(const V &visitor, std::true_type)
Definition: Registry.h:404

References ForwardTuple_().

Referenced by Registry::detail::Visitor< RegistryTraits, Visitors >::BeginGroup(), CaptureTuple_(), Registry::detail::Visitor< RegistryTraits, Visitors >::EndGroup(), and Registry::detail::Visitor< RegistryTraits, Visitors >::Visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ForwardTuple_() [1/2]

template<typename V >
auto Registry::detail::ForwardTuple_ ( const V &  visitor,
std::false_type   
)

Definition at line 400 of file Registry.h.

400 {
401 // Visitor is not a tuple
402 return std::tuple<const V&>{ visitor };
403 }

Referenced by ForwardTuple().

Here is the caller graph for this function:

◆ ForwardTuple_() [2/2]

template<typename V >
auto Registry::detail::ForwardTuple_ ( const V &  visitor,
std::true_type   
)

Definition at line 404 of file Registry.h.

404 {
405 // Visitor is a tuple
406 return Tuple::ForwardAll(visitor);
407 }
auto ForwardAll(Tuple &&tuple)
Forwarding of all of a tuple.
Definition: Tuple.h:130

References Tuple::ForwardAll().

Here is the call graph for this function:

◆ MakeTuple()

template<typename V >
auto Registry::detail::MakeTuple ( const V &  visitor)

Definition at line 421 of file Registry.h.

421 {
422 return MakeTuple_(visitor,
423 std::bool_constant<Tuple::is_tuple_like_v<V>>{});
424 }
auto MakeTuple_(const V &visitor, std::true_type)
Definition: Registry.h:417

References MakeTuple_().

Referenced by CaptureTuple_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeTuple_() [1/2]

template<typename V >
auto Registry::detail::MakeTuple_ ( const V &  visitor,
std::false_type   
)

Definition at line 413 of file Registry.h.

413 {
414 // Visitor is not a tuple
415 return std::tuple<V>{ visitor };
416 }

Referenced by MakeTuple().

Here is the caller graph for this function:

◆ MakeTuple_() [2/2]

template<typename V >
auto Registry::detail::MakeTuple_ ( const V &  visitor,
std::true_type   
)

Definition at line 417 of file Registry.h.

417 {
418 // Visitor is a tuple
419 return Tuple::All(visitor);
420 }
auto All(Tuple &&tuple)
Projection of all of a tuple.
Definition: Tuple.h:120

References Tuple::All().

Here is the call graph for this function:

◆ MakeVisitorFunction()

template<typename Types , bool Reference, typename Visitor >
VisitorFunction< Types > Registry::detail::MakeVisitorFunction ( const Visitor visitor)

Capture a callable for Visit() in a std::function wrapper.

Definition at line 440 of file Registry.h.

440 {
441 return [visitor = CaptureTuple<Reference>(visitor)](
442 Head_t<Types> &object, const Path &path
443 ){
444 // The compile time checking of reachability of cases still applies
445 // before the visitor is wrapped
446 TypeSwitch::Dispatch<void, Types>(object, visitor, path);
447 };
448 }
std::vector< Identifier > Path
Definition: Registry.h:71
typename Head< TypeList >::type Head_t
Definition: TypeList.h:95

◆ RegisterItem()

void Registry::detail::RegisterItem ( GroupItemBase registry,
const Placement placement,
BaseItemPtr  pItem 
)

Type-erased implementation details, don't call directly.

Definition at line 765 of file Registry.cpp.

767{
768 // Since registration determines only an unordered tree of menu items,
769 // we can sort children of each node lexicographically for our convenience.
770 std::vector<BaseItemPtr> *pItems{};
771 struct Comparator {
772 bool operator()
773 ( const Identifier &component, const BaseItemPtr& pItem ) const {
774 return component < pItem->name; }
775 bool operator()
776 ( const BaseItemPtr& pItem, const Identifier &component ) const {
777 return pItem->name < component; }
778 };
779 auto find = [&pItems]( const Identifier &component ){ return std::equal_range(
780 pItems->begin(), pItems->end(), component, Comparator() ); };
781
782 auto pNode = &registry;
783 pItems = &pNode->items;
784
785 const auto pathComponents = ::wxSplit( placement.path, '/' );
786 auto pComponent = pathComponents.begin(), end = pathComponents.end();
787
788 // Descend the registry hierarchy, while groups matching the path components
789 // can be found
790 auto debugPath = wxString{'/'} + registry.name.GET();
791 while ( pComponent != end ) {
792 const auto &pathComponent = *pComponent;
793
794 // Try to find an item already present that is a group item with the
795 // same name; we don't care which if there is more than one.
796 const auto range = find( pathComponent );
797 const auto iter2 = std::find_if( range.first, range.second,
798 [](const BaseItemPtr &pItem){
799 return dynamic_cast< GroupItemBase* >( pItem.get() ); } );
800
801 if ( iter2 != range.second ) {
802 // A matching group in the registry, so descend
803 pNode = static_cast< GroupItemBase* >( iter2->get() );
804 pItems = &pNode->items;
805 debugPath += '/' + pathComponent;
806 ++pComponent;
807 }
808 else
809 // Insert at this level;
810 // If there are no more path components, and a name collision of
811 // the added item with something already in the registry, don't resolve
812 // it yet in this function, but see MergeItems().
813 break;
814 }
815
816 // Create path group items for remaining components
817 while ( pComponent != end ) {
818 auto newNode =
819 std::make_unique<PlaceHolder>(*pComponent, GroupItemBase::Weak);
820 pNode = newNode.get();
821 pItems->insert( find( pNode->name ).second, std::move( newNode ) );
822 pItems = &pNode->items;
823 ++pComponent;
824 }
825
826 // Remember the hint, to be used later in merging.
827 pItem->orderingHint = placement.hint;
828
829 // Now insert the item.
830 pItems->insert( find( pItem->name ).second, std::move( pItem ) );
831}
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
std::unique_ptr< BaseItem > BaseItemPtr
Definition: Registry.h:91
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
OrderingHint hint
Definition: Registry.h:305

References details::end(), Registry::Placement::hint, Composite::Base< Component, ComponentPointer, ComponentArgs >::items, and Registry::Placement::path.

Referenced by Registry::RegisterItem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Visit()

void Registry::detail::Visit ( VisitorBase visitor,
const GroupItemBase pTopItem,
const GroupItemBase pRegistry,
void *  pComputedItemContext 
)

Definition at line 725 of file Registry.cpp.

728{
729 assert(pComputedItemContext);
730 std::vector< BaseItemSharedPtr > computedItems;
731 bool doFlush = false;
732 CollectedItems collection{ {}, computedItems };
733 Path emptyPath;
734 VisitItem(
735 visitor, collection, emptyPath, pTopItem,
736 pRegistry, pRegistry->orderingHint, doFlush, pComputedItemContext);
737 // Flush any writes done by MergeItems()
738 if (doFlush)
739 gPrefs->Flush();
740}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
virtual bool Flush() noexcept=0
void VisitItem(VisitorBase &visitor, CollectedItems &collection, Path &path, const BaseItem *pItem, const GroupItemBase *pToMerge, const OrderingHint &hint, bool &doFlush, void *pComputedItemContext)
Definition: Registry.cpp:678

References audacity::BasicSettings::Flush(), gPrefs, and anonymous_namespace{Registry.cpp}::VisitItem().

Here is the call graph for this function:

Variable Documentation

◆ TupleSize

template<typename Visitors >
constexpr auto Registry::detail::TupleSize
staticconstexpr
Initial value:
=
std::conditional_t<
Tuple::is_tuple_like_v<Visitors>,
std::tuple_size<Visitors>,
std::integral_constant<size_t, 1>
>::value

How large a tuple to make from Visitors.

Definition at line 451 of file Registry.h.