00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _QORE_QORENODEEVALOPTIONALREFHOLDER_H
00024
00025 #define _QORE_QORENODEEVALOPTIONALREFHOLDER_H
00026
00028
00036 class QoreNodeEvalOptionalRefHolder {
00037 private:
00038 AbstractQoreNode *val;
00039 ExceptionSink *xsink;
00040 bool needs_deref;
00041
00042 DLLLOCAL void discard_intern() {
00043 if (needs_deref && val)
00044 val->deref(xsink);
00045 }
00046
00048 DLLLOCAL QoreNodeEvalOptionalRefHolder(const QoreNodeEvalOptionalRefHolder&);
00049
00051 DLLLOCAL QoreNodeEvalOptionalRefHolder& operator=(const QoreNodeEvalOptionalRefHolder&);
00052
00054
00056 DLLLOCAL void *operator new(size_t);
00057
00058 public:
00060 DLLLOCAL QoreNodeEvalOptionalRefHolder(ExceptionSink *n_xsink) : val(0), xsink(n_xsink), needs_deref(false) {
00061 }
00062
00064 DLLLOCAL QoreNodeEvalOptionalRefHolder(const AbstractQoreNode *exp, ExceptionSink *n_xsink) : xsink(n_xsink) {
00065 if (exp)
00066 val = exp->eval(needs_deref, xsink);
00067 else {
00068 val = 0;
00069 needs_deref = false;
00070 }
00071 }
00072
00074 DLLLOCAL ~QoreNodeEvalOptionalRefHolder() {
00075 discard_intern();
00076 }
00077
00079 DLLLOCAL void discard() {
00080 discard_intern();
00081 needs_deref = false;
00082 val = 0;
00083 }
00084
00086 DLLLOCAL void assign(bool n_needs_deref, AbstractQoreNode *n_val) {
00087 discard_intern();
00088 needs_deref = n_needs_deref;
00089 val = n_val;
00090 }
00091
00093 DLLLOCAL AbstractQoreNode *getReferencedValue() {
00094 if (needs_deref)
00095 needs_deref = false;
00096 else if (val)
00097 val->ref();
00098 return val;
00099 }
00100
00102 DLLLOCAL const AbstractQoreNode *operator->() const { return val; }
00103
00105 DLLLOCAL const AbstractQoreNode *operator*() const { return val; }
00106
00108 DLLLOCAL operator bool() const { return val != 0; }
00109
00111 DLLLOCAL bool isTemp() const { return needs_deref; }
00112
00113 };
00114
00115 #endif