Skip to content

Commit

Permalink
Tidy: Use the auto type specifier instead of duplicating types. (libs)
Browse files Browse the repository at this point in the history
The clang-tidy "use auto" modernization checker pointed out a ton of
places where a type specifier was duplicated, e.g. "Foo *var = new
Foo();", where the code can be simplified by using the new "auto"
keyword.  The previous example will be updated to read "auto *var =
new Foo();".  This example looks trivial, but when "Foo" is a 25
character QMap or something even longer, it makes the code easier to
read.  All replacements made by clang-tidy with some manual
reformatting.

There are a couple of manual replacements of begin()/end() with
cbegin()/cend() to ensure that iterators are still const when using
the "auto" keyword.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-auto.html
  • Loading branch information
linuxdude42 committed Dec 2, 2019
1 parent 0c79cdb commit acf2aeb
Show file tree
Hide file tree
Showing 161 changed files with 627 additions and 743 deletions.
6 changes: 3 additions & 3 deletions mythtv/libs/libmyth/audio/audioconvert.cpp
Expand Up @@ -682,7 +682,7 @@ int AudioConvert::Process(void* out, const void* in, int bytes, bool noclip)

// cppcheck-suppress unassignedVariable
uint8_t buffer[65536+15];
uint8_t* tmp = (uint8_t*)(((long)buffer + 15) & ~0xf);
auto* tmp = (uint8_t*)(((long)buffer + 15) & ~0xf);
int left = bytes;

