Qore Programming Language - C/C++ Library  0.8.13.4
QoreNumberNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreNumberNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2017 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 struct qore_number_private;
53 private:
55  DLLLOCAL virtual bool getAsBoolImpl() const;
56 
58  DLLLOCAL virtual int getAsIntImpl() const;
59 
61  DLLLOCAL virtual int64 getAsBigIntImpl() const;
62 
64  DLLLOCAL virtual double getAsFloatImpl() const;
65 
66 protected:
68  struct qore_number_private* priv;
69 
71 
74  DLLEXPORT virtual ~QoreNumberNode();
75 
76  // private
77  DLLLOCAL QoreNumberNode(struct qore_number_private* p);
78 
79 public:
81  DLLEXPORT QoreNumberNode(const AbstractQoreNode* n);
82 
84  DLLEXPORT QoreNumberNode(const QoreValue& n);
85 
87 
90  DLLEXPORT QoreNumberNode(double f);
91 
93 
96  DLLEXPORT QoreNumberNode(int64 i);
97 
99 
102  DLLEXPORT QoreNumberNode(const char* str);
103 
105 
109  DLLEXPORT QoreNumberNode(const char* str, unsigned prec);
110 
112  DLLEXPORT QoreNumberNode();
113 
115  DLLEXPORT QoreNumberNode(const QoreNumberNode& old);
116 
118 
123  DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
124 
126 
129  DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
130 
132 
138  DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool& del) const;
139 
141 
145  DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
146 
148 
154  DLLEXPORT virtual int getAsString(QoreString& str, int foff, class ExceptionSink* xsink) const;
155 
157 
163  DLLEXPORT virtual QoreString *getAsString(bool& del, int foff, class ExceptionSink* xsink) const;
164 
166 
169  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
170 
172 
177  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
178 
180 
185  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
186 
188 
191  DLLEXPORT virtual const char* getTypeName() const;
192 
194  DLLEXPORT QoreNumberNode* doPlus(const QoreNumberNode& n) const;
195 
197  DLLEXPORT QoreNumberNode* doMinus(const QoreNumberNode& n) const;
198 
200  DLLEXPORT QoreNumberNode* doMultiply(const QoreNumberNode& n) const;
201 
203  DLLEXPORT QoreNumberNode* doDivideBy(const QoreNumberNode& n, ExceptionSink* xsink) const;
204 
206  DLLEXPORT QoreNumberNode* doDivideBy(double d, ExceptionSink* xsink) const;
207 
209  DLLEXPORT QoreNumberNode* doDivideBy(int64 i, ExceptionSink* xsink) const;
210 
212  DLLEXPORT QoreNumberNode* negate() const;
213 
215  DLLEXPORT bool zero() const;
216 
218  DLLEXPORT int sign() const;
219 
221  DLLEXPORT bool lessThan(const QoreNumberNode& n) const;
222 
224  DLLEXPORT bool lessThan(double n) const;
225 
227  DLLEXPORT bool lessThan(int64 n) const;
228 
230  DLLEXPORT bool lessThanOrEqual(const QoreNumberNode& n) const;
231 
233  DLLEXPORT bool lessThanOrEqual(double n) const;
234 
236  DLLEXPORT bool lessThanOrEqual(int64 n) const;
237 
239  DLLEXPORT bool greaterThan(const QoreNumberNode& n) const;
240 
242  DLLEXPORT bool greaterThan(double n) const;
243 
245  DLLEXPORT bool greaterThan(int64 n) const;
246 
248  DLLEXPORT bool greaterThanOrEqual(const QoreNumberNode& n) const;
249 
251  DLLEXPORT bool greaterThanOrEqual(double n) const;
252 
254  DLLEXPORT bool greaterThanOrEqual(int64 n) const;
255 
257  DLLEXPORT bool equals(const QoreNumberNode& n) const;
258 
260  DLLEXPORT bool equals(double n) const;
261 
263  DLLEXPORT bool equals(int64 n) const;
264 
266  DLLEXPORT QoreNumberNode* numberRefSelf() const;
267 
269 
272  DLLEXPORT void toString(QoreString& str, int fmt = QORE_NF_DEFAULT) const;
273 
275  DLLEXPORT unsigned getPrec() const;
276 
278  DLLEXPORT bool nan() const;
279 
281  DLLEXPORT bool inf() const;
282 
284  DLLEXPORT bool ordinary() const;
285 
287  DLLLOCAL virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
288 
290  DLLEXPORT static QoreNumberNode* toNumber(const AbstractQoreNode* v);
291 
293  DLLEXPORT static QoreNumberNode* toNumber(const QoreValue v);
294 
296 
299  DLLLOCAL static const char* getStaticTypeName() {
300  return "number";
301  }
302 
304  DLLLOCAL static qore_type_t getStaticTypeCode() {
305  return NT_NUMBER;
306  }
307 
308  static const qore_type_t TYPE = NT_NUMBER;
309 };
310 
313 private:
314  const QoreNumberNode* num;
315  bool del;
316 
317  DLLLOCAL QoreNumberNodeHelper(const QoreNumberNodeHelper&); // not implemented
318  DLLLOCAL QoreNumberNodeHelper& operator=(const QoreNumberNodeHelper&); // not implemented
319  DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
320 
321 public:
323  DLLLOCAL QoreNumberNodeHelper(const QoreValue n);
324 
326  DLLLOCAL ~QoreNumberNodeHelper();
327 
329 
332  DLLLOCAL const QoreNumberNode* operator->() { return num; }
333 
335 
338  DLLLOCAL const QoreNumberNode* operator*() { return num; }
339 
341 
345  DLLEXPORT QoreNumberNode* getReferencedValue();
346 
348  DLLLOCAL bool is_temp() const {
349  return del;
350  }
351 };
352 
353 #endif
Qore&#39;s arbitrary-precision number value type, dynamically-allocated only, reference counted...
Definition: QoreNumberNode.h:51
DLLEXPORT bool nan() const
returns true if the number is NaN
DLLEXPORT bool greaterThanOrEqual(const QoreNumberNode &n) const
returns true if the current object is greater than or equal to the argument
virtual DLLEXPORT int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const
concatenate the string representation of the number value to an existing QoreString ...
DLLEXPORT unsigned getPrec() const
returns the precision of the number
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
static DLLEXPORT QoreNumberNode * toNumber(const AbstractQoreNode *v)
returns the representation of the value as a number if possible (otherwise returns 0)...
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality with possible type conversion (soft compare)
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the number value converted to a string and sets del to true
DLLEXPORT QoreNumberNode * doMinus(const QoreNumberNode &n) const
subtract the argument from this value and return the result
DLLEXPORT bool lessThan(const QoreNumberNode &n) const
returns true if the current object is less than the argument
manages conversions of a QoreValue to a QoreNumberNode
Definition: QoreNumberNode.h:312
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreNumberNode.h:299
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
struct qore_number_private * priv
the private implementation of the type
Definition: QoreNumberNode.h:68
DLLEXPORT QoreNumberNode()
creates a new numbering-point value and assigns it to 0
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreNumberNode.h:304
DLLEXPORT bool equals(const QoreNumberNode &n) const
returns true if the current object is equal to the argument
DLLEXPORT bool zero() const
returns true if the number is zero
DLLEXPORT void toString(QoreString &str, int fmt=QORE_NF_DEFAULT) const
concatenates the string value corresponding to the number to the string given
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this value and sets del to true
DLLEXPORT bool ordinary() const
returns true if the number is an ordinary number (neither NaN nor an infinity)
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
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:241
DLLEXPORT bool lessThanOrEqual(const QoreNumberNode &n) const
returns true if the current object is less than or equal to the argument
DLLEXPORT QoreNumberNode * numberRefSelf() const
returns a pointer to this with the reference count incremented
DLLEXPORT int sign() const
returns -1 if the number is negative, 0 if zero, or 1 if the number is positive
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) ...
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:71
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality without type conversions (hard compare)
virtual DLLEXPORT ~QoreNumberNode()
the destructor is protected because it should not be called directly
DLLEXPORT QoreNumberNode * negate() const
returns the negative of the current object (this)
base class for simple value types
Definition: AbstractQoreNode.h:434
const qore_type_t NT_NUMBER
type value for QoreNumberNode
Definition: node_types.h:53
#define QORE_NF_DEFAULT
number format bitfield: default
Definition: QoreNumberNode.h:43
DLLEXPORT QoreNumberNode * doPlus(const QoreNumberNode &n) const
add the argument to this value and return the result
DLLEXPORT bool inf() const
returns true if the number is +/-inf
DLLEXPORT bool greaterThan(const QoreNumberNode &n) const
returns true if the current object is greater than the argument
DLLEXPORT QoreNumberNode * doMultiply(const QoreNumberNode &n) const
multiply the argument to this value and return the result