⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 longlong.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/longlong.h
// Purpose:     declaration of wxLongLong class - best implementation of a 64
//              bit integer for the current platform.
// Author:      Jeffrey C. Ollie <jeff@ollie.clive.ia.us>, Vadim Zeitlin
// Modified by:
// Created:     10.02.99
// RCS-ID:      $Id: longlong.h,v 1.1 2005/03/16 06:49:18 kehc Exp $
// Copyright:   (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence:     wxWindows license
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_LONGLONG_H
#define _WX_LONGLONG_H

#if defined(__GNUG__) && !defined(__APPLE__)
    #pragma interface "longlong.h"
#endif

#include "wx/defs.h"
#include "wx/string.h"

#include <limits.h>     // for LONG_MAX

// define this to compile wxLongLongWx in "test" mode: the results of all
// calculations will be compared with the real results taken from
// wxLongLongNative -- this is extremely useful to find the bugs in
// wxLongLongWx class!

// #define wxLONGLONG_TEST_MODE

#ifdef wxLONGLONG_TEST_MODE
    #define wxUSE_LONGLONG_WX 1
    #define wxUSE_LONGLONG_NATIVE 1
#endif // wxLONGLONG_TEST_MODE

// ----------------------------------------------------------------------------
// decide upon which class we will use
// ----------------------------------------------------------------------------

// to avoid compilation problems on 64bit machines with ambiguous method calls
// we will need to define this
#undef wxLongLongIsLong

// NB: we #define and not typedef wxLongLong_t because we want to be able to
//     use 'unsigned wxLongLong_t' as well and because we use "#ifdef
//     wxLongLong_t" below

// first check for generic cases which are long on 64bit machine and "long
// long", then check for specific compilers
#if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
    #define wxLongLong_t long
    #define wxLongLongSuffix l
    #define wxLongLongFmtSpec _T("l")
    #define wxLongLongIsLong
#elif (defined(__VISUALC__) && defined(__WIN32__)) || defined( __VMS__ )
    #define wxLongLong_t __int64
    #define wxLongLongSuffix i64
    #define wxLongLongFmtSpec _T("I64")
#elif defined(__BORLANDC__) && defined(__WIN32__) && (__BORLANDC__ >= 0x520)
    #define wxLongLong_t __int64
    #define wxLongLongSuffix i64
    #define wxLongLongFmtSpec _T("I64")
#elif (defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG >= 8)  || \
        defined(__MINGW32__) || \
        defined(__CYGWIN__) || \
        defined(__WXMICROWIN__) || \
        (defined(__DJGPP__) && __DJGPP__ >= 2)
    #define wxLongLong_t long long
    #define wxLongLongSuffix ll
    #define wxLongLongFmtSpec _T("ll")
#elif defined(__MWERKS__)
    #if __option(longlong)
        #define wxLongLong_t long long
        #define wxLongLongSuffix ll
        #define wxLongLongFmtSpec _T("ll")
    #else
        #error "The 64 bit integer support in CodeWarrior has been disabled."
        #error "See the documentation on the 'longlong' pragma."
    #endif
#elif defined(__VISAGECPP__) && __IBMCPP__ >= 400
    #define wxLongLong_t long long
#else // no native long long type
    // both warning and pragma warning are not portable, but at least an
    // unknown pragma should never be an error -- except that, actually, some
    // broken compilers don't like it, so we have to disable it in this case
    // <sigh>
#if !(defined(__WATCOMC__) || defined(__VISAGECPP__))
    #pragma warning "Your compiler does not appear to support 64 bit "\
                    "integers, using emulation class instead.\n" \
                    "Please report your compiler version to " \
                    "wx-dev@lists.wxwindows.org!"
#endif

    #define wxUSE_LONGLONG_WX 1
#endif // compiler

// this macro allows to definea 64 bit constant in a portable way
#define wxMakeLongLong(x, s) x ## s
#define wxMakeLongLong2(x, s) wxMakeLongLong(x, s)
#define wxLL(x) wxMakeLongLong2(x, wxLongLongSuffix)