while (left > 0)
Expand Down Expand Up @@ -720,8 +720,8 @@ int AudioConvert::Process(void* out, const void* in, int bytes, bool noclip)
*/
void AudioConvert::MonoToStereo(void* dst, const void* src, int samples)
{
float* d = (float*)dst;
float* s = (float*)src;
auto* d = (float*)dst;
auto* s = (float*)src;
for (int i = 0; i < samples; i++)
{
*d++ = *s;
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/audio/audiooutput.cpp
Expand Up @@ -419,7 +419,7 @@ static void fillSelectionsFromDir(const QDir &dir,

AudioOutput::ADCVect* AudioOutput::GetOutputList(void)
{
ADCVect *list = new ADCVect;
auto *list = new ADCVect;

#ifdef USING_PULSE
bool pasuspended = PulseHandler::Suspend(PulseHandler::kPulseSuspend);
Expand Down Expand Up @@ -650,7 +650,7 @@ int AudioOutput::DecodeAudio(AVCodecContext *ctx,
return ret;
}

AVSampleFormat format = (AVSampleFormat)m_frame->format;
auto format = (AVSampleFormat)m_frame->format;
AudioFormat fmt =
AudioOutputSettings::AVSampleFormatToFormat(format, ctx->bits_per_raw_sample);

Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmyth/audio/audiooutputalsa.cpp
Expand Up @@ -323,7 +323,7 @@ AudioOutputSettings* AudioOutputALSA::GetOutputSettings(bool passthrough)
AudioFormat fmt = FORMAT_NONE;
int err = 0;

AudioOutputSettings *settings = new AudioOutputSettings();
auto *settings = new AudioOutputSettings();

if (m_pcm_handle)
{
Expand Down Expand Up @@ -827,7 +827,7 @@ int AudioOutputALSA::GetVolumeChannel(int channel) const
if (!m_mixer.elem)
return retvol;

snd_mixer_selem_channel_id_t chan = (snd_mixer_selem_channel_id_t) channel;
auto chan = (snd_mixer_selem_channel_id_t) channel;
if (!snd_mixer_selem_has_playback_channel(m_mixer.elem, chan))
return retvol;

Expand Down Expand Up @@ -863,7 +863,7 @@ void AudioOutputALSA::SetVolumeChannel(int channel, int volume)
mixervol = max(mixervol, m_mixer.volmin);
mixervol = min(mixervol, m_mixer.volmax);

snd_mixer_selem_channel_id_t chan = (snd_mixer_selem_channel_id_t) channel;
auto chan = (snd_mixer_selem_channel_id_t) channel;

if (snd_mixer_selem_has_playback_switch(m_mixer.elem))
snd_mixer_selem_set_playback_switch(m_mixer.elem, chan, (volume > 0));
Expand Down Expand Up @@ -984,7 +984,7 @@ bool AudioOutputALSA::OpenMixer(void)

QMap<QString, QString> *AudioOutputALSA::GetDevices(const char *type)
{
QMap<QString, QString> *alsadevs = new QMap<QString, QString>();
auto *alsadevs = new QMap<QString, QString>();
void **hints = nullptr, **n = nullptr;

if (snd_device_name_hint(-1, type, &hints) < 0)
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmyth/audio/audiooutputbase.cpp
Expand Up @@ -189,7 +189,7 @@ AudioOutputSettings* AudioOutputBase::GetOutputSettingsUsers(bool digital)
else if (m_output_settingsdigital)
return m_output_settingsdigital;

AudioOutputSettings* aosettings = new AudioOutputSettings;
auto* aosettings = new AudioOutputSettings;

*aosettings = *GetOutputSettingsCleaned(digital);
aosettings->GetUsers();
Expand Down Expand Up @@ -1628,9 +1628,9 @@ void AudioOutputBase::GetBufferStatus(uint &fill, uint &total)
*/
void AudioOutputBase::OutputAudioLoop(void)
{
uchar *zeros = new uchar[m_fragment_size];
uchar *fragment_buf = new uchar[m_fragment_size + 16];
uchar *fragment = (uchar *)AOALIGN(fragment_buf[0]);
auto *zeros = new uchar[m_fragment_size];
auto *fragment_buf = new uchar[m_fragment_size + 16];
auto *fragment = (uchar *)AOALIGN(fragment_buf[0]);
memset(zeros, 0, m_fragment_size);

// to reduce startup latency, write silence in 8ms chunks
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/audio/audiooutputdigitalencoder.cpp
Expand Up @@ -161,7 +161,7 @@ size_t AudioOutputDigitalEncoder::Encode(void *buf, int len, AudioFormat format)
LOG(VB_AUDIO, LOG_INFO, LOC +
QString("low mem, reallocating in buffer from %1 to %2")
.arg(m_in_size) .arg(required_len));
inbuf_t *tmp = reinterpret_cast<inbuf_t*>
auto *tmp = reinterpret_cast<inbuf_t*>
(realloc(m_in, m_in_size, required_len));
if (!tmp)
{
Expand Down Expand Up @@ -275,7 +275,7 @@ size_t AudioOutputDigitalEncoder::Encode(void *buf, int len, AudioFormat format)
LOG(VB_AUDIO, LOG_WARNING, LOC +
QString("low mem, reallocating out buffer from %1 to %2")
.arg(m_out_size) .arg(required_len));
outbuf_t *tmp = reinterpret_cast<outbuf_t*>
auto *tmp = reinterpret_cast<outbuf_t*>
(realloc(m_out, m_out_size, required_len));
if (!tmp)
{
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmyth/audio/audiooutputgraph.cpp
Expand Up @@ -154,8 +154,8 @@ class AudioOutputGraph::Buffer : protected QByteArray
unsigned long cnt = len;
int n = size();
resize(n + sizeof(int16_t) * cnt);
const uchar *s = reinterpret_cast< const uchar* >(b);
int16_t *p = reinterpret_cast< int16_t* >(data() + n);
const auto *s = reinterpret_cast< const uchar* >(b);
auto *p = reinterpret_cast< int16_t* >(data() + n);
while (cnt--)
*p++ = (int16_t(*s++) - CHAR_MAX) << (16 - CHAR_BIT);
}
Expand All @@ -172,8 +172,8 @@ class AudioOutputGraph::Buffer : protected QByteArray
int n = size();
resize(n + sizeof(int16_t) * cnt);
const float f((1 << 15) - 1);
const float *s = reinterpret_cast< const float* >(b);
int16_t *p = reinterpret_cast< int16_t* >(data() + n);
const auto *s = reinterpret_cast< const float* >(b);
auto *p = reinterpret_cast< int16_t* >(data() + n);
while (cnt--)
*p++ = int16_t(f * *s++);
}
Expand Down Expand Up @@ -312,7 +312,7 @@ MythImage *AudioOutputGraph::GetImage(int64_t timecode) const
image.setPixel(x, height - 1 - y, rgb);
}

MythImage *mi = new MythImage(m_painter);
auto *mi = new MythImage(m_painter);
mi->Assign(image);
return mi;
}
11 changes: 5 additions & 6 deletions mythtv/libs/libmyth/audio/audiooutputjack.cpp
Expand Up @@ -58,7 +58,7 @@ AudioOutputSettings* AudioOutputJACK::GetOutputSettings(bool /*digital*/)
int rate = 0;
int i = 0;
const char **matching_ports = nullptr;
AudioOutputSettings *settings = new AudioOutputSettings();
auto *settings = new AudioOutputSettings();

m_client = _jack_client_open();
if (!m_client)
Expand Down Expand Up @@ -344,7 +344,7 @@ void AudioOutputJACK::DeinterleaveAudio(const float *aubuf, float **bufs, int nf
*/
int AudioOutputJACK::_JackCallback(jack_nframes_t nframes, void *arg)
{
AudioOutputJACK *aoj = static_cast<AudioOutputJACK*>(arg);
auto *aoj = static_cast<AudioOutputJACK*>(arg);
return aoj->JackCallback(nframes);
}

Expand Down Expand Up @@ -433,7 +433,7 @@ int AudioOutputJACK::JackCallback(jack_nframes_t nframes)
*/
int AudioOutputJACK::_JackXRunCallback(void *arg)
{
AudioOutputJACK *aoj = static_cast<AudioOutputJACK*>(arg);
auto *aoj = static_cast<AudioOutputJACK*>(arg);
return aoj->JackXRunCallback();
}

Expand Down Expand Up @@ -461,7 +461,7 @@ int AudioOutputJACK::JackXRunCallback(void)
*/
int AudioOutputJACK::_JackGraphOrderCallback(void *arg)
{
AudioOutputJACK *aoj = static_cast<AudioOutputJACK*>(arg);
auto *aoj = static_cast<AudioOutputJACK*>(arg);
return aoj->JackGraphOrderCallback();
}

Expand Down Expand Up @@ -569,8 +569,7 @@ void AudioOutputJACK::WriteAudio(unsigned char *aubuf, int size)
jack_client_t* AudioOutputJACK::_jack_client_open(void)
{
QString client_name = QString("mythtv_%1").arg(getpid());
jack_options_t open_options =
(jack_options_t)(JackUseExactName | JackNoStartServer);
auto open_options = (jack_options_t)(JackUseExactName | JackNoStartServer);
jack_status_t open_status = JackFailure;

jack_client_t *client = jack_client_open(client_name.toLatin1().constData(),
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audio/audiooutputnull.cpp
Expand Up @@ -53,7 +53,7 @@ void AudioOutputNULL::CloseDevice()
AudioOutputSettings* AudioOutputNULL::GetOutputSettings(bool /*digital*/)
{
// Pretend that we support everything
AudioOutputSettings *settings = new AudioOutputSettings();
auto *settings = new AudioOutputSettings();

// NOLINTNEXTLINE(bugprone-infinite-loop)
while (int rate = settings->GetNextRate())
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audio/audiooutputoss.cpp
Expand Up @@ -36,7 +36,7 @@ AudioOutputOSS::~AudioOutputOSS()

AudioOutputSettings* AudioOutputOSS::GetOutputSettings(bool /*digital*/)
{
AudioOutputSettings *settings = new AudioOutputSettings();
auto *settings = new AudioOutputSettings();

QByteArray device = m_main_device.toLatin1();
m_audiofd = open(device.constData(), O_WRONLY | O_NONBLOCK);
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmyth/audio/audiooutputpulse.cpp
Expand Up @@ -618,7 +618,7 @@ void AudioOutputPulseAudio::FlushStream(const char *caller)
void AudioOutputPulseAudio::ContextStateCallback(pa_context *c, void *arg)
{
QString fn_log_tag = "_ContextStateCallback, ";
AudioOutputPulseAudio *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
auto *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
switch (pa_context_get_state(c))
{
case PA_CONTEXT_READY:
Expand All @@ -637,7 +637,7 @@ void AudioOutputPulseAudio::ContextStateCallback(pa_context *c, void *arg)
void AudioOutputPulseAudio::StreamStateCallback(pa_stream *s, void *arg)
{
QString fn_log_tag = "StreamStateCallback, ";
AudioOutputPulseAudio *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
auto *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
switch (pa_stream_get_state(s))
{
case PA_STREAM_READY:
Expand All @@ -653,7 +653,7 @@ void AudioOutputPulseAudio::StreamStateCallback(pa_stream *s, void *arg)

void AudioOutputPulseAudio::WriteCallback(pa_stream */*s*/, size_t /*size*/, void *arg)
{
AudioOutputPulseAudio *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
auto *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
pa_threaded_mainloop_signal(audoutP->m_mainloop, 0);
}

Expand All @@ -666,7 +666,7 @@ void AudioOutputPulseAudio::OpCompletionCallback(
pa_context *c, int ok, void *arg)
{
QString fn_log_tag = "OpCompletionCallback, ";
AudioOutputPulseAudio *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
auto *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
if (!ok)
{
VBERROR(fn_log_tag + QString("bummer, an operation failed: %1")
Expand All @@ -690,7 +690,7 @@ void AudioOutputPulseAudio::ServerInfoCallback(
void AudioOutputPulseAudio::SinkInfoCallback(
pa_context */*c*/, const pa_sink_info *info, int /*eol*/, void *arg)
{
AudioOutputPulseAudio *audoutP = static_cast<AudioOutputPulseAudio*>(arg);
auto *audoutP = static_cast<AudioOutputPulseAudio*>(arg);

if (!info)
{
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmyth/audio/audiooutpututil.cpp
Expand Up @@ -102,7 +102,7 @@ void AudioOutputUtil::AdjustVolume(void *buf, int len, int volume,
bool music, bool upmix)
{
float g = volume / 100.0F;
float *fptr = (float *)buf;
auto *fptr = (float *)buf;
int samples = len >> 2;
int i = 0;

Expand Down Expand Up @@ -203,8 +203,8 @@ char *AudioOutputUtil::GeneratePinkFrames(char *frames, int channels,

initialize_pink_noise(&pink, bits);

int16_t *samp16 = (int16_t*) frames;
int32_t *samp32 = (int32_t*) frames;
auto *samp16 = (int16_t*) frames;
auto *samp32 = (int32_t*) frames;

while (count-- > 0)
{
Expand Down Expand Up @@ -287,7 +287,7 @@ int AudioOutputUtil::DecodeAudio(AVCodecContext *ctx,
return ret;
}

AVSampleFormat format = (AVSampleFormat)frame->format;
auto format = (AVSampleFormat)frame->format;

data_size = frame->nb_samples * frame->channels * av_get_bytes_per_sample(format);

Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmyth/audio/audiopulsehandler.cpp
Expand Up @@ -55,7 +55,7 @@ bool PulseHandler::Suspend(enum PulseAction action)

static int s_iPulseRunning = -1;
static QTime s_time;
static enum PulseAction s_ePulseAction = PulseAction(-1);
static auto s_ePulseAction = PulseAction(-1);

// Use the last result of IsPulseAudioRunning if within time
if (!s_time.isNull() && s_time.elapsed() < 30000)
Expand Down Expand Up @@ -93,7 +93,7 @@ bool PulseHandler::Suspend(enum PulseAction action)
// create our handler
if (!g_pulseHandler)
{
PulseHandler* handler = new PulseHandler();
auto* handler = new PulseHandler();
if (handler)
{
LOG(VB_AUDIO, LOG_INFO, LOC + "Created PulseHandler object");
Expand Down Expand Up @@ -125,7 +125,7 @@ static void StatusCallback(pa_context *ctx, void *userdata)
return;

// validate the callback
PulseHandler *handler = static_cast<PulseHandler*>(userdata);
auto *handler = static_cast<PulseHandler*>(userdata);
if (!handler)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Callback: no handler.");
Expand Down Expand Up @@ -167,7 +167,7 @@ static void OperationCallback(pa_context *ctx, int success, void *userdata)
}

// validate the callback
PulseHandler *handler = static_cast<PulseHandler*>(userdata);
auto *handler = static_cast<PulseHandler*>(userdata);
if (!handler)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Operation: no handler.");
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audio/spdifencoder.cpp
Expand Up @@ -158,7 +158,7 @@ bool SPDIFEncoder::SetMaxHDRate(int rate)
*/
int SPDIFEncoder::funcIO(void *opaque, unsigned char *buf, int size)
{
SPDIFEncoder *enc = (SPDIFEncoder *)opaque;
auto *enc = (SPDIFEncoder *)opaque;

memcpy(enc->m_buffer + enc->m_size, buf, size);
enc->m_size += size;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audio/volumebase.cpp
Expand Up @@ -23,7 +23,7 @@ class VolumeWriteBackThread : public MThread
static VolumeWriteBackThread *Instance()
{
QMutexLocker lock(&s_mutex);
static VolumeWriteBackThread *s_instance = new VolumeWriteBackThread;
static auto *s_instance = new VolumeWriteBackThread;
return s_instance;
}

Expand Down
16 changes: 6 additions & 10 deletions mythtv/libs/libmyth/backendselect.cpp
Expand Up @@ -52,7 +52,7 @@ BackendSelection::Decision BackendSelection::Prompt(
if (!mainStack)
return ret;

BackendSelection *backendSettings =
auto *backendSettings =
new BackendSelection(mainStack, dbParams, pConfig, true);

if (backendSettings->Create())
Expand Down Expand Up @@ -98,8 +98,7 @@ void BackendSelection::Accept(MythUIButtonListItem *item)
if (!item)
return;

DeviceLocation *dev = item->GetData().value<DeviceLocation *>();

auto *dev = item->GetData().value<DeviceLocation *>();
if (!dev)
{
Cancel();
Expand Down Expand Up @@ -304,7 +303,7 @@ void BackendSelection::customEvent(QEvent *event)
{
if (event->type() == MythEvent::MythEventMessage)
{
MythEvent *me = dynamic_cast<MythEvent *>(event);
auto *me = dynamic_cast<MythEvent *>(event);
if (me == nullptr)
return;

Expand Down Expand Up @@ -337,8 +336,7 @@ void BackendSelection::customEvent(QEvent *event)
}
else if (event->type() == DialogCompletionEvent::kEventType)
{
DialogCompletionEvent *dce = dynamic_cast<DialogCompletionEvent*>(event);

auto *dce = dynamic_cast<DialogCompletionEvent*>(event);
if (!dce)
return;

Expand All @@ -358,10 +356,8 @@ void BackendSelection::PromptForPassword(void)

MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");

MythTextInputDialog *pwDialog = new MythTextInputDialog(popupStack,
message,
FilterNone,
true);
auto *pwDialog = new MythTextInputDialog(popupStack, message,
FilterNone, true);

if (pwDialog->Create())
{
Expand Down
4 changes: 1 addition & 3 deletions mythtv/libs/libmyth/guistartup.cpp
Expand Up @@ -176,9 +176,7 @@ void GUIStartup::Close(void)
QString message = tr("Do you really want to exit MythTV?");
MythScreenStack *popupStack
= GetMythMainWindow()->GetStack("popup stack");
MythConfirmationDialog *confirmdialog
= new MythConfirmationDialog(
popupStack, message);
auto *confirmdialog = new MythConfirmationDialog(popupStack, message);

if (confirmdialog->Create())
popupStack->AddScreen(confirmdialog);
Expand Down

0 comments on commit acf2aeb

Please sign in to comment.