32 #ifndef _QORE_QOREVALUE_H 33 #define _QORE_QOREVALUE_H 37 typedef 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 65 template<
typename Type>
67 typedef Type * Result;
70 static Result cast(QV *qv, valtype_t type) {
72 assert(!qv->v.n || dynamic_cast<Result>(qv->v.n));
73 return reinterpret_cast<Result
>(qv->v.n);
83 static bool cast(QV *qv, valtype_t type) {
84 return qv->getAsBool();
91 typedef double Result;
94 static double cast(QV *qv, valtype_t type) {
95 return qv->getAsFloat();
102 typedef int64 Result;
104 template<
typename QV>
105 static int64 cast(QV *qv, valtype_t type) {
106 return qv->getAsBigInt();
146 DLLEXPORT
QoreValue(
unsigned long long i);
182 DLLEXPORT
void ref()
const;
246 DLLEXPORT
void clear();
260 assert(dynamic_cast<T*>(
v.
n));
261 T* rv =
reinterpret_cast<T*
>(
v.
n);
270 DLLLOCAL
typename detail::QoreValueCastHelper<T>::Result
get() {
278 DLLLOCAL
typename detail::QoreValueCastHelper<const T>::Result
get()
const {
306 DLLEXPORT
bool hasNode()
const;
312 DLLEXPORT
bool isNull()
const;
370 DLLLOCAL
operator bool()
const {
406 DLLLOCAL
operator bool()
const {
DLLEXPORT AbstractQoreNode * takeNodeIntern()
returns the internal AbstractQoreNode pointer, does not check that type == QV_Node, leaves the object empty
DLLEXPORT bool getAsBool() const
returns the value as a bool
DLLEXPORT QoreValue()
creates with no value (i.e. QoreNothingNode)
DLLEXPORT int64 getAsBigInt() const
returns the value as an int
DLLEXPORT void swap(QoreValue &val)
exchanges the values
DLLEXPORT ~ValueHolder()
dereferences any contained node
double f
for double values
Definition: QoreValue.h:58
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:258
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 AbstractQoreNode * takeNode()
returns a referenced AbstractQoreNode pointer leaving "this" empty (value is taken from "this"); the ...
base class for holding a QoreValue object
Definition: QoreValue.h:319
this is the union that stores values in QoreValue
Definition: QoreValue.h:55
DLLEXPORT AbstractQoreNode * assignNothing()
sets the value of the object to QoreNothingNode and returns any node value held previously ...
DLLEXPORT QoreValue release()
returns a QoreValue object and leaves the current object empty; the caller owns any reference contain...
DLLLOCAL ValueHolder(ExceptionSink *xs)
creates an empty object
Definition: QoreValue.h:346
qore_value_u v
the actual value is stored here
Definition: QoreValue.h:123
allows storing a value and setting a boolean flag that indicates if the value should be dereference i...
Definition: QoreValue.h:376
DLLLOCAL T * takeReferencedNode()
returns the stored node value and leaves the current object empty
Definition: QoreValue.h:435
evaluates an AbstractQoreNode and dereferences the stored value in the destructor ...
Definition: QoreValue.h:484
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 ...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
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 QoreValue & operator=(const QoreValue &n)
assigns a new value
DLLLOCAL bool isTemp() const
returns true if the value is temporary (needs dereferencing)
Definition: QoreValue.h:397
DLLEXPORT qore_type_t getType() const
returns the type of value contained
DLLLOCAL ValueOptionalRefHolder(QoreValue n_v, bool nd, ExceptionSink *xs)
creates the object with the given values
Definition: QoreValue.h:387
DLLEXPORT AbstractQoreNode * assignAndSanitize(const QoreValue n)
sets the value of the object and returns any node value held previously
DLLLOCAL AbstractQoreNode * takeNode(bool &nd)
returns the stored AbstractQoreNode pointer and sets the dereference flag as an output variable ...
Definition: QoreValue.h:449
DLLEXPORT bool isNothing() const
returns true if the object contains NOTHING
bool needs_deref
flag indicating if the value should be dereferenced in the destructor or not
Definition: QoreValue.h:383
DLLEXPORT void ref() const
references the contained value if type == QV_Node
DLLEXPORT const char * getTypeName() const
returns a string type description of the value contained (ex: "nothing" for a null AbstractQoreNode p...
DLLEXPORT double getAsFloat() const
returns the value as a float
DLLEXPORT void sanitize()
converts pointers to efficient representations and manages the reference count
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
ExceptionSink * xsink
for possible Qore-language exceptions
Definition: QoreValue.h:324
used in QoreValue::get()
Definition: QoreValue.h:66
#define QV_Node
for heap-allocated values
Definition: QoreValue.h:46
namespace for implementation details of QoreValue functions
Definition: QoreValue.h:63
DLLEXPORT AbstractQoreNode * getReferencedValue()
returns a referenced AbstractQoreNode ptr; caller owns the reference; the current object is left empt...
DLLEXPORT AbstractQoreNode * takeIfNode()
returns a referenced AbstractQoreNode pointer only if the contained value is an AbstractQoreNode poin...
DLLEXPORT void sanitize()
converts any node pointers to efficient representations if possible and dereferences the node value c...
valtype_t type
indicates the value that the union is holding
Definition: QoreValue.h:125
DLLEXPORT AbstractQoreNode * getReferencedValue()
returns a referenced AbstractQoreNode ptr; caller owns the reference; the current object is left empt...
DLLLOCAL QoreValue takeValue(bool &nd)
returns the stored value and sets the dereference flag as an output variable
Definition: QoreValue.h:459
DLLLOCAL void setValue(QoreValue nv)
assigns a new non-temporary value
Definition: QoreValue.h:411
QoreValue v
the vlaue held
Definition: QoreValue.h:322
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:469
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
AbstractQoreNode * n
for all heap-allocated values
Definition: QoreValue.h:59
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns the type of the value
DLLEXPORT QoreValue takeReferencedValue()
returns a QoreValue after incrementing the reference count of any node value stored ...
DLLLOCAL QoreValue & operator*()
returns the value being managed
Definition: QoreValue.h:339
DLLEXPORT void clear()
unconditionally set the QoreValue to QoreNothingNode (does not dereference any possible contained Abs...
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
DLLLOCAL QoreValue & operator=(QoreValue nv)
assigns the object, any currently-held value is dereferenced before the assignment ...
Definition: QoreValue.h:363
int64 i
for integer values
Definition: QoreValue.h:57
DLLEXPORT AbstractQoreNode * getInternalNode()
returns any AbstractQoreNode value held; if type != QV_Node, returns NULL
DLLEXPORT AbstractQoreNode * assign(AbstractQoreNode *n)
the QoreValue object takes the reference of the argument
DLLLOCAL ValueHolderBase(ExceptionSink *xs)
creates an ampty object
Definition: QoreValue.h:328
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:71
DLLLOCAL void evalIntern(const AbstractQoreNode *exp)
evaluates the argument, returns -1 for error, 0 = OK
DLLEXPORT ValueEvalRefHolder(const AbstractQoreNode *exp, ExceptionSink *xs)
evaluates the AbstractQoreNode argument
bool b
for boolean values
Definition: QoreValue.h:56
DLLLOCAL QoreValue * operator->()
returns the value being managed
Definition: QoreValue.h:336
DLLEXPORT bool isNull() const
returns true if the object contains NULL
DLLEXPORT bool isNullOrNothing() const
returns true if the object contains NOTHING or NULL
DLLEXPORT AbstractQoreNode * getReferencedValue() const
returns a referenced AbstractQoreNode pointer; leaving the "this" untouched; the caller owns the refe...
DLLEXPORT int eval(const AbstractQoreNode *exp)
evaluates the argument, returns -1 for error, 0 = OK
DLLEXPORT bool isEqualHard(const QoreValue v) const
returns trus if the argument value is equal to the current value without any type conversions ...
holds an object and dereferences it in the destructor
Definition: QoreValue.h:343
DLLEXPORT bool hasNode() const
returns true if the object contains a non-null AbstractQoreNode pointer (ie type == QV_Node && v...
DLLLOCAL void clearTemp()
sets needs_deref = false
Definition: QoreValue.h:400
DLLEXPORT QoreValue refSelf() const
references the contained value if type == QV_Node, returns itself
DLLEXPORT void ensureReferencedValue()
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values ...