Audacity  3.0.3
Classes | Typedefs | Functions | Variables
anonymous_namespace{Registry.cpp} Namespace Reference

Classes

struct  CollectedItems
 
struct  ItemOrdering
 

Typedefs

using Path = std::vector< Identifier >
 

Functions

const OrderingHintChooseHint (BaseItem *delegate, const OrderingHint &hint)
 
void CollectItem (Registry::Visitor &visitor, CollectedItems &collection, BaseItem *Item, const OrderingHint &hint)
 
void CollectItems (Registry::Visitor &visitor, CollectedItems &collection, const BaseItemPtrs &items, const OrderingHint &hint)
 
void BadPath (const TranslatableString &format, const wxString &key, const Identifier &name)
 
void ReportGroupGroupCollision (const wxString &key, const Identifier &name)
 
void ReportItemItemCollision (const wxString &key, const Identifier &name)
 
void ReportConflictingPlacements (const wxString &key, const Identifier &name)
 
bool MajorComp (const CollectedItems::NewItem &a, const CollectedItems::NewItem &b)
 
bool MinorComp (const CollectedItems::NewItem &a, const CollectedItems::NewItem &b)
 
bool Comp (const CollectedItems::NewItem &a, const CollectedItems::NewItem &b)
 
void VisitItem (Registry::Visitor &visitor, CollectedItems &collection, Path &path, BaseItem *pItem, const GroupItem *pToMerge, const OrderingHint &hint, bool &doFlush)
 
void VisitItems (Registry::Visitor &visitor, CollectedItems &collection, Path &path, GroupItem *pGroup, const GroupItem *pToMerge, const OrderingHint &hint, bool &doFlush)
 

Variables

std::unordered_set< wxString > sBadPaths
 

Typedef Documentation

◆ Path

using anonymous_namespace{Registry.cpp}::Path = typedef std::vector< Identifier >

Definition at line 163 of file Registry.cpp.

Function Documentation

◆ BadPath()

void anonymous_namespace{Registry.cpp}::BadPath ( const TranslatableString format,
const wxString &  key,
const Identifier name 
)

Definition at line 166 of file Registry.cpp.

168  {
169  // Warn, but not more than once in a session for each bad path
170  auto badPath = key + '/' + name.GET();
171  if ( sBadPaths.insert( badPath ).second ) {
172  auto msg = TranslatableString{ format }.Format( badPath );
173  // debug message
174  wxLogDebug( msg.Translation() );
175 #ifdef IS_ALPHA
176  // user-visible message
178 #endif
179  }
180  }

References format, key, name, sBadPaths, and BasicUI::ShowMessageBox().

Referenced by TempDirectory::IsTempDirectoryNameOK(), ReportConflictingPlacements(), ReportGroupGroupCollision(), and ReportItemItemCollision().

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

◆ ChooseHint()

const OrderingHint& anonymous_namespace{Registry.cpp}::ChooseHint ( BaseItem delegate,
const OrderingHint hint 
)

Definition at line 92 of file Registry.cpp.

93 {
94  return !delegate || delegate->orderingHint.type == OrderingHint::Unspecified
95  ? hint
96  : delegate->orderingHint;
97 }

References Registry::BaseItem::orderingHint, and Registry::OrderingHint::Unspecified.

Referenced by CollectItem(), and CollectItems().

Here is the caller graph for this function:

◆ CollectItem()

void anonymous_namespace{Registry.cpp}::CollectItem ( Registry::Visitor visitor,
CollectedItems collection,
BaseItem Item,
const OrderingHint hint 
)

Definition at line 116 of file Registry.cpp.

118 {
119  if (!pItem)
120  return;
121 
122  using namespace Registry;
123  if (const auto pShared =
124  dynamic_cast<SharedItem*>( pItem )) {
125  auto delegate = pShared->ptr.get();
126  if ( delegate )
127  // recursion
128  CollectItem( visitor, collection, delegate,
129  ChooseHint( delegate, pShared->orderingHint ) );
130  }
131  else
132  if (const auto pComputed =
133  dynamic_cast<ComputedItem*>( pItem )) {
134  auto result = pComputed->factory( visitor );
135  if (result) {
136  // Guarantee long enough lifetime of the result
137  collection.computedItems.push_back( result );
138  // recursion
139  CollectItem( visitor, collection, result.get(),
140  ChooseHint( result.get(), pComputed->orderingHint ) );
141  }
142  }
143  else
144  if (auto pGroup = dynamic_cast<GroupItem*>(pItem)) {
145  if (pGroup->Transparent() && pItem->name.empty())
146  // nameless grouping item is transparent to path calculations
147  // collect group members now
148  // recursion
149  CollectItems(
150  visitor, collection, pGroup->items, ChooseHint( pGroup, hint ) );
151  else
152  // all other group items
153  // defer collection of members until collecting at next lower level
154  collection.items.push_back( {pItem, nullptr, hint} );
155  }
156  else {
157  wxASSERT( dynamic_cast<SingleItem*>(pItem) );
158  // common to all single items
159  collection.items.push_back( {pItem, nullptr, hint} );
160  }
161 }

References ChooseHint(), CollectItems(), anonymous_namespace{Registry.cpp}::CollectedItems::computedItems, Identifier::empty(), anonymous_namespace{Registry.cpp}::CollectedItems::items, and Registry::BaseItem::name.

Referenced by CollectItems().

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

◆ CollectItems()

void anonymous_namespace{Registry.cpp}::CollectItems ( Registry::Visitor visitor,
CollectedItems collection,
const BaseItemPtrs items,
const OrderingHint hint 
)

Definition at line 108 of file Registry.cpp.

111 {
112  for ( auto &item : items )
113  CollectItem( visitor, collection, item.get(),
114  ChooseHint( item.get(), hint ) );
115 }

References ChooseHint(), and CollectItem().

Referenced by CollectItem(), anonymous_namespace{Registry.cpp}::CollectedItems::MergeItems(), and VisitItems().

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

◆ Comp()

bool anonymous_namespace{Registry.cpp}::Comp ( const CollectedItems::NewItem a,
const CollectedItems::NewItem b 
)
inline

Definition at line 484 of file Registry.cpp.

485  {
486  if ( MajorComp( a, b ) )
487  return true;
488  if ( MajorComp( b, a ) )
489  return false;
490  return MinorComp( a, b );
491 };

References MajorComp(), and MinorComp().

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

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

◆ MajorComp()

bool anonymous_namespace{Registry.cpp}::MajorComp ( const CollectedItems::NewItem a,
const CollectedItems::NewItem b 
)
inline

Definition at line 473 of file Registry.cpp.

474  {
475  // Descending sort!
476  return a.first->name > b.first->name;
477 };

Referenced by Comp(), anonymous_namespace{Registry.cpp}::CollectedItems::MergeItemsAscendingNamesPass(), and anonymous_namespace{Registry.cpp}::CollectedItems::MergeItemsDescendingNamesPass().

Here is the caller graph for this function:

◆ MinorComp()

bool anonymous_namespace{Registry.cpp}::MinorComp ( const CollectedItems::NewItem a,
const CollectedItems::NewItem b 
)
inline

Definition at line 478 of file Registry.cpp.

479  {
480  // Sort by hint type.
481  // This sorts items with unspecified hints last.
482  return a.second < b.second;
483 };

Referenced by Comp().

Here is the caller graph for this function:

◆ ReportConflictingPlacements()

void anonymous_namespace{Registry.cpp}::ReportConflictingPlacements ( const wxString &  key,
const Identifier name 
)

Definition at line 196 of file Registry.cpp.

197  {
198  BadPath(
199 XO("Plug-in items at %s specify conflicting placements"),
200  key, name);
201  }

References BadPath(), key, name, and XO.

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

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

◆ ReportGroupGroupCollision()

void anonymous_namespace{Registry.cpp}::ReportGroupGroupCollision ( const wxString &  key,
const Identifier name 
)

Definition at line 182 of file Registry.cpp.

183  {
184  BadPath(
185 XO("Plug-in group at %s was merged with a previously defined group"),
186  key, name);
187  }

References BadPath(), key, name, and XO.

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

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

◆ ReportItemItemCollision()

void anonymous_namespace{Registry.cpp}::ReportItemItemCollision ( const wxString &  key,
const Identifier name 
)

Definition at line 189 of file Registry.cpp.

190  {
191  BadPath(
192 XO("Plug-in item at %s conflicts with a previously defined item and was discarded"),
193  key, name);
194  }

References BadPath(), key, name, and XO.

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

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

◆ VisitItem()

void anonymous_namespace{Registry.cpp}::VisitItem ( Registry::Visitor visitor,
CollectedItems collection,
Path path,
BaseItem pItem,
const GroupItem pToMerge,
const OrderingHint hint,
bool &  doFlush 
)

Definition at line 667 of file Registry.cpp.

672 {
673  if (!pItem)
674  return;
675 
676  if (const auto pSingle =
677  dynamic_cast<SingleItem*>( pItem )) {
678  wxASSERT( !pToMerge );
679  visitor.Visit( *pSingle, path );
680  }
681  else
682  if (const auto pGroup =
683  dynamic_cast<GroupItem*>( pItem )) {
684  visitor.BeginGroup( *pGroup, path );
685  // recursion
686  VisitItems(
687  visitor, collection, path, pGroup, pToMerge, hint, doFlush );
688  visitor.EndGroup( *pGroup, path );
689  }
690  else
691  wxASSERT( false );
692 }

References Registry::Visitor::BeginGroup(), Registry::Visitor::EndGroup(), Registry::Visitor::Visit(), and VisitItems().

Referenced by Registry::Visit(), and VisitItems().

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

◆ VisitItems()

