Audacity  3.0.3
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Static Private Attributes | List of all members
AllProjects Class Reference

#include <Project.h>

Collaboration diagram for AllProjects:
[legend]

Public Types

using const_iterator = Container::const_iterator
 
using const_reverse_iterator = Container::const_reverse_iterator
 
using value_type = Container::value_type
 

Public Member Functions

 AllProjects ()=default
 
size_t size () const
 
bool empty () const
 
const_iterator begin () const
 
const_iterator end () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
value_type Remove (AudacityProject &project)
 
void Add (const value_type &pProject)
 This invalidates iterators. More...
 

Static Public Member Functions

static std::mutex & Mutex ()
 

Private Types

using AProjectHolder = std::shared_ptr< AudacityProject >
 
using Container = std::vector< AProjectHolder >
 

Static Private Attributes

static Container gAudacityProjects
 

Detailed Description

Like a standard library container of all open projects.

Invariant
pointers accessible through the iterators are not null

So you can iterate easily over shared pointers to them with range-for : for (auto pProject : AllProjects{}) { ... } The pointers are never null.

However iterators will be invalid if addition or deletion of projects occur during traversal.

Definition at line 34 of file Project.h.

Member Typedef Documentation

◆ AProjectHolder

using AllProjects::AProjectHolder = std::shared_ptr< AudacityProject >
private

Definition at line 38 of file Project.h.

◆ const_iterator

using AllProjects::const_iterator = Container::const_iterator

Definition at line 48 of file Project.h.

◆ const_reverse_iterator

using AllProjects::const_reverse_iterator = Container::const_reverse_iterator

Definition at line 52 of file Project.h.

◆ Container

using AllProjects::Container = std::vector< AProjectHolder >
private

Definition at line 39 of file Project.h.

◆ value_type

using AllProjects::value_type = Container::value_type

Definition at line 56 of file Project.h.

Constructor & Destructor Documentation

◆ AllProjects()

AllProjects::AllProjects ( )
default

Member Function Documentation

◆ Add()

void AllProjects::Add ( const value_type pProject)

This invalidates iterators.

Precondition
pProject is not null

Definition at line 58 of file Project.cpp.

59 {
60  if (!pProject) {
61  wxASSERT(false);
62  return;
63  }
64  std::lock_guard<std::mutex> guard{ Mutex() };
65  gAudacityProjects.push_back( pProject );
66 }

References gAudacityProjects, and Mutex().

Referenced by ProjectManager::New().

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

◆ begin()

auto AllProjects::begin ( ) const

Definition at line 24 of file Project.cpp.

25 {
26  return gAudacityProjects.begin();
27 }

References gAudacityProjects.

Referenced by CloseAllProjects(), anonymous_namespace{TransportMenus.cpp}::DoStopPlaying(), ProjectFileManager::IsAlreadyOpen(), ProjectManager::OnCloseWindow(), ProjectWindow::OnIconize(), ProjectManager::SaveWindowSize(), and TitleRestorer::TitleRestorer().

Here is the caller graph for this function:

◆ empty()

bool AllProjects::empty ( ) const
inline

Definition at line 46 of file Project.h.

46 { return size() == 0; }

References size.

Referenced by GetNextWindowPlacement(), ProjectManager::OnCloseWindow(), AudacityApp::OnMenuExit(), AudacityApp::OnMenuNew(), AudacityApp::OnMenuOpen(), AudacityApp::OnMenuPreferences(), and QuitAudacity().

Here is the caller graph for this function:

◆ end()

auto AllProjects::end ( ) const

Definition at line 29 of file Project.cpp.

30 {
31  return gAudacityProjects.end();
32 }

References gAudacityProjects.

Referenced by anonymous_namespace{TransportMenus.cpp}::DoStopPlaying(), ProjectFileManager::IsAlreadyOpen(), ProjectWindow::OnIconize(), and TitleRestorer::TitleRestorer().

Here is the caller graph for this function:

◆ Mutex()

std::mutex & AllProjects::Mutex ( )
static

In case you must iterate in a non-main thread, use this to prevent changes in the set of open projects

Definition at line 68 of file Project.cpp.

69 {
70  static std::mutex theMutex;
71  return theMutex;
72 }

Referenced by Add().

Here is the caller graph for this function:

◆ rbegin()

auto AllProjects::rbegin ( ) const

Definition at line 34 of file Project.cpp.

35 {
36  return gAudacityProjects.rbegin();
37 }

References gAudacityProjects.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ Remove()

auto AllProjects::Remove ( AudacityProject project)

Definition at line 44 of file Project.cpp.

45 {
46  std::lock_guard<std::mutex> guard{ Mutex() };
47  auto start = begin(), finish = end(), iter = std::find_if(
48  start, finish,
49  [&]( const value_type &ptr ){ return ptr.get() == &project; }
50  );
51  if (iter == finish)
52  return nullptr;
53  auto result = *iter;
54  gAudacityProjects.erase( iter );
55  return result;
56 }

Referenced by ProjectManager::OnCloseWindow().

Here is the caller graph for this function:

◆ rend()

auto AllProjects::rend ( ) const

Definition at line 39 of file Project.cpp.

40 {
41  return gAudacityProjects.rend();
42 }

References gAudacityProjects.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ size()

size_t AllProjects::size ( ) const

Definition at line 19 of file Project.cpp.

20 {
21  return gAudacityProjects.size();
22 }

References gAudacityProjects.

Referenced by CloseAllProjects(), ProjectManager::OnCloseWindow(), AudacityApp::OnEndSession(), TransportActions::Handler::OnTimerRecord(), NyquistEffect::Process(), and QuitAudacity().

Here is the caller graph for this function:

Member Data Documentation

◆ gAudacityProjects

AllProjects::Container AllProjects::gAudacityProjects
staticprivate

Definition at line 40 of file Project.h.

Referenced by Add(), begin(), end(), rbegin(), rend(), and size().


The documentation for this class was generated from the following files:
AllProjects::begin
const_iterator begin() const
Definition: Project.cpp:24
AllProjects::end
const_iterator end() const
Definition: Project.cpp:29
AllProjects::size
size_t size() const
Definition: Project.cpp:19
AllProjects::gAudacityProjects
static Container gAudacityProjects
Definition: Project.h:40
AllProjects::Mutex
static std::mutex & Mutex()
Definition: Project.cpp:68
AllProjects::value_type
Container::value_type value_type
Definition: Project.h:56