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
60 template<
typename Type>
61 struct QoreValueCastHelper {
62 typedef Type * Result;
65 static Result cast(QV *qv, valtype_t type) {
66 assert(type == QV_Node);
67 assert(dynamic_cast<Result>(qv->v.n));
68 return reinterpret_cast<Result
>(qv->v.n);
73 struct QoreValueCastHelper<bool> {
77 static bool cast(QV *qv, valtype_t type) {
78 return qv->getAsBool();
83 struct QoreValueCastHelper<double> {
84 typedef double Result;
87 static double cast(QV *qv, valtype_t type) {
88 return qv->getAsFloat();
93 struct QoreValueCastHelper<
int64> {
97 static double cast(QV *qv, valtype_t type) {
98 return qv->getAsBigInt();
103 struct QoreValueCastHelper<int> {
106 template<
typename QV>
107 static int cast(QV *qv, valtype_t type) {
108 return qv->getAsBigInt();
116 friend class ValueEvalRefHolder;
117 template<
typename>
friend struct detail::QoreValueCastHelper;
127 DLLEXPORT QoreValue();
129 DLLEXPORT QoreValue(
bool b);
131 DLLEXPORT QoreValue(
int64 i);
133 DLLEXPORT QoreValue(
double f);
139 DLLEXPORT QoreValue(
const QoreValue& old);
141 DLLEXPORT
void swap(QoreValue& val);
143 DLLEXPORT
bool getAsBool()
const;
145 DLLEXPORT
int64 getAsBigInt()
const;
147 DLLEXPORT
double getAsFloat()
const;
149 DLLEXPORT QoreValue refSelf()
const;
165 DLLEXPORT
bool isEqualSoft(
const QoreValue v,
ExceptionSink* xsink)
const;
166 DLLEXPORT
bool isEqualHard(
const QoreValue v)
const;
170 DLLEXPORT
void sanitize();
172 DLLEXPORT QoreValue& operator=(
const QoreValue& n);
174 DLLEXPORT
void clearNode();
184 assert(type == QV_Node);
185 assert(dynamic_cast<T*>(v.n));
186 T* rv =
reinterpret_cast<T*
>(v.n);
192 DLLLOCAL
typename detail::QoreValueCastHelper<T>::Result
get() {
193 return detail::QoreValueCastHelper<T>::cast(
this, type);
197 DLLLOCAL
typename detail::QoreValueCastHelper<const T>::Result
get()
const {
198 return detail::QoreValueCastHelper<const T>::cast(
this, type);
211 DLLEXPORT
const char* getTypeName()
const;
213 DLLEXPORT
bool hasNode()
const;
215 DLLEXPORT
bool isNothing()
const;
217 DLLEXPORT
bool isNull()
const;
219 DLLEXPORT
bool isNullOrNothing()
const;
222 class ValueHolderBase {
231 DLLLOCAL ValueHolderBase(QoreValue n_v,
ExceptionSink* xs) : v(n_v), xsink(xs) {
235 DLLLOCAL QoreValue* operator->() {
return &v; }
238 DLLLOCAL QoreValue& operator*() {
return v; }
241 class ValueHolder :
public ValueHolderBase {
243 DLLLOCAL ValueHolder(
ExceptionSink* xs) : ValueHolderBase(xs) {
246 DLLLOCAL ValueHolder(QoreValue n_v,
ExceptionSink* xs) : ValueHolderBase(n_v, xs) {
249 DLLEXPORT ~ValueHolder();
253 DLLLOCAL QoreValue& operator=(QoreValue nv) {
260 DLLLOCAL
operator bool()
const {
261 return v.type == QV_Node && v.v.n;
265 class ValueOptionalRefHolder :
public ValueHolderBase {
269 DLLLOCAL ValueOptionalRefHolder(
ExceptionSink* xs) : ValueHolderBase(xs), needs_deref(false) {
273 DLLLOCAL QoreValue& operator=(QoreValue& nv);
276 DLLLOCAL ValueOptionalRefHolder(QoreValue n_v,
bool nd,
ExceptionSink* xs) : ValueHolderBase(n_v, xs), needs_deref(nd) {
279 DLLEXPORT ~ValueOptionalRefHolder();
282 DLLLOCAL
bool isTemp()
const {
return needs_deref; }
285 class ValueEvalRefHolder :
public ValueOptionalRefHolder {
292 DLLLOCAL T* takeReferencedNode() {
306 if (v.type == QV_Node) {
308 return v.takeNodeIntern();
314 DLLLOCAL QoreValue takeValue(
bool& nd) {
315 if (v.type == QV_Node) {
317 return v.takeNodeIntern();
323 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:312
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:50
Definition: QoreValue.h:58
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:225
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68