Audacity 3.2.0
Public Types | Public Member Functions | Friends | List of all members
Registry::GroupItemBase Struct Referenceabstract

Common abstract base class for items that group other items. More...

#include <Registry.h>

Inheritance diagram for Registry::GroupItemBase:
[legend]
Collaboration diagram for Registry::GroupItemBase:
[legend]

Public Types

enum  Ordering { Anonymous , Weak , Strong }
 Choose treatment of the children of the group when merging trees. More...
 
- Public Types inherited from Composite::Base< BaseItem, std::unique_ptr< BaseItem >, const Identifier & >
using value_type = std::unique_ptr< BaseItem >
 
using Items = std::vector< value_type >
 

Public Member Functions

 GroupItemBase (const GroupItemBase &)=delete
 
GroupItemBaseoperator= (const GroupItemBase &)=delete
 
 ~GroupItemBase () override=0
 
virtual Ordering GetOrdering () const
 Default implementation returns Strong. More...
 
- Public Member Functions inherited from Composite::Base< BaseItem, std::unique_ptr< BaseItem >, const Identifier & >
 Base (ComponentArgs... args)
 
 Base (const Base &)=delete
 
Baseoperator= (const Base &)=delete
 
auto begin () const
 
auto end () const
 
auto cbegin () const
 
auto cend () const
 
auto rbegin () const
 
auto rend () const
 
auto crbegin () const
 
auto crend () const
 
void push_back (value_type ptr)
 
bool empty () const
 

Friends

REGISTRIES_API void RegisterItem (GroupItemBase &registry, const Placement &placement, BaseItemPtr pItem)
 

Additional Inherited Members

- Protected Attributes inherited from Composite::Base< BaseItem, std::unique_ptr< BaseItem >, const Identifier & >
Items items
 

Detailed Description

Common abstract base class for items that group other items.

Definition at line 168 of file Registry.h.

Member Enumeration Documentation

◆ Ordering

Choose treatment of the children of the group when merging trees.

Enumerator
Anonymous 

Item's name is ignored (omitted from paths) and sub-items are merged individually, sequenced by preferences or ordering hints

Weak 

Item's name is significant in paths, but its sequence of children may be overridden if it merges with another group at the same path

Strong 

Item's name is significant and it is intended to be the unique strongly ordered group at its path (but this could fail and cause an alpha-build-only error message during merging)

Definition at line 178 of file Registry.h.

Constructor & Destructor Documentation

◆ GroupItemBase()

Registry::GroupItemBase::GroupItemBase ( const GroupItemBase )
delete

◆ ~GroupItemBase()

GroupItemBase::~GroupItemBase ( )
overridepure virtual

Definition at line 726 of file Registry.cpp.

726{}

Member Function Documentation

◆ GetOrdering()

auto GroupItemBase::GetOrdering ( ) const
virtual

Default implementation returns Strong.

Reimplemented in anonymous_namespace{Registry.cpp}::PlaceHolder.

Definition at line 727 of file Registry.cpp.

727{ return Strong; }

References Strong.

Referenced by anonymous_namespace{Registry.cpp}::CollectedItems::SubordinateMultipleItems().

Here is the caller graph for this function:

◆ operator=()

GroupItemBase & Registry::GroupItemBase::operator= ( const GroupItemBase )
delete

Friends And Related Function Documentation

◆ RegisterItem

REGISTRIES_API void RegisterItem ( GroupItemBase registry,
const Placement placement,
BaseItemPtr  pItem 
)
friend
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
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

The documentation for this struct was generated from the following files: