cxUtils.h

// cxUtils.h
//
// Author David Barrett-Lennard  
// (C)opyright Cedanet Pty Ltd 2004

#pragma once
#ifndef Ceda_cxUtils_cxUtils_H
#define Ceda_cxUtils_cxUtils_H

#include "BasicTypes.h"

#if defined(_WIN32) && !defined(__WINE__) && !defined(cxUtils_STATIC_LIBRARY)
    #ifdef cxUtils_IS_COMPILING
        // While compiling the library, export symbols
        #define cxUtils_API __declspec(dllexport)
        #define cxUtils_API_T
    #else
        // While #including public headers of the library, import symbols
        #define cxUtils_API __declspec(dllimport)
        #define cxUtils_API_T __declspec(dllimport)
    #endif
#else
    #define cxUtils_API 
    #define cxUtils_API_T
#endif

// Used to self document WIN32 calls.  Example  cxWIN32::GetCurrentThreadId()
#define cxWIN32

// Used to self document functions that throw exceptions
#define cxThrow()
#define cxThrow1(e)
#define cxThrow2(e1,e2)
#define cxThrow3(e1,e2,e3)
#define cxThrow4(e1,e2,e3,e4)
#define cxThrow5(e1,e2,e3,e4,e5)
#define cxThrow6(e1,e2,e3,e4,e5,e6)

#define cxArraySize(a)  (sizeof (a) / sizeof (a[0])) 

// Hide copy constructor and assignment operator in classes which are not meant to be cloneable
// This guarantees a compiler error when the programmer inadvertently passes such a class
// by value etc.
#define cxNotCloneable(X)    private: X(const X& other); X& operator=(const X& other); public:

#define cxOffsetOfMember(cls,member)   ((octet_t*) &((cls*) 0)->member - (octet_t*) (cls*) 0)

// Note that the base class can be to any super class in the hierarchy
#define cxOffsetOfBase(cls,basecls)   ((octet_t*) (basecls*) (cls*) 0 - (octet_t*) 0)

/*
According to the ANSI C++ standard, it's not possible to bind a non-const reference to a temporary.  
By default MSVC allow this as a "non standard extension", that only produces a warning at level 4
(i.e. with /W4).   /Za can be used to disable Microsoft extensions to C and C++.

The following macros allow for binding a non-const reference to a temporary, and comply with
C++03.
*/
#define CEDA_REFERENCE_TEMPORARY(T,x)  const_cast<T&>(static_cast<const T&>(x))
#define CEDA_REFERENCE_DEFAULT_TEMPORARY(T)  const_cast<T&>(static_cast<const T&>(T()))

/*
At warning level 4 MSVC issues a warning for unreferenced formal parameters in functions.
This macro can be used to avoid the warning in particular cases.
*/
#define CEDA_AVOID_UNREFERENCED_VARIABLE_WARNING(x) x;

#ifdef _MSC_VER
    /*
    #ifndef _SCL_SECURE_NO_WARNINGS
        // warning C4996: 'std::equal': Function call with parameters that may be unsafe - this call 
        // relies on the caller to check that the passed values are correct. To disable this warning, 
        // use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
        #define _SCL_SECURE_NO_WARNINGS
    #endif
    */

    // Identifier was truncated to 'number' characters in the debug information
    #pragma warning(disable: 4786)  

    // '<' : signed/unsigned mismatch
    #pragma warning(disable: 4018)  

    /*
    // 'this' : used in base member initializer list
    #pragma warning(disable: 4355)

    // struct 'X' needs to have dll-interface to be used by clients of class 'Y'
    #pragma warning(disable:4251)

    // non dll-interface struct 'X' used as base for dll-interface class 'Y'
    #pragma warning(disable:4275)

    // Decorated name length exceeded, name was truncated
    #pragma warning(disable: 4503) 
    */
#endif

namespace ceda
{
    inline bool implies(bool p, bool q) 
    { 
        return !p || q; 
    }
    
    inline bool iff(bool p, bool q)
    {
        return p == q;
    }

    class noncopyable
    {
    public:
        noncopyable() {}
    private:
        noncopyable(const noncopyable&);
        noncopyable& operator=(const noncopyable&);
    };

    cxUtils_API void memswap(void* p1, void* p2, ssize_t count);

} // namespace ceda

#endif // include guard