Audacity 3.2.0
Namespaces | Classes | Typedefs | Functions
Registry Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  BaseItem
 
struct  DefaultTraits
 
struct  EmptyContext
 
struct  GroupItem
 Extends GroupItemBase with a variadic constructor. More...
 
struct  GroupItemBase
 Common abstract base class for items that group other items. More...
 
struct  OrderingHint
 
struct  OrderingPreferenceInitializer
 
struct  Placement
 
class  RegisteredItem
 Generates classes whose instances register items at construction. More...
 
struct  SingleItem
 Common abstract base class for items that are not groups. More...
 
class  Visitor
 

Typedefs

using BaseItemPtr = std::unique_ptr< BaseItem >
 
using BaseItemSharedPtr = std::shared_ptr< BaseItem >
 
using BaseItemPtrs = std::vector< BaseItemPtr >
 

Functions

void Visit (Visitor &visitor, BaseItem *pTopItem, const GroupItemBase *pRegistry)
 
void RegisterItem (GroupItemBase &registry, const Placement &placement, BaseItemPtr pItem)
 
template<typename Item >
std::unique_ptr< detail::IndirectItem< Item > > Indirect (const std::shared_ptr< Item > &ptr)
 A convenience function. More...
 

Typedef Documentation

◆ BaseItemPtr

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

Definition at line 77 of file Registry.h.

◆ BaseItemPtrs

using Registry::BaseItemPtrs = typedef std::vector<BaseItemPtr>

Definition at line 79 of file Registry.h.

◆ BaseItemSharedPtr

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

Definition at line 78 of file Registry.h.

Function Documentation

◆ Indirect()

template<typename Item >
std::unique_ptr< detail::IndirectItem< Item > > Registry::Indirect ( const std::shared_ptr< Item > &  ptr)
inline

A convenience function.

Definition at line 113 of file Registry.h.

115 {
116 return std::make_unique<detail::IndirectItem<Item>>( ptr );
117 }

◆ RegisterItem()

REGISTRIES_API void Registry::RegisterItem ( GroupItemBase registry,
const Placement placement,
BaseItemPtr  pItem 
)
Parameters
pItemRegistry takes ownership

Definition at line 776 of file Registry.cpp.

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

Referenced by Registry::RegisteredItem< Item, RegistryClass >::RegisteredItem(), and PopupMenuTable::RegisterItem().

Here is the caller graph for this function:

◆ Visit()

REGISTRIES_API void Registry::Visit ( Visitor visitor,
BaseItem pTopItem,
const GroupItemBase pRegistry 
)

Definition at line 739 of file Registry.cpp.

740{
741 std::vector< BaseItemSharedPtr > computedItems;
742 bool doFlush = false;
743 CollectedItems collection{ {}, computedItems };
744 Path emptyPath;
745 VisitItem(
746 visitor, collection, emptyPath, pTopItem,
747 pRegistry, pRegistry->orderingHint, doFlush );
748 // Flush any writes done by MergeItems()
749 if (doFlush)
750 gPrefs->Flush();
751}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
virtual bool Flush() noexcept=0
std::vector< Identifier > Path
Definition: Registry.cpp:178
void VisitItem(Registry::Visitor &visitor, CollectedItems &collection, Path &path, BaseItem *pItem, const GroupItemBase *pToMerge, const OrderingHint &hint, bool &doFlush)
Definition: Registry.cpp:688

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

Referenced by compileTest(), PrefsPanel::DefaultFactories(), PopupMenuTable::ExtendMenu(), SnapFunctionsRegistry::Find(), PluginManager::GetConfigValue(), ExportPluginRegistry::Initialize(), Importer::Initialize(), ToolDock::LayoutToolBars(), anonymous_namespace{EditMenus.cpp}::OnCut(), RealtimeEffectListWindow::PickEffect(), LibraryPrefs::PopulateOrExchange(), ToolDock::PositionBar(), PluginManager::SetConfigValue(), Tester< Const, ref >::testCase(), NumericConverterRegistry::Visit(), MenuManager::Visit(), and SnapFunctionsRegistry::Visit().

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