32 #ifndef _QORE_QOREVALUE_H
33 #define _QORE_QOREVALUE_H
37 typedef unsigned char valtype_t;
39 #define QV_Bool (valtype_t)0
40 #define QV_Int (valtype_t)1
41 #define QV_Float (valtype_t)2
42 #define QV_Node (valtype_t)3
43 #define QV_Ref (valtype_t)4
59 template<
typename Type>
61 typedef Type * Result;
64 static Result cast(QV *qv, valtype_t type) {
65 assert(type == QV_Node);
66 assert(!qv->v.n || dynamic_cast<Result>(qv->v.n));
67 return reinterpret_cast<Result
>(qv->v.n);
77 static bool cast(QV *qv, valtype_t type) {
78 return qv->getAsBool();
85 typedef double Result;
88 static double cast(QV *qv, valtype_t type) {
89 return qv->getAsFloat();
99 static double cast(QV *qv, valtype_t type) {
100 return qv->getAsBigInt();
106 friend class ValueHolder;
107 friend class ValueEvalRefHolder;
118 DLLEXPORT QoreValue();
120 DLLEXPORT QoreValue(
bool b);
122 DLLEXPORT QoreValue(
int i);
124 DLLEXPORT QoreValue(
unsigned int i);
126 DLLEXPORT QoreValue(
long i);
128 DLLEXPORT QoreValue(
unsigned long i);
130 DLLEXPORT QoreValue(
unsigned long long i);
132 DLLEXPORT QoreValue(
int64 i);
134 DLLEXPORT QoreValue(
double f);
145 DLLEXPORT QoreValue(
const QoreValue& old);
147 DLLEXPORT
void swap(QoreValue& val);
149 DLLEXPORT
bool getAsBool()
const;
151 DLLEXPORT
int64 getAsBigInt()
const;
153 DLLEXPORT
double getAsFloat()
const;
155 DLLEXPORT
void ref()
const;
157 DLLEXPORT QoreValue refSelf()
const;
179 DLLEXPORT
bool isEqualSoft(
const QoreValue v,
ExceptionSink* xsink)
const;
180 DLLEXPORT
bool isEqualHard(
const QoreValue v)
const;
184 DLLEXPORT
void sanitize();
186 DLLEXPORT QoreValue& operator=(
const QoreValue& n);
192 DLLEXPORT
void clear();
203 assert(type == QV_Node);
204 assert(dynamic_cast<T*>(v.n));
205 T* rv =
reinterpret_cast<T*
>(v.n);
211 DLLLOCAL
typename detail::QoreValueCastHelper<T>::Result
get() {
216 DLLLOCAL
typename detail::QoreValueCastHelper<const T>::Result
get()
const {
233 DLLEXPORT
const char* getTypeName()
const;
236 DLLEXPORT
bool hasNode()
const;
239 DLLEXPORT
bool isNothing()
const;
242 DLLEXPORT
bool isNull()
const;
245 DLLEXPORT
bool isNullOrNothing()
const;
248 class ValueHolderBase {
257 DLLLOCAL ValueHolderBase(QoreValue n_v,
ExceptionSink* xs) : v(n_v), xsink(xs) {
261 DLLLOCAL QoreValue* operator->() {
return &v; }
264 DLLLOCAL QoreValue& operator*() {
return v; }
267 class ValueHolder :
public ValueHolderBase {
269 DLLLOCAL ValueHolder(
ExceptionSink* xs) : ValueHolderBase(xs) {
272 DLLLOCAL ValueHolder(QoreValue n_v,
ExceptionSink* xs) : ValueHolderBase(n_v, xs) {
275 DLLEXPORT ~ValueHolder();
281 DLLEXPORT QoreValue release();
283 DLLLOCAL QoreValue& operator=(QoreValue nv) {
290 DLLLOCAL
operator bool()
const {
291 return v.type == QV_Node && v.v.n;
295 class ValueOptionalRefHolder :
public ValueHolderBase {
298 DLLLOCAL QoreValue& operator=(QoreValue& nv);
303 DLLLOCAL ValueOptionalRefHolder(
ExceptionSink* xs) : ValueHolderBase(xs), needs_deref(false) {
307 DLLLOCAL ValueOptionalRefHolder(QoreValue n_v,
bool nd,
ExceptionSink* xs) : ValueHolderBase(n_v, xs), needs_deref(nd) {
310 DLLEXPORT ~ValueOptionalRefHolder();
313 DLLLOCAL
bool isTemp()
const {
return needs_deref; }
316 DLLLOCAL
void setTemp() {
322 DLLLOCAL
operator bool()
const {
323 return v.type == QV_Node && v.v.n;
327 DLLLOCAL
void setTemp(QoreValue nv) {
334 class ValueEvalRefHolder :
public ValueOptionalRefHolder {
343 DLLEXPORT
void ensureReferencedValue();
346 DLLLOCAL T* takeReferencedNode() {
360 if (v.type == QV_Node) {
362 return v.takeNodeIntern();
368 DLLLOCAL QoreValue takeValue(
bool& nd) {
369 if (v.type == QV_Node) {
371 return v.takeNodeIntern();
377 DLLEXPORT QoreValue takeReferencedValue();
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
static void discard(AbstractQoreNode *n, ExceptionSink *xsink)
to deref an AbstractQoreNode (when the pointer may be 0)
Definition: QoreLib.h:322
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
used in QoreValue::get()
Definition: QoreValue.h:60
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
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:228
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68