Qore Programming Language: include/qore/QoreNumberNode.h (6585) Source File

Qore Programming Language 0.8.11

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreNumberNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreNumberNode.h
4
5 Qore Programming Language
6
7 Copyright 2003 - 2013 David Nichols
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _QORE_QORENUMBERNODE_H
25
26 #define _QORE_QORENUMBERNODE_H
27
28 class LocalVar;
29 class QoreTypeInfo;
30
35 #define QORE_NF_DEFAULT 0
37 #define QORE_NF_SCIENTIFIC (1 << 0)
39 #define QORE_NF_RAW (1 << 1)
41
42
44 class QoreNumberNode : public SimpleValueQoreNode {
45 friend struct qore_number_private;
46 private:
48 DLLLOCAL virtual bool getAsBoolImpl() const;
49
51 DLLLOCAL virtual int getAsIntImpl() const;
52
54 DLLLOCAL virtual int64 getAsBigIntImpl() const;
55
57 DLLLOCAL virtual double getAsFloatImpl() const;
58
59 protected:
61 struct qore_number_private* priv;
62
64
67 DLLEXPORT virtual ~QoreNumberNode();
68
69 // private
70 DLLLOCAL QoreNumberNode(struct qore_number_private* p);
71
72 public:
74 DLLEXPORT QoreNumberNode(const AbstractQoreNode* n);
75
77
80 DLLEXPORT QoreNumberNode(double f);
81
83
86 DLLEXPORT QoreNumberNode(int64 i);
87
89
92 DLLEXPORT QoreNumberNode(const char* str);
93
95
99 DLLEXPORT QoreNumberNode(const char* str, unsigned prec);
100
102 DLLEXPORT QoreNumberNode();
103
105 DLLEXPORT QoreNumberNode(const QoreNumberNode& old);
106
108
113 DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
114
116
119 DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
120
122
128 DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool& del) const;
129
131
135 DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
136
138
144 DLLEXPORT virtual int getAsString(QoreString& str, int foff, class ExceptionSink* xsink) const;
145
147
153 DLLEXPORT virtual QoreString *getAsString(bool& del, int foff, class ExceptionSink* xsink) const;
154
156
159 DLLEXPORT virtual AbstractQoreNode* realCopy() const;
160
162
167 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
168
170
175 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
176
178
181 DLLEXPORT virtual const char* getTypeName() const;
182
184 DLLEXPORT QoreNumberNode* doPlus(const QoreNumberNode& n) const;
185
187 DLLEXPORT QoreNumberNode* doMinus(const QoreNumberNode& n) const;
188
190 DLLEXPORT QoreNumberNode* doMultiply(const QoreNumberNode& n) const;
191
193 DLLEXPORT QoreNumberNode* doDivideBy(const QoreNumberNode& n, ExceptionSink* xsink) const;
194
196 DLLEXPORT QoreNumberNode* negate() const;
197
199 DLLEXPORT bool zero() const;
200
202 DLLEXPORT int sign() const;
203
205 DLLEXPORT int compare(const QoreNumberNode& n) const;
206
208 DLLEXPORT int compare(int64 n) const;
209
211 DLLEXPORT int compare(double n) const;
212
214 DLLEXPORT QoreNumberNode* numberRefSelf() const;
215
217
220 DLLEXPORT void toString(QoreString& str, int fmt = QORE_NF_DEFAULT) const;
221
223 DLLEXPORT unsigned getPrec() const;
224
226 DLLLOCAL virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
227
229 DLLEXPORT static QoreNumberNode* toNumber(const AbstractQoreNode* v);
230
232
235 DLLLOCAL static const char* getStaticTypeName() {
236 return "number";
237 }
238
240 DLLLOCAL static qore_type_t getStaticTypeCode() {
241 return NT_NUMBER;
242 }
243 };
244
245 #endif
QoreNumberNode::getDateTimeRepresentation
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this value and sets del to true
QoreNumberNode
Qore's arbitrary-precision number value type, dynamically-allocated only, reference counted...
Definition: QoreNumberNode.h:44
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
QoreNumberNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the number value converted to a string and sets del to true
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:85
QoreNumberNode::getPrec
DLLEXPORT unsigned getPrec() const
returns the precision of the number
QoreNumberNode::negate
DLLEXPORT QoreNumberNode * negate() const
returns the negative of the current object (this)
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
QoreNumberNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreNumberNode.h:235
QoreNumberNode::doPlus
DLLEXPORT QoreNumberNode * doPlus(const QoreNumberNode &n) const
add the argument to this value and return the result
qore_type_t
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:59
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:42
QoreNumberNode::doDivideBy
DLLEXPORT QoreNumberNode * doDivideBy(const QoreNumberNode &n, ExceptionSink *xsink) const
add the argument to this value and return the result
QoreNumberNode::priv
struct qore_number_private * priv
the private implementation of the type
Definition: QoreNumberNode.h:61
QoreNumberNode::QoreNumberNode
DLLEXPORT QoreNumberNode()
creates a new numbering-point value and assigns it to 0
QoreNumberNode::parseInit
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information
QoreNumberNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreNumberNode.h:240
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
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::numberRefSelf
DLLEXPORT QoreNumberNode * numberRefSelf() const
returns a pointer to this with the reference count incremented
QoreNumberNode::doMinus
DLLEXPORT QoreNumberNode * doMinus(const QoreNumberNode &n) const
add the argument to this value and return the result
QoreNumberNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
QoreNumberNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
QoreNumberNode::~QoreNumberNode
virtual DLLEXPORT ~QoreNumberNode()
the destructor is protected because it should not be called directly
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:417
NT_NUMBER
const qore_type_t NT_NUMBER
type value for QoreNumberNode
Definition: node_types.h:45
QORE_NF_DEFAULT
#define QORE_NF_DEFAULT
number format bitfield: default
Definition: QoreNumberNode.h:36
QoreNumberNode::doMultiply
DLLEXPORT QoreNumberNode * doMultiply(const QoreNumberNode &n) const
add the argument to this value and return the result
QoreNumberNode::sign
DLLEXPORT int sign() const
returns -1 if the number is negative, 0 if zero, or 1 if the number is positive
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::compare
DLLEXPORT int compare(const QoreNumberNode &n) const
compares the argument to the current object, returns -1 if the current object is less than the argume...
QoreNumberNode::zero
DLLEXPORT bool zero() const
returns true if the number is zero
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)