Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Value.h File Reference


Detailed Description

Defines the mcValue classes.

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.


Define Documentation

#define GMP2WX  )     (wxString(x, wxConvUTF8))
 

Definition at line 161 of file Value.h.

Referenced by mcRealValue::GetBaseStr(), and mcIntegerValue::GetStr().

#define mcVALUE_DEFAULTPRECISION   30
 

The default precision for mcValue-derived classes.

Definition at line 150 of file Value.h.

Referenced by mcRealValue::GetStr().

#define mcVALUE_DEFINE_ALLOPERATORS x,
structname,
 ) 
 

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)
Defines all the operators for a mcValue-derived class.

Definition at line 377 of file Value.h.

#define mcVALUE_DEFINE_ARITHMETIC_OPERATORS rettype,
x,
y,
fncprefix,
z,
 ) 
 

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;}
Defines and implements the +,-,*,/ operators.

Definition at line 353 of file Value.h.

#define mcVALUE_DEFINE_CONSTRUCTORS x,
 ) 
 

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(); }
Defines some standard constructor + the virtual destructor.

Definition at line 406 of file Value.h.

#define mcVALUE_DEFINE_COW x,
 ) 
 

Value:

Put this macro at the beginning of the class declaration.

Definition at line 398 of file Value.h.

#define mcVALUE_DEFINE_DOUBLEOPERATORS x,
structname,
 ) 
 

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)

Definition at line 391 of file Value.h.

#define mcVALUE_DEFINE_FLAGS_EQUAL_OPERATORS y,
fnc,
 ) 
 

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());}

Definition at line 329 of file Value.h.

#define mcVALUE_DEFINE_FLAGSCOMPARISON_OPERATORS y,
fnc,
 ) 
 

Value:

Definition at line 348 of file Value.h.

#define mcVALUE_DEFINE_GETSET x,
fncprefix   ) 
 

Value:

Just a short version for.

Definition at line 324 of file Value.h.

#define mcVALUE_DEFINE_GETTERS x,
fncprefix   )     long GetLong() const { return fncprefix##_get_ui(cMP()); }
 

Defines some getters common to all mcValue-derived classes.

Definition at line 313 of file Value.h.

#define mcVALUE_DEFINE_GMP_STRUCTWRAPPER name,
base   ) 
 

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); }     \
 };
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).

Definition at line 203 of file Value.h.

#define mcVALUE_DEFINE_INTERNAL_GETTERS  ) 
 

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;              \
 }
Defines and implements the non-const and the const getters of the internal GMP structure.

Used to implement Copy-On-Write (COW).

Definition at line 278 of file Value.h.

#define mcVALUE_DEFINE_INTERNALS x,
fncprefix   ) 
 

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; }
Implements InternalInit() and InternalDestroy().

These two functions are used to create and init the structure wrapped by this class.

Definition at line 233 of file Value.h.

#define mcVALUE_DEFINE_MISCELLANEOUS rettype,
fncprefix   ) 
 

Value:

rettype ChangeSign()            \
 { rettype ret; fncprefix##_neg(ret.MP(), cMP()); return ret; }
Defines some miscellaneous function: - ChangeSign() changes the sign of *this value: this function is sometimes useful when the "-" unary operator is ambiguos.

Definition at line 319 of file Value.h.

#define mcVALUE_DEFINE_NOFLAGS_EQUAL_OPERATORS y,
fnc,
 ) 
 

Value:

bool operator==(y m) const   {return (fnc(cMP(), z) == 0);}  \
 bool operator!=(y m) const   {return (fnc(cMP(), z) != 0);}

Definition at line 333 of file Value.h.

#define mcVALUE_DEFINE_NOFLAGS_GTLT_OPERATORS y,
fnc,
 ) 
 

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);}
Defines and implements the comparison operators.

Definition at line 338 of file Value.h.

#define mcVALUE_DEFINE_NOFLAGSCOMPARISON_OPERATORS y,
fnc,
 ) 
 

Value:

Definition at line 344 of file Value.h.

#define mcVALUE_DEFINE_REFCOUNT x,
 ) 
 

Defines and implements the Ref() and Unref() functions used for reference counting.

Definition at line 243 of file Value.h.

 
#define mcVALUE_DEFINE_SETGET_FLAGS  ) 
 

Value:

int GetFlags() const   { return (int)cMP()->GetFlags(); } \
 void SetFlags(int n)   { MP()->SetFlags((wxInt16)n); }  \
 bool hasSameFlags(int n) const { return GetFlags() == n; }
Defines the flags set/get functions.

Definition at line 301 of file Value.h.

#define mcVALUE_DEFINE_SETTERS x,
fncprefix   ) 
 

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); }
Defines some setters common to all mcValue-derived classes.

Definition at line 307 of file Value.h.

#define mcVALUE_DEFINE_UNARY_OPERATORS rettype,
x,
fncprefix   ) 
 

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;}
Defines and implements unary operators.

Definition at line 364 of file Value.h.

#define mcVALUE_MASK   0xFFFF0000
 

The bit mask used to divide flags from reference count in a GMP struct wrapper.

Definition at line 194 of file Value.h.

#define mcVALUE_NAN_FLAG   0x000F
 

The value is a NAN (Not a Number).

Definition at line 196 of file Value.h.

Referenced by mcValue::Init(), and mcValue::isNAN().

#define mcVALUE_NEGINF_FLAG   0x0F00
 

The value is -INF.

Definition at line 198 of file Value.h.

Referenced by mcValue::Init(), and mcValue::isNegInf().

#define mcVALUE_POSINF_FLAG   0x00F0
 

The value is +INF.

Definition at line 197 of file Value.h.

Referenced by mcValue::Init(), and mcValue::isPosInf().

#define mcVALUE_SMARTSTR_THRESHOLD   10
 

The default threshold for mcValue::GetSmartStr.

Definition at line 153 of file Value.h.

#define WX2GMP  )     (wxString(x).mb_str(wxConvUTF8))
 

Definition at line 158 of file Value.h.

Referenced by mcRationalValue::SetStr().


Function Documentation

class class class class void* mcGMPAlloc size_t  n  ) 
 

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().

void mcGMPFree void *  ,
size_t 
 

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().

void* mcGMPRealloc void *  p,
size_t  oldsz,
size_t  newsz
 

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().

mcVALUE_DEFINE_GMP_STRUCTWRAPPER mcMPZ  ,
__mpz_struct 
 

mcVALUE_DEFINE_GMP_STRUCTWRAPPER mcMPQ  ,
__mpq_struct 
 

mcVALUE_DEFINE_GMP_STRUCTWRAPPER mcMPF  ,
__mpf_struct 
 



Documentation generated with Doxygen on Sun Feb 6 17:12:16 2005
Visit MathStudio home page for more info

[ Top ]