32#ifndef _QORE_QOREVALUE_H
33#define _QORE_QOREVALUE_H
37typedef unsigned char valtype_t;
43#define QV_Bool (valtype_t)0
44#define QV_Int (valtype_t)1
45#define QV_Float (valtype_t)2
46#define QV_Node (valtype_t)3
47#define QV_Ref (valtype_t)4
66 template<
typename Type>
68 typedef Type * Result;
71 static Result cast(QV *qv, valtype_t type) {
73 assert(!qv->v.n ||
dynamic_cast<Result
>(qv->v.n));
74 return reinterpret_cast<Result
>(qv->v.n);
84 static bool cast(QV *qv, valtype_t type) {
85 return qv->getAsBool();
92 typedef double Result;
95 static double cast(QV *qv, valtype_t type) {
96 return qv->getAsFloat();
103 typedef int64 Result;
105 template<
typename QV>
106 static int64 cast(QV *qv, valtype_t type) {
107 return qv->getAsBigInt();
127 DLLLOCAL
void set(
double f) {
133 DLLLOCAL
void set(
bool b) {
203 assert(
dynamic_cast<T*
>(
v.
n));
204 T* rv =
reinterpret_cast<T*
>(
v.
n);
214 DLLLOCAL
typename detail::QoreValueCastHelper<T>::Result
get() {
223 DLLLOCAL
typename detail::QoreValueCastHelper<const T>::Result
get()
const {
271 DLLEXPORT
operator bool()
const;
334 DLLEXPORT
void ref()
const;
524 DLLLOCAL
operator bool()
const {
560 DLLLOCAL
operator bool()
const {
685DLLEXPORT
extern const char* qoreBoolTypeName;
687DLLEXPORT
extern const char* qoreIntTypeName;
689DLLEXPORT
extern const char* qoreFloatTypeName;
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
Base value class; parent of QoreValue; designed to be passed by value.
Definition: QoreValue.h:113
DLLLOCAL void set(double f)
assigns a floating-point value to the object; any current value is overwritten
Definition: QoreValue.h:127
valtype_t type
indicates the value that the union is holding
Definition: QoreValue.h:118
qore_value_u v
the actual value is stored here
Definition: QoreValue.h:116
DLLEXPORT double getAsFloat() const
returns the value as a float
DLLEXPORT bool isValue() const
returns true if the object holds a value, false if it holds an expression
DLLEXPORT const AbstractQoreNode * getInternalNode() const
returns any AbstractQoreNode value held; if type != QV_Node, returns nullptr
DLLEXPORT void set(AbstractQoreNode *n)
assigns a new value to the object; any current value is overwritten
DLLLOCAL QoreSimpleValue & assign(bool b)
assigns a new value to the object and returns a reference to the object; any current value is overwri...
Definition: QoreValue.h:163
DLLEXPORT bool isNull() const
returns true if the object contains NULL
DLLLOCAL detail::QoreValueCastHelper< T >::Result get()
returns the value as the given type
Definition: QoreValue.h:214
DLLEXPORT AbstractQoreNode * getInternalNode()
returns any AbstractQoreNode value held; if type != QV_Node, returns nullptr
DLLEXPORT qore_type_t getType() const
returns the type of value contained
DLLEXPORT AbstractQoreNode * takeNodeIntern()
returns the internal AbstractQoreNode pointer, does not check that type == QV_Node,...
DLLEXPORT const char * getTypeName() const
returns a string type description of the value contained (ex: "nothing" for a null AbstractQoreNode p...
DLLLOCAL QoreSimpleValue & assign(const QoreSimpleValue &val)
assigns a new value to the object and returns a reference to the object; any current value is overwri...
Definition: QoreValue.h:145
DLLLOCAL QoreSimpleValue & assign(AbstractQoreNode *n)
assigns a new value to the object and returns a reference to the object; any current value is overwri...
Definition: QoreValue.h:169
DLLEXPORT bool isNullOrNothing() const
returns true if the object contains NOTHING or NULL
DLLLOCAL void set(int64 i)
assigns an integer value to the object; any current value is overwritten
Definition: QoreValue.h:121
DLLLOCAL detail::QoreValueCastHelper< constT >::Result get() const
returns the value as the given type
Definition: QoreValue.h:223
DLLEXPORT bool isScalar() const
returns true if the value is a scalar (int, bool, float, number, string)
DLLEXPORT bool isConstant() const
returns true if the value is a constant value (does not require evaluation)
DLLEXPORT bool getAsBool() const
returns the value as a bool
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values
DLLEXPORT bool hasEffect() const
return true if the value needs evaluation and has a side effect
DLLLOCAL T * take()
returns a pointer to an object of the given class; takes the pointer from the object; the caller owns...
Definition: QoreValue.h:201
DLLLOCAL QoreSimpleValue & assign(int64 i)
assigns a new value to the object and returns a reference to the object; any current value is overwri...
Definition: QoreValue.h:151
DLLLOCAL void set(bool b)
assigns a boolean value to the object; any current value is overwritten
Definition: QoreValue.h:133
DLLEXPORT bool needsEval() const
return true if the value needs evaluation
DLLEXPORT bool isEqualHard(const QoreValue v) const
returns trus if the argument value is equal to the current value without any type conversions
DLLEXPORT void set(const QoreSimpleValue &val)
assigns a new value to the object; any current value is overwritten
DLLEXPORT int64 getAsBigInt() const
returns the value as an int
DLLEXPORT void clear()
unconditionally set the QoreValue to QoreNothingNode (does not dereference any possible contained Abs...
DLLEXPORT AbstractQoreNode * takeNode()
returns a referenced AbstractQoreNode pointer leaving "this" empty (value is taken from "this"); the ...
DLLEXPORT bool isNothing() const
returns true if the object contains NOTHING
DLLLOCAL QoreSimpleValue & assign(double f)
assigns a new value to the object and returns a reference to the object; any current value is overwri...
Definition: QoreValue.h:157
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
evaluates an AbstractQoreNode and dereferences the stored value in the destructor
Definition: QoreValue.h:672
DLLEXPORT ValueEvalOptimizedRefHolder(const QoreValue &exp, ExceptionSink *xs)
evaluates the exp argument
DLLEXPORT int eval(const QoreValue &exp)
evaluates the argument, returns -1 for error, 0 = OK
DLLEXPORT ValueEvalOptimizedRefHolder(ExceptionSink *xs)
creates the object with with no evaluation
evaluates an AbstractQoreNode and dereferences the stored value in the destructor
Definition: QoreValue.h:634
DLLEXPORT ValueEvalRefHolder(const AbstractQoreNode *exp, ExceptionSink *xs)
evaluates the exp argument
DLLEXPORT ValueEvalRefHolder(ExceptionSink *xs)
creates the object with with no evaluation
DLLLOCAL int evalIntern(const QoreValue &exp)
evaluates the argument, returns -1 for error, 0 = OK
DLLEXPORT ValueEvalRefHolder(const QoreValue exp, ExceptionSink *xs)
evaluates the exp argument
DLLEXPORT int eval(const AbstractQoreNode *exp)
evaluates the argument, returns -1 for error, 0 = OK
DLLEXPORT int eval(const QoreValue exp)
evaluates the argument, returns -1 for error, 0 = OK
DLLLOCAL int evalIntern(const AbstractQoreNode *exp)
evaluates the argument, returns -1 for error, 0 = OK
base class for holding a QoreValue object
Definition: QoreValue.h:457
DLLLOCAL QoreValue & operator*()
returns the value being managed
Definition: QoreValue.h:480
DLLLOCAL const QoreValue & operator*() const
returns the value being managed
Definition: QoreValue.h:483
DLLLOCAL ValueHolderBase(QoreValue n_v, ExceptionSink *xs)
creates the object with the given value
Definition: QoreValue.h:470
ExceptionSink * xsink
for possible Qore-language exceptions
Definition: QoreValue.h:462
DLLLOCAL const QoreValue * operator->() const
returns the value being managed
Definition: QoreValue.h:477
DLLLOCAL ValueHolderBase(ExceptionSink *xs)
creates an ampty object
Definition: QoreValue.h:466
QoreValue v
the value held
Definition: QoreValue.h:460
DLLLOCAL QoreValue * operator->()
returns the value being managed
Definition: QoreValue.h:474
holds an object and dereferences it in the destructor
Definition: QoreValue.h:487
DLLEXPORT ~ValueHolder()
dereferences any contained node
DLLEXPORT QoreValue release()
returns a QoreValue object and leaves the current object empty; the caller owns any reference contain...
DLLLOCAL T * releaseAs()
returns a pointer to a value of the given class and leaves the current object empty
Definition: QoreValue.h:510
DLLLOCAL QoreValue & operator=(QoreValue nv)
assigns the object, any currently-held value is dereferenced before the assignment
Definition: QoreValue.h:517
DLLLOCAL ValueHolder(QoreValue n_v, ExceptionSink *xs)
creates the object with the given value
Definition: QoreValue.h:494
DLLLOCAL ValueHolder(ExceptionSink *xs)
creates an empty object
Definition: QoreValue.h:490
DLLEXPORT QoreValue getReferencedValue()
returns a referenced value; caller owns the reference; the current object is left undisturbed
allows storing a value and setting a boolean flag that indicates if the value should be dereference i...
Definition: QoreValue.h:530
DLLLOCAL bool isTemp() const
returns true if the value is temporary (needs dereferencing)
Definition: QoreValue.h:551
DLLLOCAL ValueOptionalRefHolder(QoreValue n_v, bool nd, ExceptionSink *xs)
creates the object with the given values
Definition: QoreValue.h:541
DLLLOCAL ValueOptionalRefHolder(ExceptionSink *xs)
creates an empty object
Definition: QoreValue.h:545
DLLLOCAL T * takeReferencedNode()
returns the stored node value and leaves the current object empty
Definition: QoreValue.h:589
DLLLOCAL QoreValue takeValue(bool &nd)
returns the stored value and sets the dereference flag as an output variable
Definition: QoreValue.h:613
DLLLOCAL void setValue(QoreValue nv)
assigns a new non-temporary value
Definition: QoreValue.h:565
DLLEXPORT void ensureReferencedValue()
DLLEXPORT QoreValue takeReferencedValue()
returns a QoreValue after incrementing the reference count of any node value stored if necessary
DLLLOCAL void clearTemp()
sets needs_deref = false
Definition: QoreValue.h:554
DLLLOCAL AbstractQoreNode * takeNode(bool &nd)
returns the stored AbstractQoreNode pointer and sets the dereference flag as an output variable
Definition: QoreValue.h:603
DLLEXPORT QoreValue getReferencedValue()
returns a referenced value; caller owns the reference; the current object is not disturbed
DLLLOCAL void setValue(QoreValue nv, bool temp)
assigns a new value
Definition: QoreValue.h:574
bool needs_deref
flag indicating if the value should be dereferenced in the destructor or not
Definition: QoreValue.h:537
DLLLOCAL void takeValueFrom(ValueOptionalRefHolder &val)
returns the stored value which must be dereferenced if it is a node object (i.e. type == QV_Node)
Definition: QoreValue.h:623
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
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
#define QV_Node
for heap-allocated values
Definition: QoreValue.h:46
#define QV_Bool
for boolean values
Definition: QoreValue.h:43
#define QV_Float
for floating-point values
Definition: QoreValue.h:45
#define QV_Int
for integer values
Definition: QoreValue.h:44
namespace for implementation details of QoreValue functions
Definition: QoreValue.h:64
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:279
DLLEXPORT AbstractQoreNode * assignNothing()
sets the value of the object to QoreNothingNode and returns any node value held previously
DLLEXPORT AbstractQoreNode * assign(bool n)
sets the value of the object and returns any node value held previously
DLLEXPORT const char * getFullTypeName(bool with_namespaces) const
returns a string type description of the full type of the value contained (ex: "nothing" for a null A...
DLLEXPORT QoreValue(AbstractQoreNode *n)
the QoreValue object takes the reference of the argument passed
DLLEXPORT int getAsString(QoreString &str, int format_offset, ExceptionSink *xsink) const
appends the string value of the contained node to the string argument with optional formatting
DLLEXPORT QoreValue(unsigned long i)
creates as an int
DLLEXPORT QoreValue(unsigned long long i)
creates as an int
DLLEXPORT QoreValue(const AbstractQoreNode *n)
creates as the given object; does not reference n for the assignment to this object
DLLEXPORT QoreValue(int i)
creates as an int
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns the type of the value
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values
DLLEXPORT QoreValue(double f)
creates as a double
DLLEXPORT QoreValue(int64 i)
creates as an int
DLLEXPORT const char * getFullTypeName() const
returns a string type description of the full type of the value contained (ex: "nothing" for a null A...
DLLEXPORT QoreString * getAsString(bool &del, int foff, ExceptionSink *xsink) const
returns the string value with optional formatting of the contained node
DLLEXPORT bool isReferenceCounted() const
returns true if the value holds a referenced-counted node
DLLEXPORT AbstractQoreNode * takeIfNode()
returns a referenced value; leaving the "this" untouched; the caller owns the reference returned
DLLEXPORT QoreValue(unsigned int i)
creates as an int
DLLEXPORT void swap(QoreValue &val)
exchanges the values
DLLEXPORT AbstractQoreNode * assign(const QoreValue n)
sets the value of the object and returns any node value held previously
DLLEXPORT bool hasNode() const
returns true if the object contains a non-null AbstractQoreNode pointer (ie type == QV_Node && v....
DLLEXPORT QoreValue & operator=(const QoreSimpleValue &n)
assigns a new value
DLLEXPORT QoreValue(const QoreValue &old)
copies the value, in case type == QV_Node, no additional references are made in this function
DLLEXPORT bool isEqualValue(const QoreValue v)
returns true of the argument is exactly the same value as the current value, meaning also that if bot...
DLLEXPORT QoreValue eval(ExceptionSink *xsink) const
evaluates the node and returns the result
DLLEXPORT const QoreTypeInfo * getFullTypeInfo() const
returns the exact type of the value; i.e. the class type for classes, hashdecl type for hashdecls
DLLEXPORT bool derefCanThrowException() const
returns true if a dereference could theoretically throw an exception (an object is reachable from thi...
DLLEXPORT AbstractQoreNode * assign(double n)
sets the value of the object and returns any node value held previously
DLLEXPORT QoreValue()
creates with no value (i.e. QoreNothingNode)
DLLEXPORT const char * getFullTypeName(bool with_namespaces, QoreString &scratch) const
returns a string type description of the full type of the value contained (ex: "nothing" for a null A...
DLLEXPORT AbstractQoreNode * assign(int64 n)
sets the value of the object and returns any node value held previously
DLLEXPORT QoreValue(long i)
creates as an int
DLLEXPORT void ref() const
references the contained value if type == QV_Node
DLLEXPORT QoreValue(const QoreSimpleValue &v)
creates the value from the argument
DLLEXPORT QoreValue(bool b)
creates as a bool
DLLEXPORT QoreValue eval(bool &needs_deref, ExceptionSink *xsink) const
evaluates the node and returns the result
DLLEXPORT QoreValue refSelf() const
references the contained value if type == QV_Node, returns itself
DLLEXPORT bool isEqualSoft(const QoreValue v, ExceptionSink *xsink) const
returns trus if the argument value is equal to the current value with type conversions
DLLEXPORT QoreValue & operator=(const QoreValue &n)
assigns a new value
DLLEXPORT void sanitize()
converts any node pointers to efficient representations if possible and dereferences the node value c...
DLLEXPORT AbstractQoreNode * assign(AbstractQoreNode *n)
the QoreValue object takes the reference of the argument
used in QoreValue::get()
Definition: QoreValue.h:67
this is the union that stores values in QoreValue
Definition: QoreValue.h:56
bool b
for boolean values
Definition: QoreValue.h:57
AbstractQoreNode * n
for all heap-allocated values
Definition: QoreValue.h:60
double f
for double values
Definition: QoreValue.h:59
int64 i
for integer values
Definition: QoreValue.h:58