Audacity  3.0.3
Classes | Typedefs | Functions
Registry Namespace Reference

Classes

struct  BaseItem
 
struct  ComputedItem
 
struct  ConcreteGroupItem
 
struct  GroupItem
 
struct  InlineGroupItem
 
struct  OrderingHint
 
struct  OrderingPreferenceInitializer
 
struct  Placement
 
struct  SharedItem
 
struct  SingleItem
 
struct  TransparentGroupItem
 
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 GroupItem *pRegistry)
 
void RegisterItem (GroupItem &registry, const Placement &placement, BaseItemPtr pItem)
 
std::unique_ptr< SharedItemShared (const BaseItemSharedPtr &ptr)
 

Typedef Documentation

◆ BaseItemPtr

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

Definition at line 71 of file Registry.h.

◆ BaseItemPtrs

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

Definition at line 73 of file Registry.h.

◆ BaseItemSharedPtr

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

Definition at line 72 of file Registry.h.

Function Documentation

◆ RegisterItem()

REGISTRIES_API void Registry::RegisterItem ( GroupItem registry,
const Placement placement,
BaseItemPtr  pItem 
)

Definition at line 750 of file Registry.cpp.

752 {
753  // Since registration determines only an unordered tree of menu items,
754  // we can sort children of each node lexicographically for our convenience.
755  BaseItemPtrs *pItems;
756  struct Comparator {
757  bool operator()
758  ( const Identifier &component, const BaseItemPtr& pItem ) const {
759  return component < pItem->name; }
760  bool operator()
761  ( const BaseItemPtr& pItem, const Identifier &component ) const {
762  return pItem->name < component; }
763  };
764  auto find = [&pItems]( const Identifier &component ){ return std::equal_range(
765  pItems->begin(), pItems->end(), component, Comparator() ); };
766 
767  auto pNode = &registry;
768  pItems = &pNode->items;
769 
770  const auto pathComponents = ::wxSplit( placement.path, '/' );
771  auto pComponent = pathComponents.begin(), end = pathComponents.end();
772 
773  // Descend the registry hierarchy, while groups matching the path components
774  // can be found
775  auto debugPath = wxString{'/'} + registry.name.GET();
776  while ( pComponent != end ) {
777  const auto &pathComponent = *pComponent;
778 
779  // Try to find an item already present that is a group item with the
780  // same name; we don't care which if there is more than one.
781  const auto range = find( pathComponent );
782  const auto iter2 = std::find_if( range.first, range.second,
783  [](const BaseItemPtr &pItem){
784  return dynamic_cast< GroupItem* >( pItem.get() ); } );
785 
786  if ( iter2 != range.second ) {
787  // A matching group in the registry, so descend
788  pNode = static_cast< GroupItem* >( iter2->get() );
789  pItems = &pNode->items;
790  debugPath += '/' + pathComponent;
791  ++pComponent;
792  }
793  else
794  // Insert at this level;
795  // If there are no more path components, and a name collision of
796  // the added item with something already in the registry, don't resolve
797  // it yet in this function, but see MergeItems().
798  break;
799  }
800 
801  // Create path group items for remaining components
802  while ( pComponent != end ) {
803  auto newNode = std::make_unique<TransparentGroupItem<>>( *pComponent );
804  pNode = newNode.get();
805  pItems->insert( find( pNode->name ).second, std::move( newNode ) );
806  pItems = &pNode->items;
807  ++pComponent;
808  }
809 
810  // Remember the hint, to be used later in merging.
811  pItem->orderingHint = placement.hint;
812 
813  // Now insert the item.
814  pItems->insert( find( pItem->name ).second, std::move( pItem ) );
815 }

References Identifier::GET(), Registry::Placement::hint, Registry::GroupItem::items, Registry::BaseItem::name, and Registry::Placement::path.

Referenced by MenuTable::AttachedItem::AttachedItem(), Exporter::RegisteredExportPlugin::RegisteredExportPlugin(), Importer::RegisteredImportPlugin::RegisteredImportPlugin(), PopupMenuTable::RegisterItem(), and PrefsPanel::Registration::Registration().

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

◆ Shared()

std::unique_ptr<SharedItem> Registry::Shared ( const BaseItemSharedPtr ptr)
inline

Definition at line 93 of file Registry.h.

94  { return std::make_unique<SharedItem>( ptr ); }

◆ Visit()

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

Definition at line 713 of file Registry.cpp.

714 {
715  std::vector< BaseItemSharedPtr > computedItems;
716  bool doFlush = false;
717  CollectedItems collection{ {}, computedItems };
718  Path emptyPath;
719  VisitItem(
720  visitor, collection, emptyPath, pTopItem,
721  pRegistry, pRegistry->orderingHint, doFlush );
722  // Flush any writes done by MergeItems()
723  if (doFlush)
724  gPrefs->Flush();
725 }

References FileConfig::Flush(), gPrefs, Registry::BaseItem::orderingHint, and anonymous_namespace{Registry.cpp}::VisitItem().

Referenced by PrefsPanel::DefaultFactories(), EffectTruncSilence::DoRemoval(), PopupMenuTable::ExtendMenu(), Importer::Initialize(), ToolDock::LayoutToolBars(), EditActions::Handler::OnCut(), ToolDock::PositionBar(), and MenuManager::Visit().

Here is the call graph for this function:
Here is the caller graph for this function:
Registry::Placement::path
wxString path
Definition: Registry.h:220
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
Registry::BaseItem::orderingHint
OrderingHint orderingHint
Definition: Registry.h:69
Identifier
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Registry::BaseItem::name
const Identifier name
Definition: Registry.h:67
Registry::BaseItemPtr
std::unique_ptr< BaseItem > BaseItemPtr
Definition: Registry.h:71
Registry::Placement::hint
OrderingHint hint
Definition: Registry.h:221
anonymous_namespace{Registry.cpp}::VisitItem
void VisitItem(Registry::Visitor &visitor, CollectedItems &collection, Path &path, BaseItem *pItem, const GroupItem *pToMerge, const OrderingHint &hint, bool &doFlush)
Definition: Registry.cpp:667
Identifier::GET
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
anonymous_namespace{Registry.cpp}::Path
std::vector< Identifier > Path
Definition: Registry.cpp:163
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
Registry::BaseItemPtrs
std::vector< BaseItemPtr > BaseItemPtrs
Definition: Registry.h:73
Registry::GroupItem
Definition: Registry.h:126
Registry::GroupItem::items
BaseItemPtrs items
Definition: Registry.h:141