// the user may predefine wxUSE_LONGLONG_NATIVE and/or wxUSE_LONGLONG_NATIVE
// to disable automatic testing (useful for the test program which defines
// both classes) but by default we only use one class
#if (defined(wxUSE_LONGLONG_WX) && wxUSE_LONGLONG_WX) || !defined(wxLongLong_t)
    // don't use both classes unless wxUSE_LONGLONG_NATIVE was explicitly set:
    // this is useful in test programs and only there
    #ifndef wxUSE_LONGLONG_NATIVE
        #define wxUSE_LONGLONG_NATIVE 0
    #endif

    class WXDLLEXPORT wxLongLongWx;
    class WXDLLEXPORT wxULongLongWx;
#if defined(__VISUALC__) && !defined(__WIN32__)
    #define wxLongLong wxLongLongWx
    #define wxULongLong wxULongLongWx
#else
    typedef wxLongLongWx wxLongLong;
    typedef wxULongLongWx wxULongLong;
#endif

#else
    // if nothing is defined, use native implementation by default, of course
    #ifndef wxUSE_LONGLONG_NATIVE
        #define wxUSE_LONGLONG_NATIVE 1
    #endif
#endif

#ifndef wxUSE_LONGLONG_WX
    #define wxUSE_LONGLONG_WX 0
    class WXDLLEXPORT wxLongLongNative;
    class WXDLLEXPORT wxULongLongNative;
    typedef wxLongLongNative wxLongLong;
    typedef wxULongLongNative wxULongLong;
#endif

// NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
//     typedef wxLongLong as it wants, we don't do it

// ----------------------------------------------------------------------------
// choose the appropriate class
// ----------------------------------------------------------------------------

// we use iostream for wxLongLong output
#include "wx/ioswrap.h"

#if wxUSE_LONGLONG_NATIVE

class WXDLLEXPORT wxLongLongNative
{
public:
    // ctors
        // default ctor initializes to 0
    wxLongLongNative() : m_ll(0) { }
        // from long long
    wxLongLongNative(wxLongLong_t ll) : m_ll(ll) { }
        // from 2 longs
    wxLongLongNative(long hi, unsigned long lo) : m_ll(0)
    {
        // assign first to avoid precision loss!
        m_ll = ((wxLongLong_t) hi) << 32;
        m_ll |= (wxLongLong_t) lo;
    }

    // default copy ctor is ok

    // no dtor

    // assignment operators
        // from native 64 bit integer
    wxLongLongNative& operator=(wxLongLong_t ll)
        { m_ll = ll; return *this; }

        // from double: this one has an explicit name because otherwise we
        // would have ambiguity with "ll = int" and also because we don't want
        // to have implicit conversions between doubles and wxLongLongs
    wxLongLongNative& Assign(double d)
        { m_ll = (wxLongLong_t)d; return *this; }

    // assignment operators from wxLongLongNative is ok

    // accessors
        // get high part
    long GetHi() const
        { return (long)(m_ll >> 32); }
        // get low part
    unsigned long GetLo() const
        { return (unsigned long)m_ll; }

        // get absolute value
    wxLongLongNative Abs() const { return wxLongLongNative(*this).Abs(); }
    wxLongLongNative& Abs() { if ( m_ll < 0 ) m_ll = -m_ll; return *this; }

        // convert to native long long
    wxLongLong_t GetValue() const { return m_ll; }

        // convert to long with range checking in the debug mode (only!)
    long ToLong() const
    {
        wxASSERT_MSG( (m_ll >= LONG_MIN) && (m_ll <= LONG_MAX),
                      _T("wxLongLong to long conversion loss of precision") );

        return (long)m_ll;
    }

    // don't provide implicit conversion to wxLongLong_t or we will have an
    // ambiguity for all arithmetic operations
    //operator wxLongLong_t() const { return m_ll; }

