Audacity 3.2.0
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 35 of file Project.h.

Member Typedef Documentation

◆ AProjectHolder

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

Definition at line 39 of file Project.h.

◆ const_iterator

using AllProjects::const_iterator = Container::const_iterator

Definition at line 49 of file Project.h.

◆ const_reverse_iterator

using AllProjects::const_reverse_iterator = Container::const_reverse_iterator

Definition at line 53 of file Project.h.

◆ Container

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

Definition at line 40 of file Project.h.

◆ value_type

using AllProjects::value_type = Container::value_type

Definition at line 57 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 56 of file Project.cpp.

57{
58 if (!pProject) {
59 wxASSERT(false);
60 return;
61 }
62 std::lock_guard<std::mutex> guard{ Mutex() };
63 gAudacityProjects.push_back( pProject );
64}
static std::mutex & Mutex()
Definition: Project.cpp:66
static Container gAudacityProjects
Definition: Project.h:41

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 22 of file Project.cpp.

23{
24 return gAudacityProjects.begin();
25}

References gAudacityProjects.

Referenced by CloseAllProjects(), TransportUtilities::DoStopPlaying(), audacity::cloud::audiocom::sync::GetOpenedProject(), 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 47 of file Project.h.

47{ return size() == 0; }
size_t size() const
Definition: Project.cpp:17

References size.

Referenced by GetNextWindowPlacement(), audacity::cloud::audiocom::sync::GetPotentialTarget(), AudacityApp::MacNewFile(), 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 27 of file Project.cpp.

28{
29 return gAudacityProjects.end();
30}

References gAudacityProjects.

Referenced by TransportUtilities::DoStopPlaying(), audacity::cloud::audiocom::sync::GetOpenedProject(), 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 66 of file Project.cpp.

67{
68 static std::mutex theMutex;
69 return theMutex;
70}

Referenced by Add().

Here is the caller graph for this function:

◆ rbegin()

auto AllProjects::rbegin ( ) const

Definition at line 32 of file Project.cpp.

33{
34 return gAudacityProjects.rbegin();
35}

References gAudacityProjects.

Referenced by GetNextWindowPlacement(), and audacity::cloud::audiocom::sync::GetPotentialTarget().

Here is the caller graph for this function:

◆ Remove()

auto AllProjects::Remove ( AudacityProject project)

Definition at line 42 of file Project.cpp.

43{
44 std::lock_guard<std::mutex> guard{ Mutex() };
45 auto start = begin(), finish = end(), iter = std::find_if(
46 start, finish,
47 [&]( const value_type &ptr ){ return ptr.get() == &project; }
48 );
49 if (iter == finish)
50 return nullptr;
51 auto result = *iter;
52 gAudacityProjects.erase( iter );
53 return result;
54}
const auto project
const_iterator end() const
Definition: Project.cpp:27
Container::value_type value_type
Definition: Project.h:57
const_iterator begin() const
Definition: Project.cpp:22

References details::begin(), details::end(), and project.

Referenced by ProjectManager::OnCloseWindow().

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

◆ rend()

auto AllProjects::rend ( ) const

Definition at line 37 of file Project.cpp.

38{
39 return gAudacityProjects.rend();
40}

References gAudacityProjects.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ size()

size_t AllProjects::size ( ) const

Definition at line 17 of file Project.cpp.

18{
19 return gAudacityProjects.size();
20}

References gAudacityProjects.

Referenced by CloseAllProjects(), ProjectManager::OnCloseWindow(), AudacityApp::OnEndSession(), anonymous_namespace{TimerRecordDialog.cpp}::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 41 of file Project.h.

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


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