X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FKM_platform.h;h=defcd8a23b41c13cf9791b9df49dc661ed88853f;hb=dd3acfff947ca52e1a3260243cb38f7035626282;hp=54d5f2789d0b70b4091c1326cb9817541e275cc5;hpb=03f7685c1bc862896fa8e04289f6738749cd5d12;p=asdcplib.git diff --git a/src/KM_platform.h b/src/KM_platform.h index 54d5f27..defcd8a 100644 --- a/src/KM_platform.h +++ b/src/KM_platform.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2009, John Hurst +Copyright (c) 2004-2015, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -32,7 +32,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef _KM_PLATFORM_H_ # define _KM_PLATFORM_H_ -# ifdef __APPLE__ +#if defined(__APPLE__) && defined(__MACH__) +# define KM_MACOSX # ifdef __BIG_ENDIAN__ # define KM_BIG_ENDIAN # endif @@ -120,11 +121,17 @@ namespace Kumu // template inline T xclamp(T v, T l, T h) { - if ( v < l ) return l; - if ( v > h ) return h; + if ( v < l ) { return l; } + if ( v > h ) { return h; } return v; } + // + template + inline T xabs(T n) { + if ( n < 0 ) { return -n; } + return n; + } // read an integer from byte-structured storage template @@ -134,6 +141,7 @@ namespace Kumu template inline void i2p(T i, byte_t* p) { *(T*)p = i; } + # ifdef KM_BIG_ENDIAN # define KM_i16_LE(i) Kumu::Swap2(i) # define KM_i32_LE(i) Kumu::Swap4(i) @@ -166,7 +174,7 @@ namespace Kumu ~mem_ptr() { delete m_p; } inline T& operator*() const { return *m_p; } - inline T* operator->() const { return m_p; } + inline T* operator->() const { assert(m_p!=0); return m_p; } inline operator T*()const { return m_p; } inline const mem_ptr& operator=(T* p) { this->set(p); return *this; } inline T* set(T* p) { delete m_p; m_p = p; return m_p; }