    // operations
        // addition
    wxLongLongNative operator+(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll + ll.m_ll); }
    wxLongLongNative& operator+=(const wxLongLongNative& ll)
        { m_ll += ll.m_ll; return *this; }

    wxLongLongNative operator+(const wxLongLong_t ll) const
        { return wxLongLongNative(m_ll + ll); }
    wxLongLongNative& operator+=(const wxLongLong_t ll)
        { m_ll += ll; return *this; }

        // pre increment
    wxLongLongNative& operator++()
        { m_ll++; return *this; }

        // post increment
    wxLongLongNative operator++(int)
        { wxLongLongNative value(*this); m_ll++; return value; }

        // negation operator
    wxLongLongNative operator-() const
        { return wxLongLongNative(-m_ll); }
    wxLongLongNative& Negate() { m_ll = -m_ll; return *this; }

        // subtraction
    wxLongLongNative operator-(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll - ll.m_ll); }
    wxLongLongNative& operator-=(const wxLongLongNative& ll)
        { m_ll -= ll.m_ll; return *this; }

    wxLongLongNative operator-(const wxLongLong_t ll) const
        { return wxLongLongNative(m_ll - ll); }
    wxLongLongNative& operator-=(const wxLongLong_t ll)
        { m_ll -= ll; return *this; }

        // pre decrement
    wxLongLongNative& operator--()
        { m_ll--; return *this; }

        // post decrement
    wxLongLongNative operator--(int)
        { wxLongLongNative value(*this); m_ll--; return value; }

    // shifts
        // left shift
    wxLongLongNative operator<<(int shift) const
        { return wxLongLongNative(m_ll << shift);; }
    wxLongLongNative& operator<<=(int shift)
        { m_ll <<= shift; return *this; }

        // right shift
    wxLongLongNative operator>>(int shift) const
        { return wxLongLongNative(m_ll >> shift);; }
    wxLongLongNative& operator>>=(int shift)
        { m_ll >>= shift; return *this; }

    // bitwise operators
    wxLongLongNative operator&(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll & ll.m_ll); }
    wxLongLongNative& operator&=(const wxLongLongNative& ll)
        { m_ll &= ll.m_ll; return *this; }

    wxLongLongNative operator|(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll | ll.m_ll); }
    wxLongLongNative& operator|=(const wxLongLongNative& ll)
        { m_ll |= ll.m_ll; return *this; }

    wxLongLongNative operator^(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll ^ ll.m_ll); }
    wxLongLongNative& operator^=(const wxLongLongNative& ll)
        { m_ll ^= ll.m_ll; return *this; }

    // multiplication/division
    wxLongLongNative operator*(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll * ll.m_ll); }
    wxLongLongNative operator*(long l) const
        { return wxLongLongNative(m_ll * l); }
    wxLongLongNative& operator*=(const wxLongLongNative& ll)
        { m_ll *= ll.m_ll; return *this; }
    wxLongLongNative& operator*=(long l)
        { m_ll *= l; return *this; }

    wxLongLongNative operator/(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll / ll.m_ll); }
    wxLongLongNative operator/(long l) const
        { return wxLongLongNative(m_ll / l); }
    wxLongLongNative& operator/=(const wxLongLongNative& ll)
        { m_ll /= ll.m_ll; return *this; }
    wxLongLongNative& operator/=(long l)
        { m_ll /= l; return *this; }

    wxLongLongNative operator%(const wxLongLongNative& ll) const
        { return wxLongLongNative(m_ll % ll.m_ll); }
    wxLongLongNative operator%(long l) const
        { return wxLongLongNative(m_ll % l); }

    // comparison
    bool operator==(const wxLongLongNative& ll) const
        { return m_ll == ll.m_ll; }
    bool operator==(long l) const
        { return m_ll == l; }
    bool operator!=(const wxLongLongNative& ll) const
        { return m_ll != ll.m_ll; }
    bool operator!=(long l) const

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -