| Qore Programming Language - C/C++ Library 1.0.8

QoreNumberNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreNumberNode.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2021 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
51 class QoreNumberNode : public SimpleValueQoreNode {
52 friend struct 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 struct 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 int parseInit(QoreValue& val, QoreParseContext& parse_context);
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
310 class QoreNumberNodeHelper {
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
QoreNumberNode
Qore&#39;s arbitrary-precision number value type, dynamically-allocated only, reference counted...
Definition: QoreNumberNode.h:51
QoreNumberNode::nan
DLLEXPORT bool nan() const
returns true if the number is NaN
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::getPrec
DLLEXPORT unsigned getPrec() const
returns the precision of the number
QoreNumberNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
QoreNumberNode::toNumber
static DLLEXPORT QoreNumberNode * toNumber(const AbstractQoreNode *v)
returns the representation of the value as a number if possible (otherwise returns 0)...
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
QoreNumberNodeHelper::is_temp
DLLLOCAL bool is_temp() const
returns true if the referenced being managed is temporary
Definition: QoreNumberNode.h:346
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::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
QoreNumberNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the number value converted to a string and sets del to true
QoreNumberNode::doMinus
DLLEXPORT QoreNumberNode * doMinus(const QoreNumberNode &n) const
subtract the argument from this value and return the result
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::~QoreNumberNodeHelper
DLLLOCAL ~QoreNumberNodeHelper()
destroys the object and dereferences the pointer being managed if it was a temporary object ...
QoreNumberNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreNumberNode.h:297
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreNumberNode::priv
struct qore_number_private * priv
the private implementation of the type
Definition: QoreNumberNode.h:69
QoreNumberNode::QoreNumberNode
DLLEXPORT QoreNumberNode()
creates a new numbering-point value and assigns it to 0
QoreNumberNode::parseInit
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
returns the type information
QoreNumberNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreNumberNode.h:302
QoreNumberNode::equals
DLLEXPORT bool equals(const QoreNumberNode &n) const
returns true if the current object is equal to the argument
QoreNumberNode::zero
DLLEXPORT bool zero() const
returns true if the number is zero
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
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
QoreNumberNode::getDateTimeRepresentation
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this value and sets del to true
QoreNumberNode::ordinary
DLLEXPORT bool ordinary() const
returns true if the number is an ordinary number (neither NaN nor an infinity)
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
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::lessThanOrEqual
DLLEXPORT bool lessThanOrEqual(const QoreNumberNode &n) const
returns true if the current object is less than or equal to the argument
QoreNumberNode::numberRefSelf
DLLEXPORT QoreNumberNode * numberRefSelf() const
returns a pointer to this with the reference count incremented
QoreNumberNodeHelper::operator->
DLLLOCAL const QoreNumberNode * operator->()
returns the object being managed
Definition: QoreNumberNode.h:330
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) ...
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::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality without type conversions (hard compare)
QoreNumberNode::~QoreNumberNode
virtual DLLEXPORT ~QoreNumberNode()
the destructor is protected because it should not be called directly
QoreNumberNode::negate
DLLEXPORT QoreNumberNode * negate() const
returns the negative of the current object (this)
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:372
NT_NUMBER
const qore_type_t NT_NUMBER
type value for QoreNumberNode
Definition: node_types.h:53
QORE_NF_DEFAULT
#define QORE_NF_DEFAULT
number format bitfield: default
Definition: QoreNumberNode.h:43
QoreNumberNode::doPlus
DLLEXPORT QoreNumberNode * doPlus(const QoreNumberNode &n) const
add the argument to this value and return the result
QoreNumberNode::inf
DLLEXPORT bool inf() const
returns true if the number is +/-inf
QoreNumberNode::greaterThan
DLLEXPORT bool greaterThan(const QoreNumberNode &n) const
returns true if the current object is greater than the argument
QoreNumberNodeHelper::getReferencedValue
DLLEXPORT QoreNumberNode * getReferencedValue()
returns a referenced value and leaves the current object empty; the caller will own the reference ...
QoreNumberNodeHelper::operator*
DLLLOCAL const QoreNumberNode * operator*()
returns the object being managed
Definition: QoreNumberNode.h:336
QoreNumberNode::doMultiply
DLLEXPORT QoreNumberNode * doMultiply(const QoreNumberNode &n) const
multiply the argument to this value and return the result