See Value.cpp for more info.
Definition in file Value.h.
#include "mc/Setup.h"
#include <math.h>
#include <gmp.h>
Include dependency graph for Value.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
The GMP/MPFR wrapped structures. | |
The structures used by mcValue-derived classes to implement COW. | |
#define | mcVALUE_MASK 0xFFFF0000 |
The bit mask used to divide flags from reference count in a GMP struct wrapper. | |
#define | mcVALUE_NAN_FLAG 0x000F |
The value is a NAN (Not a Number). | |
#define | mcVALUE_POSINF_FLAG 0x00F0 |
The value is +INF. | |
#define | mcVALUE_NEGINF_FLAG 0x0F00 |
The value is -INF. | |
#define | mcVALUE_DEFINE_GMP_STRUCTWRAPPER(name, base) |
Defines a structure named NAME derived from BASE which have an additional field required to store both the reference count (in the lower 16 bits) and the flags (in the upper 16 bits). | |
mcVALUE_DEFINE_GMP_STRUCTWRAPPER (mcMPF, __mpf_struct) | |
mcVALUE_DEFINE_GMP_STRUCTWRAPPER (mcMPQ, __mpq_struct) | |
mcVALUE_DEFINE_GMP_STRUCTWRAPPER (mcMPZ, __mpz_struct) | |
The mcValue macros | |
The macros used to define & implement those parts of mcValue-derived classes that are redundant code. | |
#define | mcVALUE_DEFINE_INTERNALS(x, fncprefix) |
Implements InternalInit() and InternalDestroy(). | |
#define | mcVALUE_DEFINE_REFCOUNT(x, y) |
Defines and implements the Ref() and Unref() functions used for reference counting. | |
#define | mcVALUE_DEFINE_INTERNAL_GETTERS(x) |
Defines and implements the non-const and the const getters of the internal GMP structure. | |
#define | mcVALUE_DEFINE_SETGET_FLAGS() |
Defines the flags set/get functions. | |
#define | mcVALUE_DEFINE_SETTERS(x, fncprefix) |
Defines some setters common to all mcValue-derived classes. | |
#define | mcVALUE_DEFINE_GETTERS(x, fncprefix) long GetLong() const { return fncprefix##_get_ui(cMP()); } |
Defines some getters common to all mcValue-derived classes. | |
#define | mcVALUE_DEFINE_MISCELLANEOUS(rettype, fncprefix) |
Defines some miscellaneous function: - ChangeSign() changes the sign of *this value: this function is sometimes useful when the "-" unary operator is ambiguos. | |
#define | mcVALUE_DEFINE_GETSET(x, fncprefix) |
Just a short version for. | |
#define | mcVALUE_DEFINE_FLAGS_EQUAL_OPERATORS(y, fnc, z) |
#define | mcVALUE_DEFINE_NOFLAGS_EQUAL_OPERATORS(y, fnc, z) |
#define | mcVALUE_DEFINE_NOFLAGS_GTLT_OPERATORS(y, fnc, z) |
Defines and implements the comparison operators. | |
#define | mcVALUE_DEFINE_NOFLAGSCOMPARISON_OPERATORS(y, fnc, z) |
#define | mcVALUE_DEFINE_FLAGSCOMPARISON_OPERATORS(y, fnc, z) |
#define | mcVALUE_DEFINE_ARITHMETIC_OPERATORS(rettype, x, y, fncprefix, z, w) |
Defines and implements the +,-,*,/ operators. | |
#define | mcVALUE_DEFINE_UNARY_OPERATORS(rettype, x, fncprefix) |
Defines and implements unary operators. | |
#define | mcVALUE_DEFINE_ALLOPERATORS(x, structname, y) |
Defines all the operators for a mcValue-derived class. | |
#define | mcVALUE_DEFINE_DOUBLEOPERATORS(x, structname, y) |
#define | mcVALUE_DEFINE_COW(x, y) |
Put this macro at the beginning of the class declaration. | |
#define | mcVALUE_DEFINE_CONSTRUCTORS(x, y) |
Defines some standard constructor + the virtual destructor. | |
Defines | |
#define | mcVALUE_DEFAULTPRECISION 30 |
The default precision for mcValue-derived classes. | |
#define | mcVALUE_SMARTSTR_THRESHOLD 10 |
The default threshold for mcValue::GetSmartStr. | |
#define | WX2GMP(x) (wxString(x).mb_str(wxConvUTF8)) |
#define | GMP2WX(x) (wxString(x, wxConvUTF8)) |
Functions | |
class class class void * | mcGMPAlloc (size_t n) |
Allocates n bytes and returns a pointer to the starting address of the allocated memory. | |
void * | mcGMPRealloc (void *p, size_t oldsz, size_t newsz) |
Reallocates the oldsz bytes pointed by p returning an address to newsz allocated bytes. | |
void | mcGMPFree (void *, size_t) |
Frees the given pointer of the given size. |
|
Definition at line 161 of file Value.h. Referenced by mcRealValue::GetBaseStr(), and mcIntegerValue::GetStr(). |
|
The default precision for mcValue-derived classes.
Definition at line 150 of file Value.h. Referenced by mcRealValue::GetStr(). |
|
Value: mcVALUE_DEFINE_UNARY_OPERATORS(x, structname, y); \ \ mcVALUE_DEFINE_ARITHMETIC_OPERATORS(x, const x &, const x &, y, a.cMP(), b.cMP()); \ mcVALUE_DEFINE_ARITHMETIC_OPERATORS(x, const x &, long, y, a.cMP(), x(b).cMP()); \ mcVALUE_DEFINE_ARITHMETIC_OPERATORS(x, const x &, int, y, a.cMP(), x(b).cMP()); \ mcVALUE_DEFINE_ARITHMETIC_OPERATORS(x, long, const x &, y, x(a).cMP(), b.cMP()); \ mcVALUE_DEFINE_ARITHMETIC_OPERATORS(x, int, const x &, y, x(a).cMP(), b.cMP()); \ \ mcVALUE_DEFINE_FLAGSCOMPARISON_OPERATORS(const x &, __g##y##_cmp, m.cMP()); \ mcVALUE_DEFINE_NOFLAGSCOMPARISON_OPERATORS(long, __g##y##_cmp_si, m); \ mcVALUE_DEFINE_NOFLAGSCOMPARISON_OPERATORS(int, __g##y##_cmp_si, (long)m); \ mcVALUE_DEFINE_MISCELLANEOUS(x, y)
|
|
Value: friend rettype operator+(x a, y b) \ {rettype ret; fncprefix##_add(ret.MP(), z, w); return ret;} \ friend rettype operator-(x a, y b) \ {rettype ret; fncprefix##_sub(ret.MP(), z, w); return ret;} \ friend rettype operator*(x a, y b) \ {rettype ret; fncprefix##_mul(ret.MP(), z, w); return ret;} \ friend rettype operator/(x a, y b) \ {rettype ret; fncprefix##_div(ret.MP(), z, w); return ret;}
|
|
Value: x() { InternalInit(); } \ x(long n) { InternalInit(); SetLong(n); } \ x(int n) { InternalInit(); SetLong(n); } \ x(const wxString &str) { InternalInit(); SetStr(str); } \ x(y *m) { mp=m; Ref(mp); } \ x(const x &m) { mp=m.mp; Ref(mp); } \ virtual ~x() { Unref(); }
|
|
Value: protected: \ mcVALUE_DEFINE_INTERNALS(x, y); \ mcVALUE_DEFINE_REFCOUNT(x, y); \ public: \ mcVALUE_DEFINE_INTERNAL_GETTERS(x)
|
|
Value: mcVALUE_DEFINE_ARITHMETIC_OPERATORS(x, const x &, double, y, a.cMP(), x(b).cMP()); \ mcVALUE_DEFINE_ARITHMETIC_OPERATORS(x, double, const x &, y, x(a).cMP(), b.cMP()); \ mcVALUE_DEFINE_NOFLAGSCOMPARISON_OPERATORS(double, __g##y##_cmp_d, m) |
|
Value: bool operator==(y m) const {return (fnc(cMP(), z) == 0) && hasSameFlags(m.GetFlags());} \ bool operator!=(y m) const {return (fnc(cMP(), z) != 0) || !hasSameFlags(m.GetFlags());} |
|
Value: mcVALUE_DEFINE_NOFLAGS_GTLT_OPERATORS(y, fnc, z) \ mcVALUE_DEFINE_FLAGS_EQUAL_OPERATORS(y, fnc, z) |
|
Value: mcVALUE_DEFINE_SETGET_FLAGS() \ mcVALUE_DEFINE_GETTERS(x, fncprefix) \ mcVALUE_DEFINE_SETTERS(x, fncprefix)
|
|
Defines some getters common to all mcValue-derived classes.
|
|
Value: struct name : base { \ wxUint32 flags; \ \ void SetRefCount(wxUint16 n) \ { flags = (n & ~mcVALUE_MASK) | (GetFlags()<<16); } \ wxUint16 GetRefCount() const \ { return (wxUint16)(flags & ~mcVALUE_MASK); } \ void SetFlags(wxUint16 n) \ { flags = (((int)n) << 16) | GetRefCount(); } \ wxUint16 GetFlags() const \ { return (wxUint16)(flags >> 16); } \ };
|
|
Value: \ x *MP() { \ mcASSERT(mp->GetRefCount() > 0, \ wxT("This object cannot exist")); \ if (mp->GetRefCount() == 1) \ return mp; \ \ /* make a private instance copying the shared object */ \ x *old = mp; \ Unref(); \ InternalInit(); \ CopyMP(old); \ return mp; \ } \ \ \ \ const x *cMP() const { \ return mp; \ } Used to implement Copy-On-Write (COW). |
|
Value: void InternalInit(int flags = 0) { \ mp = new x; fncprefix##_init(mp); \ mp->SetRefCount((wxUint16)1); \ mp->SetFlags((wxInt16)flags); } \ void InternalDestroy() \ { fncprefix##_clear(mp); delete mp; } These two functions are used to create and init the structure wrapped by this class. |
|
Value: rettype ChangeSign() \
{ rettype ret; fncprefix##_neg(ret.MP(), cMP()); return ret; }
|
|
Value: bool operator==(y m) const {return (fnc(cMP(), z) == 0);} \ bool operator!=(y m) const {return (fnc(cMP(), z) != 0);} |
|
Value: bool operator<=(y m) const {return (fnc(cMP(), z) <= 0);} \ bool operator>=(y m) const {return (fnc(cMP(), z) >= 0);} \ bool operator<(y m) const {return (fnc(cMP(), z) < 0);} \ bool operator>(y m) const {return (fnc(cMP(), z) > 0);}
|
|
Value: mcVALUE_DEFINE_NOFLAGS_GTLT_OPERATORS(y, fnc, z) \ mcVALUE_DEFINE_NOFLAGS_EQUAL_OPERATORS(y, fnc, z) |
|
Defines and implements the Ref() and Unref() functions used for reference counting.
|
|
Value: int GetFlags() const { return (int)cMP()->GetFlags(); } \ void SetFlags(int n) { MP()->SetFlags((wxInt16)n); } \ bool hasSameFlags(int n) const { return GetFlags() == n; }
|
|
Value: void SetLong(long n) { fncprefix##_set_si(MP(), n); } \ void SetStr(const wxString &str, int base = 10) \ { fncprefix##_set_str(MP(), WX2GMP(str), base); }
|
|
Value: rettype &operator=(const rettype &m) { Unref(); mp=m.mp; Ref(mp); return *this;} \ rettype &operator=(x &m) { mp=&m; Ref(mp); return *this;} \ rettype &operator=(const wxString &str) { SetStr(str); return *this;} \ rettype &operator=(int n) { SetInt(n); return *this;} \ rettype operator++() { fncprefix##_add_ui(MP(), cMP(), 1); return *this;} \ rettype operator--() { fncprefix##_sub_ui(MP(), cMP(), 1); return *this;} \ rettype &operator+=(const rettype &m) {*this = *this+m;return *this;} \ rettype &operator-=(const rettype &m) {*this = *this-m;return *this;} \ rettype &operator*=(const rettype &m) {*this = *this*m;return *this;} \ rettype &operator/=(const rettype &m) {*this = *this/m;return *this;}
|
|
The bit mask used to divide flags from reference count in a GMP struct wrapper.
|
|
The value is a NAN (Not a Number).
Definition at line 196 of file Value.h. Referenced by mcValue::Init(), and mcValue::isNAN(). |
|
The value is -INF.
Definition at line 198 of file Value.h. Referenced by mcValue::Init(), and mcValue::isNegInf(). |
|
The value is +INF.
Definition at line 197 of file Value.h. Referenced by mcValue::Init(), and mcValue::isPosInf(). |
|
The default threshold for mcValue::GetSmartStr.
|
|
Definition at line 158 of file Value.h. Referenced by mcRationalValue::SetStr(). |
|
Allocates n bytes and returns a pointer to the starting address of the allocated memory. Uses the NEW operator. Used by MathCore to enable GMP to use new and delete C++ operators. Definition at line 76 of file Value.cpp. Referenced by mcValue::Init(), and mcGMPRealloc(). |
|
Frees the given pointer of the given size. Uses the DELETE [] operator. Used by MathCore to enable GMP to use new and delete C++ operators. Definition at line 77 of file Value.cpp. Referenced by mcValue::Init(), and mcGMPRealloc(). |
|
Reallocates the oldsz bytes pointed by p returning an address to newsz allocated bytes. Uses NEW and DELETE []. Used by MathCore to enable GMP to use new and delete C++ operators. Definition at line 79 of file Value.cpp. References mcGMPAlloc(), mcGMPFree(), and mcMIN. Referenced by mcValue::Init(). |
|
|
|
|
|
|
[ Top ] |