From c224dfaf815cad5196f58c8b3784e07f991d419e Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Fri, 30 Apr 2010 07:11:06 +0000 Subject: [PATCH] [2994288] AI_BE / AI_LE macros - Thanks to mick-p for the patch. Add shared_ptr to pch includes. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@712 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/AssimpPCH.h | 1 + code/ByteSwap.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/code/AssimpPCH.h b/code/AssimpPCH.h index daf7673c1..b07f9c2a7 100644 --- a/code/AssimpPCH.h +++ b/code/AssimpPCH.h @@ -134,6 +134,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "qnan.h" // ---------------------------------------------------------------------------------------- +#include #include #include #include diff --git a/code/ByteSwap.h b/code/ByteSwap.h index 79bb86d68..75877bc9a 100644 --- a/code/ByteSwap.h +++ b/code/ByteSwap.h @@ -162,6 +162,40 @@ public: static inline void Swap(uint64_t* fOut) { Swap8(fOut); } + + // ---------------------------------------------------------------------- + //! Templatized ByteSwap + //! \returns param tOut as swapped + template + static inline Type Swapped(Type tOut) + { + return _swapper()(tOut); + } + +private: + + template struct _swapper; +}; + +template struct ByteSwap::_swapper { + T operator() (T tOut) { + Swap2(&tOut); + return tOut; + } +}; + +template struct ByteSwap::_swapper { + T operator() (T tOut) { + Swap4(&tOut); + return tOut; + } +}; + +template struct ByteSwap::_swapper { + T operator() (T tOut) { + Swap8(&tOut); + return tOut; + } }; } // Namespace Assimp @@ -171,6 +205,8 @@ public: // ByteSwap macros for BigEndian/LittleEndian support // -------------------------------------------------------------------------------------- #if (defined AI_BUILD_BIG_ENDIAN) +# define AI_LE(t) (t) +# define AI_BE(t) ByteSwap::Swapped(t) # define AI_LSWAP2(p) # define AI_LSWAP4(p) # define AI_LSWAP8(p) @@ -186,6 +222,8 @@ public: # define AI_SWAP8P(p) ByteSwap::Swap8((p)) # define BE_NCONST #else +# define AI_BE(t) (t) +# define AI_LE(t) ByteSwap::Swapped(t) # define AI_SWAP2(p) # define AI_SWAP4(p) # define AI_SWAP8(p)