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

an object of class AllProjects acts like a standard library container, but refers to a global array of open projects. So you can iterate easily over shared pointers to them with range-for : for (auto pProject : AllProjects{}) { ... } The pointers are never null. More...

#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)
 

Static Public Member Functions

static std::mutex & Mutex ()
 
static bool Close (bool force=false)
 
static bool Closing ()
 

Private Types

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

Static Private Attributes

static Container gAudacityProjects
 
static bool sbClosing = false
 

Detailed Description

an object of class AllProjects acts like a standard library container, but refers to a global array of open projects. So you can iterate easily over shared pointers to them with range-for : for (auto pProject : AllProjects{}) { ... } The pointers are never null.

Definition at line 37 of file Project.h.

Member Typedef Documentation

◆ AProjectHolder

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

Definition at line 40 of file Project.h.

◆ const_iterator

using AllProjects::const_iterator = Container::const_iterator

Definition at line 50 of file Project.h.

◆ const_reverse_iterator

using AllProjects::const_reverse_iterator = Container::const_reverse_iterator

Definition at line 54 of file Project.h.

◆ Container

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

Definition at line 41 of file Project.h.

◆ value_type

using AllProjects::value_type = Container::value_type

Definition at line 58 of file Project.h.

Constructor & Destructor Documentation

◆ AllProjects()

AllProjects::AllProjects ( )
default

Member Function Documentation

◆ Add()

void AllProjects::Add ( const value_type pProject)

Definition at line 65 of file Project.cpp.

66 {
67  std::lock_guard<std::mutex> guard{ Mutex() };
68  gAudacityProjects.push_back( pProject );
69 }

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

32 {
33  return gAudacityProjects.begin();
34 }

References gAudacityProjects.

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

Here is the caller graph for this function:

◆ Close()

bool AllProjects::Close ( bool  force = false)
static

Definition at line 73 of file Project.cpp.

74 {
75  ValueRestorer<bool> cleanup{ sbClosing, true };
76  while (AllProjects{}.size())
77  {
78  // Closing the project has global side-effect
79  // of deletion from gAudacityProjects
80  if ( force )
81  {
82  GetProjectFrame( **AllProjects{}.begin() ).Close(true);
83  }
84  else
85  {
86  if (! GetProjectFrame( **AllProjects{}.begin() ).Close())
87  return false;
88  }
89  }
90  return true;
91 }

References begin(), GetProjectFrame(), sbClosing, and size().

Referenced by AudacityApp::OnEndSession(), and QuitAudacity().

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

◆ Closing()

static bool AllProjects::Closing ( )
inlinestatic

Definition at line 76 of file Project.h.

76 { return sbClosing; }

Referenced by ProjectManager::OnCloseWindow().

Here is the caller graph for this function:

◆ empty()

bool AllProjects::empty ( ) const
inline

Definition at line 48 of file Project.h.

48 { return size() == 0; }

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

37 {
38  return gAudacityProjects.end();
39 }

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

94 {
95  static std::mutex theMutex;
96  return theMutex;
97 }

Referenced by Add(), and ODTask::DoSome().

Here is the caller graph for this function:

◆ rbegin()

auto AllProjects::rbegin ( ) const

Definition at line 41 of file Project.cpp.

42 {
43  return gAudacityProjects.rbegin();
44 }

References gAudacityProjects.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ Remove()

auto AllProjects::Remove ( AudacityProject project)

Definition at line 51 of file Project.cpp.

52 {
53  std::lock_guard<std::mutex> guard{ Mutex() };
54  auto start = begin(), finish = end(), iter = std::find_if(
55  start, finish,
56  [&]( const value_type &ptr ){ return ptr.get() == &project; }
57  );
58  if (iter == finish)
59  return nullptr;
60  auto result = *iter;
61  gAudacityProjects.erase( iter );
62  return result;
63 }

Referenced by ProjectManager::OnCloseWindow().

Here is the caller graph for this function:

◆ rend()

auto AllProjects::rend ( ) const

Definition at line 46 of file Project.cpp.

47 {
48  return gAudacityProjects.rend();
49 }

References gAudacityProjects.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ size()

size_t AllProjects::size ( ) const

Definition at line 26 of file Project.cpp.

27 {
28  return gAudacityProjects.size();
29 }

References gAudacityProjects.

Referenced by Close(), 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 42 of file Project.h.

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

◆ sbClosing

bool AllProjects::sbClosing = false
staticprivate

Definition at line 79 of file Project.h.

Referenced by Close().


The documentation for this class was generated from the following files:
AllProjects::begin
const_iterator begin() const
Definition: Project.cpp:31
AllProjects::Close
static bool Close(bool force=false)
Definition: Project.cpp:73
AllProjects::end
const_iterator end() const
Definition: Project.cpp:36
AllProjects::size
size_t size() const
Definition: Project.cpp:26
GetProjectFrame
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
Definition: Project.cpp:186
AllProjects::gAudacityProjects
static Container gAudacityProjects
Definition: Project.h:42
AllProjects::sbClosing
static bool sbClosing
Definition: Project.h:79
AllProjects
an object of class AllProjects acts like a standard library container, but refers to a global array o...
Definition: Project.h:38
ValueRestorer
Set a variable temporarily in a scope.
Definition: MemoryX.h:331
AllProjects::Mutex
static std::mutex & Mutex()
Definition: Project.cpp:93
AllProjects::value_type
Container::value_type value_type
Definition: Project.h:58