From 632e4a20a989d2e2849b81d828ab22fba3b8d6da Mon Sep 17 00:00:00 2001 From: Salvage <29021710+Saalvage@users.noreply.github.com> Date: Tue, 11 May 2021 05:29:51 +0200 Subject: [PATCH 1/2] Utilize decltype for slightly improved syntax --- include/assimp/Bitmap.h | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/include/assimp/Bitmap.h b/include/assimp/Bitmap.h index d56bb4c73..a455e2ecf 100644 --- a/include/assimp/Bitmap.h +++ b/include/assimp/Bitmap.h @@ -75,13 +75,12 @@ protected: uint32_t offset; // We define the struct size because sizeof(Header) might return a wrong result because of structure padding. - // Moreover, we must use this ugly and error prone syntax because Visual Studio neither support constexpr or sizeof(name_of_field). - static const std::size_t header_size = - sizeof(uint16_t) + // type - sizeof(uint32_t) + // size - sizeof(uint16_t) + // reserved1 - sizeof(uint16_t) + // reserved2 - sizeof(uint32_t); // offset + static constexpr std::size_t header_size = + sizeof(decltype(type)) + + sizeof(decltype(size)) + + sizeof(decltype(reserved1)) + + sizeof(decltype(reserved2)) + + sizeof(decltype(offset)); }; struct DIB { @@ -98,22 +97,21 @@ protected: uint32_t nb_important_colors; // We define the struct size because sizeof(DIB) might return a wrong result because of structure padding. - // Moreover, we must use this ugly and error prone syntax because Visual Studio neither support constexpr or sizeof(name_of_field). - static const std::size_t dib_size = - sizeof(uint32_t) + // size - sizeof(int32_t) + // width - sizeof(int32_t) + // height - sizeof(uint16_t) + // planes - sizeof(uint16_t) + // bits_per_pixel - sizeof(uint32_t) + // compression - sizeof(uint32_t) + // image_size - sizeof(int32_t) + // x_resolution - sizeof(int32_t) + // y_resolution - sizeof(uint32_t) + // nb_colors - sizeof(uint32_t); // nb_important_colors + static constexpr std::size_t dib_size = + sizeof(decltype(size)) + + sizeof(decltype(width)) + + sizeof(decltype(height)) + + sizeof(decltype(planes)) + + sizeof(decltype(bits_per_pixel)) + + sizeof(decltype(compression)) + + sizeof(decltype(image_size)) + + sizeof(decltype(x_resolution)) + + sizeof(decltype(y_resolution)) + + sizeof(decltype(nb_colors)) + + sizeof(decltype(nb_important_colors)); }; - static const std::size_t mBytesPerPixel = 4; + static constexpr std::size_t mBytesPerPixel = 4; public: static void Save(aiTexture* texture, IOStream* file); From 8d20460ae43728b31d390a49a81b655cfe856ad9 Mon Sep 17 00:00:00 2001 From: Salvage <29021710+Saalvage@users.noreply.github.com> Date: Tue, 11 May 2021 19:06:21 +0200 Subject: [PATCH 2/2] Ditch decltype --- include/assimp/Bitmap.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/assimp/Bitmap.h b/include/assimp/Bitmap.h index a455e2ecf..e4ce194d9 100644 --- a/include/assimp/Bitmap.h +++ b/include/assimp/Bitmap.h @@ -76,11 +76,11 @@ protected: // We define the struct size because sizeof(Header) might return a wrong result because of structure padding. static constexpr std::size_t header_size = - sizeof(decltype(type)) + - sizeof(decltype(size)) + - sizeof(decltype(reserved1)) + - sizeof(decltype(reserved2)) + - sizeof(decltype(offset)); + sizeof(type) + + sizeof(size) + + sizeof(reserved1) + + sizeof(reserved2) + + sizeof(offset); }; struct DIB { @@ -98,17 +98,17 @@ protected: // We define the struct size because sizeof(DIB) might return a wrong result because of structure padding. static constexpr std::size_t dib_size = - sizeof(decltype(size)) + - sizeof(decltype(width)) + - sizeof(decltype(height)) + - sizeof(decltype(planes)) + - sizeof(decltype(bits_per_pixel)) + - sizeof(decltype(compression)) + - sizeof(decltype(image_size)) + - sizeof(decltype(x_resolution)) + - sizeof(decltype(y_resolution)) + - sizeof(decltype(nb_colors)) + - sizeof(decltype(nb_important_colors)); + sizeof(size) + + sizeof(width) + + sizeof(height) + + sizeof(planes) + + sizeof(bits_per_pixel) + + sizeof(compression) + + sizeof(image_size) + + sizeof(x_resolution) + + sizeof(y_resolution) + + sizeof(nb_colors) + + sizeof(nb_important_colors); }; static constexpr std::size_t mBytesPerPixel = 4;