/*
-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
#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
//
template<class T>
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<class T>
+ inline T xabs(T n) {
+ if ( n < 0 ) { return -n; }
+ return n;
+ }
// read an integer from byte-structured storage
template<class T>
template<class T>
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)
~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<T>& operator=(T* p) { this->set(p); return *this; }
inline T* set(T* p) { delete m_p; m_p = p; return m_p; }
T(const T&); \
T& operator=(const T&)
+/*
+// Example
+ class foo
+ {
+ KM_NO_COPY_CONSTRUCT(foo); // accessing private mthods will cause compile time error
+ public:
+ // ...
+ };
+*/
+
+// Produces copy constructor boilerplate. Implements
+// copy and assignment, see example below
+# define KM_EXPLICIT_COPY_CONSTRUCT(T) \
+ T(const T&); \
+ const T& operator=(const T&)
+
+# define KM_EXPLICIT_COPY_CONSTRUCT_IMPL_START(N, T) \
+ void T##_copy_impl(N::T& lhs, const N::T& rhs) \
+ {
+
+#define KM_COPY_ITEM(I) lhs.I = rhs.I;
+
+# define KM_EXPLICIT_COPY_CONSTRUCT_IMPL_END(N, T) \
+ } \
+ N::T::T(const N::T& rhs) { T##_copy_impl(*this, rhs); } \
+ const N::T& N::T::operator=(const N::T& rhs) { T##_copy_impl(*this, rhs); return *this; }
+
+/*
+// Example
+namespace bar {
+ class foo
+ {
+ public:
+ std::string param_a;
+ int param_b;
+
+ KM_EXPLICIT_COPY_CONSTRUCT(foo);
+ // ...
+ };
+}
+
+//
+KM_EXPLICIT_COPY_CONSTRUCT_IMPL_START(bar, foo)
+KM_COPY_ITEM(param_a)
+KM_COPY_ITEM(param_b)
+KM_EXPLICIT_COPY_CONSTRUCT_IMPL_END(bar, foo)
+*/
+
#endif // _KM_PLATFORM_H_
//