Skip to content

Commit

Permalink
Rename enum getItems to getValues
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Jul 31, 2024
1 parent e78fbec commit 1fc6743
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
26 changes: 13 additions & 13 deletions YUViewLib/src/common/EnumMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@

using namespace std::string_view_literals;

template <class T, std::size_t N> struct EnumMapper
template <class ValueType, std::size_t N> struct EnumMapper
{
public:
using ValueNamePair = std::pair<T, std::string_view>;
using ItemArray = std::array<T, N>;
using ValueNamePair = std::pair<ValueType, std::string_view>;
using ItemArray = std::array<ValueType, N>;
using ItemIterator = typename ItemArray::const_iterator;
using NameArray = std::array<std::string_view, N>;
using NameIterator = typename NameArray::const_iterator;
Expand Down Expand Up @@ -103,7 +103,7 @@ template <class T, std::size_t N> struct EnumMapper

constexpr std::size_t size() const { return N; }

constexpr std::string_view getName(const T value) const
constexpr std::string_view getName(const ValueType value) const
{
const auto it = std::find(this->items.begin(), this->items.end(), value);
if (it == this->items.end())
Expand All @@ -113,7 +113,7 @@ template <class T, std::size_t N> struct EnumMapper
return this->names.at(index);
}

constexpr std::optional<T> getValue(const std::string_view name) const
constexpr std::optional<ValueType> getValue(const std::string_view name) const
{
const auto it =
std::find_if(this->begin(),
Expand All @@ -125,7 +125,7 @@ template <class T, std::size_t N> struct EnumMapper
return it->first;
}

constexpr std::optional<T> getValueCaseInsensitive(const std::string_view name) const
constexpr std::optional<ValueType> getValueCaseInsensitive(const std::string_view name) const
{
const auto compareToNameLowercase = [&name](const std::string_view str)
{
Expand All @@ -147,7 +147,7 @@ template <class T, std::size_t N> struct EnumMapper
return this->items.at(index);
}

std::optional<T> getValueFromNameOrIndex(const std::string_view nameOrIndex) const
std::optional<ValueType> getValueFromNameOrIndex(const std::string_view nameOrIndex) const
{
if (auto index = functions::toUnsigned(nameOrIndex))
if (*index < N)
Expand All @@ -156,7 +156,7 @@ template <class T, std::size_t N> struct EnumMapper
return this->getValue(nameOrIndex);
}

constexpr size_t indexOf(const T value) const
constexpr size_t indexOf(const ValueType value) const
{
const auto it = std::find(this->items.begin(), this->items.end(), value);
if (it == this->items.end())
Expand All @@ -167,23 +167,23 @@ template <class T, std::size_t N> struct EnumMapper
return index;
}

constexpr std::optional<T> at(const size_t index) const
constexpr std::optional<ValueType> at(const size_t index) const
{
if (index >= N)
return {};
return this->items.at(index);
}

constexpr const ItemArray &getItems() const { return this->items; }
constexpr const ItemArray &getValues() const { return this->items; }
constexpr const NameArray &getNames() const { return this->names; }

private:
constexpr void addElementsRecursively(const std::size_t) {};

template <typename TArg, typename... Args>
constexpr void addElementsRecursively(const std::size_t index, TArg first, Args... args)
template <typename ArgumentType, typename... Args>
constexpr void addElementsRecursively(const std::size_t index, ArgumentType first, Args... args)
{
static_assert(std::is_same<ValueNamePair, TArg>());
static_assert(std::is_same<ValueNamePair, ArgumentType>());

const auto [value, name] = first;
this->items[index] = value;
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/video/yuv/videoHandlerYUV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,7 @@ void videoHandlerYUV::setFormatFromCorrelation(const QByteArray &rawYUVData, int
{
int bits = (b == 0) ? 8 : (b == 1) ? 10 : 16;
// Test all subsampling modes
for (const auto &subsampling : SubsamplingMapper.getItems())
for (const auto &subsampling : SubsamplingMapper.getValues())
for (const auto &size : testSizes)
formatList.push_back(
testFormatAndSize(size, PixelFormatYUV(subsampling, bits, PlaneOrder::YUV)));
Expand Down
4 changes: 2 additions & 2 deletions YUViewUnitTest/common/EnumMapperTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ TEST(EnumMapperTest, testAt)
EXPECT_FALSE(TestEnumMapper.at(8902));
}

TEST(EnumMapperTest, testGetItems)
TEST(EnumMapperTest, testGetValues)
{
ASSERT_THAT(TestEnumMapper.getItems(),
ASSERT_THAT(TestEnumMapper.getValues(),
ElementsAre(TestEnum::ValueOne, TestEnum::ValueTwo, TestEnum::ValueThree));
}

Expand Down
8 changes: 4 additions & 4 deletions YUViewUnitTest/video/rgb/ConversionRGBTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void testConversionToRGBASinglePlane(const QByteArray &sourceBuffer,
const bool limitedRange,
const bool)
{
for (const auto channel : ChannelMapper.getItems())
for (const auto channel : ChannelMapper.getValues())
{
if (channel == Channel::Alpha && !srcPixelFormat.hasAlpha())
continue;
Expand Down Expand Up @@ -246,11 +246,11 @@ void runTestForAllParameters(TestingFunction testingFunction)
{
for (const auto bitDepth : {8, 10, 12})
{
for (const auto &alphaMode : AlphaModeMapper.getItems())
for (const auto &alphaMode : AlphaModeMapper.getValues())
{
for (const auto &dataLayout : video::DataLayoutMapper.getItems())
for (const auto &dataLayout : video::DataLayoutMapper.getValues())
{
for (const auto &channelOrder : video::rgb::ChannelOrderMapper.getItems())
for (const auto &channelOrder : video::rgb::ChannelOrderMapper.getValues())
{
const video::rgb::PixelFormatRGB format(
bitDepth, dataLayout, channelOrder, alphaMode, endianness);
Expand Down
8 changes: 4 additions & 4 deletions YUViewUnitTest/video/rgb/GetPixelValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ void testGetPixelValueFromBuffer(const QByteArray &sourceBuffer,

TEST(GetPixelValueTest, TestGetPixelValueFromBuffer)
{
for (const auto endianness : EndianessMapper.getItems())
for (const auto endianness : EndianessMapper.getValues())
{
for (auto bitDepth : {8, 10, 12})
{
for (const auto &alphaMode : AlphaModeMapper.getItems())
for (const auto &alphaMode : AlphaModeMapper.getValues())
{
for (const auto &dataLayout : DataLayoutMapper.getItems())
for (const auto &dataLayout : DataLayoutMapper.getValues())
{
for (const auto &channelOrder : ChannelOrderMapper.getItems())
for (const auto &channelOrder : ChannelOrderMapper.getValues())
{
const PixelFormatRGB pixelFormat(
bitDepth, dataLayout, channelOrder, alphaMode, endianness);
Expand Down
8 changes: 4 additions & 4 deletions YUViewUnitTest/video/rgb/PixelFormatRGBTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ std::vector<PixelFormatRGB> getAllFormats()
std::vector<PixelFormatRGB> allFormats;

for (int bitsPerPixel = 8; bitsPerPixel <= 16; bitsPerPixel++)
for (auto dataLayout : DataLayoutMapper.getItems())
for (auto channelOrder : ChannelOrderMapper.getItems())
for (auto alphaMode : AlphaModeMapper.getItems())
for (auto endianness : EndianessMapper.getItems())
for (auto dataLayout : DataLayoutMapper.getValues())
for (auto channelOrder : ChannelOrderMapper.getValues())
for (auto alphaMode : AlphaModeMapper.getValues())
for (auto endianness : EndianessMapper.getValues())
allFormats.push_back(
PixelFormatRGB(bitsPerPixel, dataLayout, channelOrder, alphaMode, endianness));

Expand Down
6 changes: 3 additions & 3 deletions YUViewUnitTest/video/yuv/PixelFormatYUVTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ std::vector<PixelFormatYUV> getAllFormats()
{
std::vector<PixelFormatYUV> allFormats;

for (const auto subsampling : SubsamplingMapper.getItems())
for (const auto subsampling : SubsamplingMapper.getValues())
{
for (const auto bitsPerSample : BitDepthList)
{
const auto endianList =
(bitsPerSample > 8) ? std::vector<bool>({false, true}) : std::vector<bool>({false});

// Planar
for (const auto planeOrder : PlaneOrderMapper.getItems())
for (const auto planeOrder : PlaneOrderMapper.getValues())
for (const auto bigEndian : endianList)
allFormats.push_back(PixelFormatYUV(subsampling, bitsPerSample, planeOrder, bigEndian));

Expand All @@ -65,7 +65,7 @@ std::vector<PixelFormatYUV> getAllFormats()
}
}

for (auto predefinedFormat : PredefinedPixelFormatMapper.getItems())
for (auto predefinedFormat : PredefinedPixelFormatMapper.getValues())
allFormats.push_back(PixelFormatYUV(predefinedFormat));

return allFormats;
Expand Down

0 comments on commit 1fc6743

Please sign in to comment.