All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreNumberNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreNumberNode.h
Qore Programming Language
Copyright (C) 2003 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QORENUMBERNODE_H
#define _QORE_QORENUMBERNODE_H
class LocalVar;
#define QORE_NF_DEFAULT 0
#define QORE_NF_SCIENTIFIC (1 << 0)
#define QORE_NF_RAW (1 << 1)
class QoreNumberNode : public SimpleValueQoreNode {
friend struct qore_number_private;
private:
DLLLOCAL virtual bool getAsBoolImpl() const;
DLLLOCAL virtual int getAsIntImpl() const;
DLLLOCAL virtual int64 getAsBigIntImpl() const;
DLLLOCAL virtual double getAsFloatImpl() const;
protected:
struct qore_number_private* priv;
DLLEXPORT virtual ~QoreNumberNode();
// private
DLLLOCAL QoreNumberNode(struct qore_number_private* p);
public:
DLLEXPORT QoreNumberNode(const AbstractQoreNode* n);
DLLEXPORT QoreNumberNode(const QoreValue& n);
DLLEXPORT QoreNumberNode(double f);
DLLEXPORT QoreNumberNode(int64 i);
DLLEXPORT QoreNumberNode(const char* str);
DLLEXPORT QoreNumberNode(const char* str, unsigned prec);
DLLEXPORT QoreNumberNode();
DLLEXPORT QoreNumberNode(const QoreNumberNode& old);
DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool& del) const;
DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
DLLEXPORT virtual int getAsString(QoreString& str, int foff, class ExceptionSink* xsink) const;
DLLEXPORT virtual QoreString *getAsString(bool& del, int foff, class ExceptionSink* xsink) const;
DLLEXPORT virtual AbstractQoreNode* realCopy() const;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual const char* getTypeName() const;
DLLEXPORT QoreNumberNode* doPlus(const QoreNumberNode& n) const;
DLLEXPORT QoreNumberNode* doMinus(const QoreNumberNode& n) const;
DLLEXPORT QoreNumberNode* doMultiply(const QoreNumberNode& n) const;
DLLEXPORT QoreNumberNode* doDivideBy(const QoreNumberNode& n, ExceptionSink* xsink) const;
DLLEXPORT QoreNumberNode* doDivideBy(double d, ExceptionSink* xsink) const;
DLLEXPORT QoreNumberNode* doDivideBy(int64 i, ExceptionSink* xsink) const;
DLLEXPORT QoreNumberNode* negate() const;
DLLEXPORT bool zero() const;
DLLEXPORT int sign() const;
DLLEXPORT bool lessThan(const QoreNumberNode& n) const;
DLLEXPORT bool lessThan(double n) const;
DLLEXPORT bool lessThan(int64 n) const;
DLLEXPORT bool lessThanOrEqual(const QoreNumberNode& n) const;
DLLEXPORT bool lessThanOrEqual(double n) const;
DLLEXPORT bool lessThanOrEqual(int64 n) const;
DLLEXPORT bool greaterThan(const QoreNumberNode& n) const;
DLLEXPORT bool greaterThan(double n) const;
DLLEXPORT bool greaterThan(int64 n) const;
DLLEXPORT bool greaterThanOrEqual(const QoreNumberNode& n) const;
DLLEXPORT bool greaterThanOrEqual(double n) const;
DLLEXPORT bool greaterThanOrEqual(int64 n) const;
DLLEXPORT bool equals(const QoreNumberNode& n) const;
DLLEXPORT bool equals(double n) const;
DLLEXPORT bool equals(int64 n) const;
DLLEXPORT QoreNumberNode* numberRefSelf() const;
DLLEXPORT void toString(QoreString& str, int fmt = QORE_NF_DEFAULT) const;
DLLEXPORT unsigned getPrec() const;
DLLEXPORT bool nan() const;
DLLEXPORT bool inf() const;
DLLEXPORT bool ordinary() const;
DLLLOCAL virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
DLLEXPORT static QoreNumberNode* toNumber(const AbstractQoreNode* v);
DLLEXPORT static QoreNumberNode* toNumber(const QoreValue v);
DLLLOCAL static const char* getStaticTypeName() {
return "number";
}
DLLLOCAL static qore_type_t getStaticTypeCode() {
return NT_NUMBER;
}
static const qore_type_t TYPE = NT_NUMBER;
};
class QoreNumberNodeHelper {
private:
const QoreNumberNode* num;
bool del;
DLLLOCAL QoreNumberNodeHelper(const QoreNumberNodeHelper&); // not implemented
DLLLOCAL QoreNumberNodeHelper& operator=(const QoreNumberNodeHelper&); // not implemented
DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
public:
DLLLOCAL QoreNumberNodeHelper(const QoreValue n);
DLLLOCAL ~QoreNumberNodeHelper();
DLLLOCAL const QoreNumberNode* operator->() { return num; }
DLLLOCAL const QoreNumberNode* operator*() { return num; }
DLLEXPORT QoreNumberNode* getReferencedValue();
DLLLOCAL bool is_temp() const {
return del;
}
};
#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&#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::inf
DLLEXPORT bool inf() const
returns true if the number is +/-inf
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
QoreNumberNodeHelper::is_temp
DLLLOCAL bool is_temp() const
returns true if the referenced being managed is temporary
Definition: QoreNumberNode.h:348
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:93
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)
QoreNumberNode::equals
DLLEXPORT bool equals(const QoreNumberNode &n) const
returns true if the current object is equal to the argument
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
QoreNumberNode::ordinary
DLLEXPORT bool ordinary() const
returns true if the number is an ordinary number (neither NaN nor an infinity)
QoreNumberNodeHelper
manages conversions of a QoreValue to a QoreNumberNode
Definition: QoreNumberNode.h:312
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:299
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
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
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::priv
struct qore_number_private * priv
the private implementation of the type
Definition: QoreNumberNode.h:68
QoreNumberNode::QoreNumberNode
DLLEXPORT QoreNumberNode()
creates a new numbering-point value and assigns it to 0
QoreNumberNode::greaterThanOrEqual
DLLEXPORT bool greaterThanOrEqual(const QoreNumberNode &n) const
returns true if the current object is greater than or equal to the argument
QoreNumberNode::parseInit
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information
QoreNumberNode::lessThan
DLLEXPORT bool lessThan(const QoreNumberNode &n) const
returns true if the current object is less than the argument
QoreNumberNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreNumberNode.h:304
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:47
QoreNumberNode::lessThanOrEqual
DLLEXPORT bool lessThanOrEqual(const QoreNumberNode &n) const
returns true if the current object is less 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 ...
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:241
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
subtract the argument from 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
QoreNumberNodeHelper::operator->
DLLLOCAL const QoreNumberNode * operator->()
returns the object being managed
Definition: QoreNumberNode.h:332
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:71
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:434
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::doMultiply
DLLEXPORT QoreNumberNode * doMultiply(const QoreNumberNode &n) const
multiply 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
QoreNumberNodeHelper::getReferencedValue
DLLEXPORT QoreNumberNode * getReferencedValue()
returns a referenced value and leaves the current object empty; the caller will own the reference ...
QoreNumberNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality without type conversions (hard compare)
QoreNumberNodeHelper::operator*
DLLLOCAL const QoreNumberNode * operator*()
returns the object being managed
Definition: QoreNumberNode.h:338
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)