From 32abfb18d12f4d32b620cb3bc2b94f065a3ee7c2 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 27 Jun 2014 11:24:04 +0000 Subject: [PATCH] base: various Visual Studio compilation fixes. --- src/image/codec/gdiplus-image.cpp | 5 +- src/image/pixel.cpp | 4 ++ src/lol/base/array.h | 93 ++++++++++++++++++++++++++++++- src/lol/image/pixel.h | 4 ++ src/lol/math/array2d.h | 4 +- src/lol/math/array3d.h | 6 +- 6 files changed, 107 insertions(+), 9 deletions(-) diff --git a/src/image/codec/gdiplus-image.cpp b/src/image/codec/gdiplus-image.cpp index ecb86168..d67d534a 100644 --- a/src/image/codec/gdiplus-image.cpp +++ b/src/image/codec/gdiplus-image.cpp @@ -124,9 +124,8 @@ bool GdiPlusImageCodec::Load(Image *image, char const *path) image->SetSize(size); u8vec4 *pdst = image->Lock(); u8vec4 *psrc = static_cast(bdata.Scan0); - for (int y = 0; y < size.y; y++) - for (int x = 0; x < size.x; x++) - *pdst++ = (*psrc++).bgra; + for (int n = 0; n < size.x * size.y; n++) + pdst[n] = psrc[n].bgra; image->Unlock(pdst); bitmap->UnlockBits(&bdata); diff --git a/src/image/pixel.cpp b/src/image/pixel.cpp index a7295894..9a1113fe 100644 --- a/src/image/pixel.cpp +++ b/src/image/pixel.cpp @@ -68,8 +68,10 @@ void Image::SetFormat(PixelFormat fmt) if (m_data->m_pixels[(int)fmt] == nullptr) { PixelDataBase *data = nullptr; +#if __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic error "-Wswitch" +#endif switch (fmt) { case PixelFormat::Unknown: @@ -87,7 +89,9 @@ void Image::SetFormat(PixelFormat fmt) case PixelFormat::RGBA_F32: data = new PixelData(size); break; } +#if __GNUC__ #pragma GCC diagnostic pop +#endif ASSERT(data, "invalid pixel type %d", (int)fmt); m_data->m_pixels[(int)fmt] = data; } diff --git a/src/lol/base/array.h b/src/lol/base/array.h index 2903bf8d..f7b79aef 100644 --- a/src/lol/base/array.h +++ b/src/lol/base/array.h @@ -29,6 +29,9 @@ namespace lol { +/* Set this to 1 when Visual Studio finally understands the feature */ +#define INHERIT_CONSTRUCTORS 0 + #define INDEX_NONE -1 /* @@ -52,7 +55,7 @@ public: m_count(0), m_reserved(0) { - Reserve(list.size()); + Reserve((int)list.size()); for (auto elem : list) Push(elem); } @@ -548,8 +551,19 @@ template, Array> { +#if INHERIT_CONSTRUCTORS using ArrayBase, Array>::ArrayBase; +#else +public: + inline Array() + : ArrayBase, + Array>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase, + Array>::ArrayBase(list) {} +#endif public: inline void Push(T1 const &m1, T2 const &m2, T3 const &m3, T4 const &m4, @@ -590,8 +604,19 @@ class Array : public ArrayBase, Array> { +#if INHERIT_CONSTRUCTORS using ArrayBase, Array>::ArrayBase; +#else +public: + inline Array() + : ArrayBase, + Array>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase, + Array>::ArrayBase(list) {} +#endif public: inline void Push(T1 const &m1, T2 const &m2, T3 const &m3, T4 const &m4, @@ -630,8 +655,19 @@ class Array : public ArrayBase, Array> { +#if INHERIT_CONSTRUCTORS using ArrayBase, Array>::ArrayBase; +#else +public: + inline Array() + : ArrayBase, + Array>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase, + Array>::ArrayBase(list) {} +#endif public: inline void Push(T1 const &m1, T2 const &m2, T3 const &m3, T4 const &m4, @@ -667,8 +703,19 @@ class Array : public ArrayBase, Array> { +#if INHERIT_CONSTRUCTORS using ArrayBase, Array>::ArrayBase; +#else +public: + inline Array() + : ArrayBase, + Array>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase, + Array>::ArrayBase(list) {} +#endif public: inline void Push(T1 const &m1, T2 const &m2, T3 const &m3, T4 const &m4, @@ -702,8 +749,19 @@ class Array : public ArrayBase, Array> { +#if INHERIT_CONSTRUCTORS using ArrayBase, Array>::ArrayBase; +#else +public: + inline Array() + : ArrayBase, + Array>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase, + Array>::ArrayBase(list) {} +#endif public: inline void Push(T1 const &m1, T2 const &m2, T3 const &m3, T4 const &m4) @@ -733,8 +791,19 @@ class Array : public ArrayBase, Array> { +#if INHERIT_CONSTRUCTORS using ArrayBase, Array>::ArrayBase; +#else +public: + inline Array() + : ArrayBase, + Array>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase, + Array>::ArrayBase(list) {} +#endif public: inline void Push(T1 const &m1, T2 const &m2, T3 const &m3) @@ -762,8 +831,19 @@ class Array : public ArrayBase, Array> { +#if INHERIT_CONSTRUCTORS using ArrayBase, Array>::ArrayBase; +#else +public: + inline Array() + : ArrayBase, + Array>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase, + Array>::ArrayBase(list) {} +#endif public: inline void Push(T1 const &m1, T2 const &m2) @@ -789,8 +869,19 @@ class Array : public ArrayBase> { +#if INHERIT_CONSTRUCTORS using ArrayBase>::ArrayBase; +#else +public: + inline Array() + : ArrayBase>::ArrayBase() {} + + inline Array(std::initializer_list const &list) + : ArrayBase>::ArrayBase(list) {} +#endif }; } /* namespace lol */ diff --git a/src/lol/image/pixel.h b/src/lol/image/pixel.h index e9ea1a21..7fd37133 100644 --- a/src/lol/image/pixel.h +++ b/src/lol/image/pixel.h @@ -44,8 +44,10 @@ template<> struct PixelType { typedef vec4 type; }; /* Number of bytes used by each pixel format */ static inline uint8_t BytesPerPixel(PixelFormat format) { +#if __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic error "-Wswitch" +#endif switch (format) { case PixelFormat::Unknown: @@ -64,7 +66,9 @@ static inline uint8_t BytesPerPixel(PixelFormat format) return 16; } return 0; +#if __GNUC__ #pragma GCC diagnostic pop +#endif }; } /* namespace lol */ diff --git a/src/lol/math/array2d.h b/src/lol/math/array2d.h index 07e55b0f..4f390b92 100644 --- a/src/lol/math/array2d.h +++ b/src/lol/math/array2d.h @@ -46,8 +46,8 @@ public: inline Array2D(std::initializer_list< std::initializer_list> const &list) - : m_size(list.size() ? (*list.begin()).size() : 0, - list.size()) + : m_size(list.size() ? (int)(*list.begin()).size() : 0, + (int)list.size()) { Super::Reserve(m_size.x * m_size.y); for (auto l : list) diff --git a/src/lol/math/array3d.h b/src/lol/math/array3d.h index 444bbdae..f6700a29 100644 --- a/src/lol/math/array3d.h +++ b/src/lol/math/array3d.h @@ -48,9 +48,9 @@ public: std::initializer_list< std::initializer_list>> const &list) : m_size(list.size() && (*list.begin()).size() ? - (*(*list.begin()).begin()).size() : 0, - list.size() ? (*list.begin()).size() : 0, - list.size()) + (int)(*(*list.begin()).begin()).size() : 0, + list.size() ? (int)(*list.begin()).size() : 0, + (int)list.size()) { Super::Reserve(m_size.x * m_size.y * m_size.z); for (auto ll : list)