Qore Programming Language  0.9.16
QoreNumberNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreNumberNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2018 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_QORENUMBERNODE_H
33 
34 #define _QORE_QORENUMBERNODE_H
35 
36 class LocalVar;
37 
42 #define QORE_NF_DEFAULT 0
44 #define QORE_NF_SCIENTIFIC (1 << 0)
46 #define QORE_NF_RAW (1 << 1)
48 
49 
52  friend hashdecl qore_number_private;
53 
54 private:
56  DLLLOCAL virtual bool getAsBoolImpl() const;
57 
59  DLLLOCAL virtual int getAsIntImpl() const;
60 
62  DLLLOCAL virtual int64 getAsBigIntImpl() const;
63 
65  DLLLOCAL virtual double getAsFloatImpl() const;
66 
67 protected:
69  hashdecl qore_number_private* priv;
70 
72 
75  DLLEXPORT virtual ~QoreNumberNode();
76 
77  // private
78  DLLLOCAL QoreNumberNode(struct qore_number_private* p);
79 
80 public:
82  DLLEXPORT QoreNumberNode(const QoreValue n);
83 
85 
88  DLLEXPORT QoreNumberNode(double f);
89 
91 
94  DLLEXPORT QoreNumberNode(int64 i);
95 
97 
100  DLLEXPORT QoreNumberNode(const char* str);
101 
103 
107  DLLEXPORT QoreNumberNode(const char* str, unsigned prec);
108 
110  DLLEXPORT QoreNumberNode();
111 
113  DLLEXPORT QoreNumberNode(const QoreNumberNode& old);
114 
116 
121  DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
122 
124 
127  DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
128 
130 
136  DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool& del) const;
137 
139 
143  DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
144 
146 
152  DLLEXPORT virtual int getAsString(QoreString& str, int foff, class ExceptionSink* xsink) const;
153 
155 
161  DLLEXPORT virtual QoreString *getAsString(bool& del, int foff, class ExceptionSink* xsink) const;
162 
164 
167  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
168 
170 
175  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
176 
178 
183  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
184 
186 
189  DLLEXPORT virtual const char* getTypeName() const;
190 
192  DLLEXPORT QoreNumberNode* doPlus(const QoreNumberNode& n) const;
193 
195  DLLEXPORT QoreNumberNode* doMinus(const QoreNumberNode& n) const;
196 
198  DLLEXPORT QoreNumberNode* doMultiply(const QoreNumberNode& n) const;
199 
201  DLLEXPORT QoreNumberNode* doDivideBy(const QoreNumberNode& n, ExceptionSink* xsink) const;
202 
204  DLLEXPORT QoreNumberNode* doDivideBy(double d, ExceptionSink* xsink) const;
205 
207  DLLEXPORT QoreNumberNode* doDivideBy(int64 i, ExceptionSink* xsink) const;
208 
210  DLLEXPORT QoreNumberNode* negate() const;
211 
213  DLLEXPORT bool zero() const;
214 
216  DLLEXPORT int sign() const;
217 
219  DLLEXPORT bool lessThan(const QoreNumberNode& n) const;
220 
222  DLLEXPORT bool lessThan(double n) const;
223 
225  DLLEXPORT bool lessThan(int64 n) const;
226 
228  DLLEXPORT bool lessThanOrEqual(const QoreNumberNode& n) const;
229 
231  DLLEXPORT bool lessThanOrEqual(double n) const;
232 
234  DLLEXPORT bool lessThanOrEqual(int64 n) const;
235 
237  DLLEXPORT bool greaterThan(const QoreNumberNode& n) const;
238 
240  DLLEXPORT bool greaterThan(double n) const;
241 
243  DLLEXPORT bool greaterThan(int64 n) const;
244 
246  DLLEXPORT bool greaterThanOrEqual(const QoreNumberNode& n) const;
247 
249  DLLEXPORT bool greaterThanOrEqual(double n) const;
250 
252  DLLEXPORT bool greaterThanOrEqual(int64 n) const;
253 
255  DLLEXPORT bool equals(const QoreNumberNode& n) const;
256 
258  DLLEXPORT bool equals(double n) const;
259 
261  DLLEXPORT bool equals(int64 n) const;
262 
264  DLLEXPORT QoreNumberNode* numberRefSelf() const;
265 
267 
270  DLLEXPORT void toString(QoreString& str, int fmt = QORE_NF_DEFAULT) const;
271 
273  DLLEXPORT unsigned getPrec() const;
274 
276  DLLEXPORT bool nan() const;
277 
279  DLLEXPORT bool inf() const;
280 
282  DLLEXPORT bool ordinary() const;
283 
285  DLLLOCAL virtual void parseInit(QoreValue& val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&returnTypeInfo);
286 
288  DLLEXPORT static QoreNumberNode* toNumber(const AbstractQoreNode* v);
289 
291  DLLEXPORT static QoreNumberNode* toNumber(const QoreValue v);
292 
294 
297  DLLLOCAL static const char* getStaticTypeName() {
298  return "number";
299  }
300 
302  DLLLOCAL static qore_type_t getStaticTypeCode() {
303  return NT_NUMBER;
304  }
305 
306  static const qore_type_t TYPE = NT_NUMBER;
307 };
308 
311 private:
312  const QoreNumberNode* num;
313  bool del;
314 
315  DLLLOCAL QoreNumberNodeHelper(const QoreNumberNodeHelper&); // not implemented
316  DLLLOCAL QoreNumberNodeHelper& operator=(const QoreNumberNodeHelper&); // not implemented
317  DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
318 
319 public:
321  DLLLOCAL QoreNumberNodeHelper(const QoreValue n);
322 
324  DLLLOCAL ~QoreNumberNodeHelper();
325 
327 
330  DLLLOCAL const QoreNumberNode* operator->() { return num; }
331 
333 
336  DLLLOCAL const QoreNumberNode* operator*() { return num; }
337 
339 
343  DLLEXPORT QoreNumberNode* getReferencedValue();
344 
346  DLLLOCAL bool is_temp() const {
347  return del;
348  }
349 };
350 
351 #endif
NT_NUMBER
const qore_type_t NT_NUMBER
type value for QoreNumberNode
Definition: node_types.h:53
QoreNumberNode::getStaticTypeName
static const DLLLOCAL char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreNumberNode.h:297
QoreNumberNode::greaterThanOrEqual
DLLEXPORT bool greaterThanOrEqual(const QoreNumberNode &n) const
returns true if the current object is greater than or equal to the argument
QoreNumberNode::getAsString
virtual DLLEXPORT int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const
concatenate the string representation of the number value to an existing QoreString
QoreNumberNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
QoreNumberNodeHelper::is_temp
DLLLOCAL bool is_temp() const
returns true if the referenced being managed is temporary
Definition: QoreNumberNode.h:346
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
QoreNumberNode::doMinus
DLLEXPORT QoreNumberNode * doMinus(const QoreNumberNode &n) const
subtract the argument from this value and return the result
QoreNumberNode::getPrec
DLLEXPORT unsigned getPrec() const
returns the precision of the number
QoreNumberNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the number value converted to a string and sets del to true
QoreNumberNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality with possible type conversion (soft compare)
QoreNumberNode::priv
hashdecl qore_number_private * priv
the private implementation of the type
Definition: QoreNumberNode.h:69
QoreNumberNodeHelper::operator->
const DLLLOCAL QoreNumberNode * operator->()
returns the object being managed
Definition: QoreNumberNode.h:330
QoreNumberNodeHelper::~QoreNumberNodeHelper
DLLLOCAL ~QoreNumberNodeHelper()
destroys the object and dereferences the pointer being managed if it was a temporary object
QoreNumberNode
Qore's arbitrary-precision number value type, dynamically-allocated only, reference counted.
Definition: QoreNumberNode.h:51
int64
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
QoreNumberNode::toNumber
static DLLEXPORT QoreNumberNode * toNumber(const AbstractQoreNode *v)
returns the representation of the value as a number if possible (otherwise returns 0),...
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreNumberNode::lessThan
DLLEXPORT bool lessThan(const QoreNumberNode &n) const
returns true if the current object is less than the argument
QoreNumberNodeHelper
manages conversions of a QoreValue to a QoreNumberNode
Definition: QoreNumberNode.h:310
QoreNumberNodeHelper::getReferencedValue
DLLEXPORT QoreNumberNode * getReferencedValue()
returns a referenced value and leaves the current object empty; the caller will own the reference
QoreNumberNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreNumberNode.h:302
QoreNumberNode::parseInit
virtual DLLLOCAL void parseInit(QoreValue &val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&returnTypeInfo)
returns the type information
QoreNumberNode::equals
DLLEXPORT bool equals(const QoreNumberNode &n) const
returns true if the current object is equal to the argument
QoreNumberNode::getTypeName
virtual const DLLEXPORT char * getTypeName() const
returns the type name as a c string
QoreNumberNode::QoreNumberNode
DLLEXPORT QoreNumberNode()
creates a new numbering-point value and assigns it to 0
QoreNumberNode::lessThanOrEqual
DLLEXPORT bool lessThanOrEqual(const QoreNumberNode &n) const
returns true if the current object is less than or equal to the argument
QoreNumberNode::getDateTimeRepresentation
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this value and sets del to true
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:366
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreNumberNode::sign
DLLEXPORT int sign() const
returns -1 if the number is negative, 0 if zero, or 1 if the number is positive
QoreNumberNode::doDivideBy
DLLEXPORT QoreNumberNode * doDivideBy(const QoreNumberNode &n, ExceptionSink *xsink) const
divide this value by the argument return the result (can throw a division-by-zero exception)
QoreNumberNode::zero
DLLEXPORT bool zero() const
returns true if the number is zero
QoreNumberNode::~QoreNumberNode
virtual DLLEXPORT ~QoreNumberNode()
the destructor is protected because it should not be called directly
QoreNumberNode::toString
DLLEXPORT void toString(QoreString &str, int fmt=QORE_NF_DEFAULT) const
concatenates the string value corresponding to the number to the string given
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
QoreNumberNode::inf
DLLEXPORT bool inf() const
returns true if the number is +/-inf
QoreNumberNode::ordinary
DLLEXPORT bool ordinary() const
returns true if the number is an ordinary number (neither NaN nor an infinity)
QoreNumberNode::doMultiply
DLLEXPORT QoreNumberNode * doMultiply(const QoreNumberNode &n) const
multiply the argument to this value and return the result
QoreNumberNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality without type conversions (hard compare)
QoreNumberNode::negate
DLLEXPORT QoreNumberNode * negate() const
returns the negative of the current object (this)
QoreNumberNodeHelper::operator*
const DLLLOCAL QoreNumberNode * operator*()
returns the object being managed
Definition: QoreNumberNode.h:336
QoreNumberNode::numberRefSelf
DLLEXPORT QoreNumberNode * numberRefSelf() const
returns a pointer to this with the reference count incremented
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
QoreNumberNode::nan
DLLEXPORT bool nan() const
returns true if the number is NaN
QoreNumberNode::doPlus
DLLEXPORT QoreNumberNode * doPlus(const QoreNumberNode &n) const
add the argument to this value and return the result
QoreNumberNode::greaterThan
DLLEXPORT bool greaterThan(const QoreNumberNode &n) const
returns true if the current object is greater than the argument