Mobile API Reference  MicroStrategy 2019
BigDecimal.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : BigDecimal.h
3 // AUTHOR : Xun Feng
4 // CREATION : 2/11/04
5 // Copyright (C) MicroStrategy, Inc. 2001
6 //==============================================================================================
7 #ifndef MDataType_BigDecimal_h
8 #define MDataType_BigDecimal_h
9 
10 #include "PDCHeader/PDCwtypes.h"
11 
13 
14 #include "Base/Base/String.h"
15 #include "Base/Base/ReturnString.h"
17 
18 namespace MDataType
19 {
20  //==============================================================================================
21  // Bigdecimal represents an arbitrary length integer or fixed point number
22  // it is a immutable object except that one can create an empty one using default constructor and
23  // then assign. It can only be assigned once
24  // It's size is IMMUTABLE - you can not make a bug fix which creates new member!!!
25  //==============================================================================================
26 
28  {
29 
30  private:
31  // members
32  Int32 mScale;
33  MBase::Buffer *mBuffer;
34  void * mBigInt; // use void to avoid exposing BigInteger to outside
35 
36  public:
37 
40 
41  BigDecimal(MBase::Buffer *iBuffer = 0);
42 
43  BigDecimal(const char *iStr, MBase::Buffer *iBuffer = 0);
44 #ifndef NO_WCHAR_SUPPORT
45  BigDecimal(const wchar_t* iStr, MBase::Buffer *iBuffer = 0);
46 #endif
47  BigDecimal(int val, MBase::Buffer *iBuffer = 0);
48 
49  BigDecimal(double val, MBase::Buffer *iBuffer = 0);
50 
51  BigDecimal(const BigDecimal& iRight, MBase::Buffer *iBuffer = 0);
52 
53  ~BigDecimal();
54 
55  // comparison
56  bool operator==(const BigDecimal& right) const;
57 
58  BigDecimal& operator=(const BigDecimal& right);
59 
60  bool operator> (const BigDecimal& right) const;
61  bool operator< (const BigDecimal& right) const;
62 
63 
64  // arithmatic calculations
65  ReturnPtr operator+(const BigDecimal& right) const;
66  // Returns a BigDecimal whose value is (this + right), and whose scale is max(this.scale(), right.scale()).
67 
68  ReturnPtr operator-(const BigDecimal& right) const;
69  // Returns a BigDecimal whose value is (this - right), and whose scale is max(this.scale(), right.scale()).
70 
71  ReturnPtr operator*(const BigDecimal& right) const;
72  // Returns a BigDecimal whose value is (this * right), and whose scale is (this.scale() + right.scale()).
73 
74  ReturnPtr operator/(const BigDecimal& right) const;
75  // Returns a BigDecimal whose value is (this / right), and whose scale is this.scale()
76 
77  ReturnPtr Divide(const BigDecimal& right, Int32 req_cale = -1) const;
78  // Returns a BigDecimal whose value is (left / right), and whose scale is req_scale or this.scale() if req_scope is -1
79 #ifndef NO_WCHAR_SUPPORT
80  MBase::ReturnWString ToWString() const;
81 
82  MBase::ReturnWString ToWString(LCID inLocale) const;
83 #endif
85 
86  // Comparison
87  Int32 CompareTo(const BigDecimal& val) const;
88  // Compares this BigDecimal with the specified BigDecimal.
89  // -1 means this is smaller than val, 0 means equal, 1 means greater
90 
91  // property that describes the number
92  Int32 Scale() const;
93  // Returns the scale of this BigDecimal.
94 
95  Int32 Signum() const;
96  // Returns the signum function of this BigDecimal.
97 
98  Int32 Precision() const;
99 #ifndef NO_WCHAR_SUPPORT
100  MBase::ReturnWString MantissaToWString() const;
101  // Returns the string representation of this BigDecimal's mantissa part.
102 #endif
103  bool IsInvalid() const;
104 
105  MBase::ReturnString GetIntegerDigits() const;
106 
107  MBase::ReturnString GetFractionDigits() const;
108 
109  private:
110  void _StrToBigDecimal(const char *iStr);
111 
112  void _CreateInvalidBigDecimal();
113 
114  const char * _FindChr(const char *iStr, const char *iEnd, char ch);
115 
116  bool _CheckDigits(const char* iStr, const char* iEnd, bool & oAllZero, char ch = '\0');
117 
118  bool IsEmpty() const;
119 
120  static BigDecimal * CreateBigDecimal(void *iBigInt, Int32 iScale, MBase::Buffer *iBuffer);
121  };
122 
124 
125 }
126 #endif // MDataType_BigDecimal_h
bool operator<(const ::GUID &irGUID1, const ::GUID &irGUID2)
Definition: Base/Base/GUID.h:156
Definition: ReturnString.h:36
bool operator==(const Allocator< _Ty > &left, const Allocator< _UT > &right)
Definition: Allocator.h:204
MBase::ReturnPtr< BigDecimal > ReturnPtr
Definition: BigDecimal.h:39
Definition: Buffer.h:58
#define DLL_DATATYPE_EXIM
Definition: DataType.h:22
Definition: ReturnString.h:85
Definition: BigDecimal.h:18
Definition: BigDecimal.h:123
DWORD LCID
Definition: PDCwtypes.h:294
#define Int32
Definition: BasicTypes.h:20
Definition: Message.h:32
Definition: BigDecimal.h:27
DLL_BASE_EXIM const char * ToString(MBase::MessageDomain iDomain)
Definition: StrongPtr.h:50
MBase::StrongPtr< BigDecimal > Ptr
Definition: BigDecimal.h:38
Definition: ReturnPtr.h:22