From eef0db7d073fb982a24218d331cb044b55916865 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 9 Jul 2024 15:21:49 -0400 Subject: [PATCH] Use a `switch` statement in `common::sample_type_to_string()`. --- src/common/utilities.cpp | 32 +++++++++++++------------------- src/common/utilities.hh | 7 ------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp index af4bf976..90d8e70d 100644 --- a/src/common/utilities.cpp +++ b/src/common/utilities.cpp @@ -166,28 +166,22 @@ common::bytes_per_chunk(const std::vector& dimensions, return n_bytes; } -const char* -common::sample_type_to_dtype(SampleType t) - -{ - static const char* table[] = { "u1", "u2", "i1", "i2", - "f4", "u2", "u2", "u2" }; - if (t < countof(table)) { - return table[t]; - } else { - throw std::runtime_error("Invalid sample type."); - } -} - const char* common::sample_type_to_string(SampleType t) noexcept { - static const char* table[] = { "u8", "u16", "i8", "i16", - "f32", "u16", "u16", "u16" }; - if (t < countof(table)) { - return table[t]; - } else { - return "unrecognized pixel type"; + switch (t) { + case SampleType_u8: + return "u8"; + case SampleType_u16: + return "u16"; + case SampleType_i8: + return "i8"; + case SampleType_i16: + return "i16"; + case SampleType_f32: + return "f32"; + default: + return "unrecognized pixel type"; } } diff --git a/src/common/utilities.hh b/src/common/utilities.hh index e2241c89..1290c53e 100644 --- a/src/common/utilities.hh +++ b/src/common/utilities.hh @@ -80,13 +80,6 @@ size_t bytes_per_chunk(const std::vector& dimensions, const SampleType& dtype); -/// @brief Get the Zarr dtype for a given SampleType. -/// @param t An enumerated sample type. -/// @throw std::runtime_error if @par t is not a valid SampleType. -/// @return A representation of the SampleType @par t expected by a Zarr reader. -const char* -sample_type_to_dtype(SampleType t); - /// @brief Get a string representation of the SampleType enum. /// @param t An enumerated sample type. /// @return A human-readable representation of the SampleType @par t.