Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
FormatterContext Class Referencefinal

A context in which formatter operates. More...

#include <NumericConverterFormatterContext.h>

Collaboration diagram for FormatterContext:
[legend]

Public Member Functions

 FormatterContext ()=default
 
 FormatterContext (const FormatterContext &)=default
 
 FormatterContext (FormatterContext &&)=default
 
FormatterContextoperator= (const FormatterContext &)=default
 
FormatterContextoperator= (FormatterContext &&)=default
 
 ~FormatterContext ()
 
bool HasProject () const
 Returns true if the reference to the project is valid at this moment. More...
 
std::shared_ptr< const AudacityProjectGetProject () const
 Returns a potentially null pointer to the project. More...
 
bool HasSampleRate () const
 Returns true if it is possible to get a sample rate from this context. More...
 
double GetSampleRate (double defaultSampleRate=44100.0) const
 Returns a sample rate from this context. More...
 

Static Public Member Functions

static FormatterContext EmptyContext ()
 
static FormatterContext ProjectContext (const AudacityProject &project)
 
static FormatterContext SampleRateContext (double sampleRate)
 

Private Member Functions

 FormatterContext (const AudacityProject &project)
 
 FormatterContext (double sampleRate)
 

Private Attributes

std::weak_ptr< const AudacityProjectmProject
 
std::optional< double > mProjectRate
 

Detailed Description

A context in which formatter operates.

This class is used to pass additional information to the formatter, allowing AudacityProject to be an optional dependency

Definition at line 23 of file NumericConverterFormatterContext.h.

Constructor & Destructor Documentation

◆ FormatterContext() [1/5]

FormatterContext::FormatterContext ( const AudacityProject project)
explicitprivate

Definition at line 17 of file NumericConverterFormatterContext.cpp.

18 : mProject(project.weak_from_this())
19{
20}
const auto project
std::weak_ptr< const AudacityProject > mProject

◆ FormatterContext() [2/5]

FormatterContext::FormatterContext ( double  sampleRate)
explicitprivate

Definition at line 22 of file NumericConverterFormatterContext.cpp.

◆ FormatterContext() [3/5]

FormatterContext::FormatterContext ( )
default

◆ FormatterContext() [4/5]

FormatterContext::FormatterContext ( const FormatterContext )
default

◆ FormatterContext() [5/5]

FormatterContext::FormatterContext ( FormatterContext &&  )
default

◆ ~FormatterContext()

FormatterContext::~FormatterContext ( )

Definition at line 43 of file NumericConverterFormatterContext.cpp.

44{
45}

Member Function Documentation

◆ EmptyContext()

FormatterContext FormatterContext::EmptyContext ( )
static

Definition at line 27 of file NumericConverterFormatterContext.cpp.

28{
29 return {};
30}

Referenced by TagsEditorDialog::PopulateOrExchange(), TimerRecordDialog::PopulateOrExchange(), and ExtImportPrefs::PopulateOrExchange().

Here is the caller graph for this function:

◆ GetProject()

std::shared_ptr< const AudacityProject > FormatterContext::GetProject ( ) const

Returns a potentially null pointer to the project.

Definition at line 52 of file NumericConverterFormatterContext.cpp.

53{
54 return mProject.lock();
55}

References mProject.

Referenced by GetSampleRate().

Here is the caller graph for this function:

◆ GetSampleRate()

double FormatterContext::GetSampleRate ( double  defaultSampleRate = 44100.0) const

Returns a sample rate from this context.

Definition at line 62 of file NumericConverterFormatterContext.cpp.

63{
64 auto project = GetProject();
65
66 if (project)
67 return ProjectRate::Get(*project).GetRate();
68
69 if (mProjectRate.has_value())
70 return *mProjectRate;
71
72 return defaultSampleRate;
73}
std::shared_ptr< const AudacityProject > GetProject() const
Returns a potentially null pointer to the project.
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53

References ProjectRate::Get(), GetProject(), ProjectRate::GetRate(), mProjectRate, and project.

Here is the call graph for this function:

◆ HasProject()

bool FormatterContext::HasProject ( ) const

Returns true if the reference to the project is valid at this moment.

This operation is not thread-safe.The project isn't locked. Generally it is safe to assume that project outlives any of the formatters, so HasProject() can be used as a hint when building the UI.

Definition at line 47 of file NumericConverterFormatterContext.cpp.

48{
49 return !mProject.expired();
50}

References mProject.

Referenced by HasSampleRate(), and anonymous_namespace{BeatsNumericConverterFormatter.cpp}::BeatsNumericConverterFormatterFactory::IsAcceptableInContext().

Here is the caller graph for this function:

◆ HasSampleRate()

bool FormatterContext::HasSampleRate ( ) const

Returns true if it is possible to get a sample rate from this context.

Definition at line 57 of file NumericConverterFormatterContext.cpp.

58{
59 return HasProject() || mProjectRate.has_value();
60}
bool HasProject() const
Returns true if the reference to the project is valid at this moment.

References HasProject(), and mProjectRate.

Referenced by anonymous_namespace{ParsedNumericConverterFormatter.cpp}::ParsedNumericConverterFormatterFactory::IsAcceptableInContext().

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

◆ operator=() [1/2]

FormatterContext & FormatterContext::operator= ( const FormatterContext )
default

◆ operator=() [2/2]

FormatterContext & FormatterContext::operator= ( FormatterContext &&  )
default

◆ ProjectContext()

FormatterContext FormatterContext::ProjectContext ( const AudacityProject project)
static

Definition at line 33 of file NumericConverterFormatterContext.cpp.

34{
35 return FormatterContext { project };
36}
A context in which formatter operates.

References project.

Referenced by SelectionBar::AddTime(), ProjectNumericFormats::LookupFormat(), LabelDialog::OnFreqUpdate(), LabelDialog::OnUpdate(), SpectralSelectionBar::Populate(), TimeToolBar::Populate(), LabelDialog::PopulateOrExchange(), TimeDialog::PopulateOrExchange(), TEST_CASE(), and SelectionBar::UpdatePrefs().

Here is the caller graph for this function:

◆ SampleRateContext()

FormatterContext FormatterContext::SampleRateContext ( double  sampleRate)
static

Member Data Documentation

◆ mProject

std::weak_ptr<const AudacityProject> FormatterContext::mProject
private

Definition at line 56 of file NumericConverterFormatterContext.h.

Referenced by GetProject(), and HasProject().

◆ mProjectRate

std::optional<double> FormatterContext::mProjectRate
private

Definition at line 57 of file NumericConverterFormatterContext.h.

Referenced by GetSampleRate(), and HasSampleRate().


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