void anonymous_namespace{Registry.cpp}::VisitItems ( Registry::Visitor visitor,
CollectedItems collection,
Path path,
GroupItem pGroup,
const GroupItem pToMerge,
const OrderingHint hint,
bool &  doFlush 
)

Definition at line 620 of file Registry.cpp.

625 {
626  // Make a NEW collection for this subtree, sharing the memo cache
627  CollectedItems newCollection{ {}, collection.computedItems };
628 
629  // Gather items at this level
630  // (The ordering hint is irrelevant when not merging items in)
631  CollectItems( visitor, newCollection, pGroup->items, {} );
632 
633  path.push_back( pGroup->name.GET() );
634 
635  // Merge with the registry
636  if ( pToMerge )
637  {
638  ItemOrdering itemOrdering{ path };
639  newCollection.MergeItems( visitor, itemOrdering, pToMerge->items, hint );
640 
641  // Remember the NEW ordering, if there was any need to use the old.
642  // This makes a side effect in preferences.
643  if ( itemOrdering.gotOrdering ) {
644  wxString newValue;
645  for ( const auto &item : newCollection.items ) {
646  const auto &name = item.visitNow->name;
647  if ( !name.empty() )
648  newValue += newValue.empty()
649  ? name.GET()
650  : ',' + name.GET();
651  }
652  if (newValue != itemOrdering.strValue) {
653  gPrefs->Write( itemOrdering.key, newValue );
654  doFlush = true;
655  }
656  }
657  }
658 
659  // Now visit them
660  for ( const auto &item : newCollection.items )
661  VisitItem( visitor, collection, path,
662  item.visitNow, item.mergeLater, item.hint,
663  doFlush );
664 
665  path.pop_back();
666 }

References CollectItems(), anonymous_namespace{Registry.cpp}::CollectedItems::computedItems, TranslatableString::empty(), Identifier::GET(), gPrefs, Registry::GroupItem::items, Registry::BaseItem::name, name, and VisitItem().

Referenced by VisitItem().

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

Variable Documentation

◆ sBadPaths

std::unordered_set< wxString > anonymous_namespace{Registry.cpp}::sBadPaths

Definition at line 165 of file Registry.cpp.

Referenced by BadPath().

TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
Registry::Visitor::EndGroup
virtual void EndGroup(GroupItem &item, const Path &path)
Definition: Registry.cpp:710
anonymous_namespace{Registry.cpp}::MajorComp
bool MajorComp(const CollectedItems::NewItem &a, const CollectedItems::NewItem &b)
Definition: Registry.cpp:473
Registry::SingleItem
Definition: Registry.h:120
TranslatableString::empty
bool empty() const
Definition: TranslatableString.h:72
Registry
Definition: Menus.h:35
anonymous_namespace{Registry.cpp}::CollectItems
void CollectItems(Registry::Visitor &visitor, CollectedItems &collection, const BaseItemPtrs &items, const OrderingHint &hint)
Definition: Registry.cpp:108
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
BasicUI::ShowMessageBox
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:248
Registry::Visitor::BeginGroup
virtual void BeginGroup(GroupItem &item, const Path &path)
Definition: Registry.cpp:709
XO
#define XO(s)
Definition: Internat.h:31
anonymous_namespace{Registry.cpp}::ChooseHint
const OrderingHint & ChooseHint(BaseItem *delegate, const OrderingHint &hint)
Definition: Registry.cpp:92
Registry::BaseItem::orderingHint
OrderingHint orderingHint
Definition: Registry.h:69
Registry::Visitor::Visit
virtual void Visit(SingleItem &item, const Path &path)
Definition: Registry.cpp:711
Registry::BaseItem::name
const Identifier name
Definition: Registry.h:67
anonymous_namespace{Registry.cpp}::sBadPaths
std::unordered_set< wxString > sBadPaths
Definition: Registry.cpp:165
name
const TranslatableString name
Definition: Distortion.cpp:98
format
int format
Definition: ExportPCM.cpp:56
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}::VisitItems
void VisitItems(Registry::Visitor &visitor, CollectedItems &collection, Path &path, GroupItem *pGroup, const GroupItem *pToMerge, const OrderingHint &hint, bool &doFlush)
Definition: Registry.cpp:620
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
Registry::GroupItem
Definition: Registry.h:126
Registry::ComputedItem
Definition: Registry.h:100
anonymous_namespace{Registry.cpp}::CollectItem
void CollectItem(Registry::Visitor &visitor, CollectedItems &collection, BaseItem *Item, const OrderingHint &hint)
Definition: Registry.cpp:116
Registry::GroupItem::items
BaseItemPtrs items
Definition: Registry.h:141
anonymous_namespace{Registry.cpp}::MinorComp
bool MinorComp(const CollectedItems::NewItem &a, const CollectedItems::NewItem &b)
Definition: Registry.cpp:478
anonymous_namespace{Registry.cpp}::BadPath
void BadPath(const TranslatableString &format, const wxString &key, const Identifier &name)
Definition: Registry.cpp:166
Registry::SharedItem
Definition: Registry.h:82