Skip to content

Commit

Permalink
Convert another enum mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Jul 21, 2024
1 parent 9a09483 commit e0bc883
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
11 changes: 11 additions & 0 deletions YUViewLib/src/common/NewEnumMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <algorithm>
#include <array>
#include <cuchar>
#include <optional>
#include <string_view>

using namespace std::string_view_literals;
Expand All @@ -59,6 +60,16 @@ template <class T, size_t N> struct NewEnumMapper
return this->names.at(index);
}

constexpr std::optional<T> getValue(std::string_view name) const
{
const auto it = std::find(this->names.begin(), this->names.end(), name);
if (it == this->names.end())
return {};

const auto index = std::distance(this->names.begin(), it);
return this->items.at(index);
}

constexpr const std::array<T, N> &getItems() const { return this->items; }

private:
Expand Down
8 changes: 4 additions & 4 deletions YUViewLib/src/common/YUViewDomElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ double YUViewDomElement::findChildValueDouble(const QString &tagName, double def
return r.isEmpty() ? defaultValue : r.toDouble();
};

void YUViewDomElement::appendProperiteChild(const QString & type,
const QString & name,
void YUViewDomElement::appendProperiteChild(const QString &type,
const QString &name,
const QStringPairList &attributes)
{
auto newChild = ownerDocument().createElement(type);
Expand All @@ -92,9 +92,9 @@ void YUViewDomElement::setAttribute(const std::string &name, const std::string &
QDomElement::setAttribute(QString::fromStdString(name), QString::fromStdString(value));
}

void YUViewDomElement::appendProperiteChild(const std::string &type, const std::string &name)
void YUViewDomElement::appendProperiteChild(const std::string &type, const std::string_view name)
{
auto newChild = ownerDocument().createElement(QString::fromStdString(type));
newChild.appendChild(ownerDocument().createTextNode(QString::fromStdString(name)));
newChild.appendChild(ownerDocument().createTextNode(QString::fromStdString(std::string(name))));
appendChild(newChild);
}
6 changes: 3 additions & 3 deletions YUViewLib/src/common/YUViewDomElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class YUViewDomElement : public QDomElement
using QDomElement::setAttribute;
void setAttribute(const std::string &name, const std::string &value);

void appendProperiteChild(const QString & type,
const QString & name,
void appendProperiteChild(const QString &type,
const QString &name,
const QStringPairList &attributes = QStringPairList());
void appendProperiteChild(const std::string &type, const std::string &name);
void appendProperiteChild(const std::string &type, const std::string_view name);
};
23 changes: 12 additions & 11 deletions YUViewLib/src/decoder/decoderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#pragma once

#include <common/EnumMapper.h>
#include <common/NewEnumMapper.h>
#include <filesource/FileSourceAnnexBFile.h>
#include <statistics/StatisticsData.h>
#include <video/rgb/videoHandlerRGB.h>
Expand Down Expand Up @@ -64,13 +64,14 @@ enum class DecoderEngine
FFMpeg // The FFMpeg decoder
};

const auto DecoderEngineMapper = EnumMapper<DecoderEngine>({{DecoderEngine::Invalid, "Invalid"},
{DecoderEngine::Libde265, "Libde265"},
{DecoderEngine::HM, "HM"},
{DecoderEngine::VTM, "VTM"},
{DecoderEngine::VVDec, "VVDec"},
{DecoderEngine::Dav1d, "Dav1d"},
{DecoderEngine::FFMpeg, "FFMpeg"}});
constexpr auto DecoderEngineMapper =
NewEnumMapper<DecoderEngine, 7>(std::make_pair(DecoderEngine::Invalid, "Invalid"sv),
std::make_pair(DecoderEngine::Libde265, "Libde265"sv),
std::make_pair(DecoderEngine::HM, "HM"sv),
std::make_pair(DecoderEngine::VTM, "VTM"sv),
std::make_pair(DecoderEngine::VVDec, "VVDec"sv),
std::make_pair(DecoderEngine::Dav1d, "Dav1d"sv),
std::make_pair(DecoderEngine::FFMpeg, "FFMpeg"sv));

const auto DecodersHEVC =
std::vector<DecoderEngine>({DecoderEngine::Libde265, DecoderEngine::HM, DecoderEngine::FFMpeg});
Expand All @@ -90,7 +91,7 @@ class decoderBase
// Create a new decoder. cachingDecoder: Is this a decoder used for caching or interactive
// decoding?
decoderBase(bool cachingDecoder = false);
virtual ~decoderBase(){};
virtual ~decoderBase() {};

// Reset the decoder. Afterwards, the decoder should behave as if you just created a new one
// (without the overhead of reloading the libraries). This must be used in case of errors or when
Expand Down Expand Up @@ -179,8 +180,8 @@ class decoderBase
class decoderBaseSingleLib : public decoderBase
{
public:
decoderBaseSingleLib(bool cachingDecoder = false) : decoderBase(cachingDecoder){};
virtual ~decoderBaseSingleLib(){};
decoderBaseSingleLib(bool cachingDecoder = false) : decoderBase(cachingDecoder) {};
virtual ~decoderBaseSingleLib() {};

QStringList getLibraryPaths() const override
{
Expand Down
3 changes: 2 additions & 1 deletion YUViewLib/src/playlistitem/playlistItemCompressedVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,8 @@ void playlistItemCompressedVideo::createPropertiesWidget()
}
// Add decoders we can use
for (auto e : possibleDecoders)
ui.comboBoxDecoder->addItem(QString::fromStdString(DecoderEngineMapper.getName(e)));
ui.comboBoxDecoder->addItem(
QString::fromStdString(std::string(DecoderEngineMapper.getName(e))));
if (const auto index = vectorIndexOf(possibleDecoders, this->decoderEngine))
ui.comboBoxDecoder->setCurrentIndex(static_cast<int>(index.value()));

Expand Down
6 changes: 3 additions & 3 deletions YUViewLib/src/ui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)

for (const auto &decoder : decoder::DecodersHEVC)
ui.comboBoxDefaultHEVC->addItem(
QString::fromStdString(decoder::DecoderEngineMapper.getName(decoder)));
QString::fromStdString(std::string(decoder::DecoderEngineMapper.getName(decoder))));
for (const auto &decoder : decoder::DecodersVVC)
ui.comboBoxDefaultVVC->addItem(
QString::fromStdString(decoder::DecoderEngineMapper.getName(decoder)));
QString::fromStdString(std::string(decoder::DecoderEngineMapper.getName(decoder))));
for (const auto &decoder : decoder::DecodersAV1)
ui.comboBoxDefaultAV1->addItem(
QString::fromStdString(decoder::DecoderEngineMapper.getName(decoder)));
QString::fromStdString(std::string(decoder::DecoderEngineMapper.getName(decoder))));

ui.comboBoxDefaultHEVC->setCurrentText(settings.value("DefaultDecoderHEVC", 0).toString());
ui.comboBoxDefaultVVC->setCurrentText(settings.value("DefaultDecoderVVC", 0).toString());
Expand Down

0 comments on commit e0bc883

Please sign in to comment.