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 {
00044 if (needs_deref && val)
00045 val->deref(xsink);
00046 }
00047
00049 DLLLOCAL QoreNodeEvalOptionalRefHolder(const QoreNodeEvalOptionalRefHolder&);
00050
00052 DLLLOCAL QoreNodeEvalOptionalRefHolder& operator=(const QoreNodeEvalOptionalRefHolder&);
00053
00055
00057 DLLLOCAL void *operator new(size_t);
00058
00059 public:
00061 DLLLOCAL QoreNodeEvalOptionalRefHolder(ExceptionSink *n_xsink) : val(0), xsink(n_xsink), needs_deref(false)
00062 {
00063 }
00064
00066 DLLLOCAL QoreNodeEvalOptionalRefHolder(const AbstractQoreNode *exp, ExceptionSink *n_xsink) : xsink(n_xsink)
00067 {
00068 if (exp)
00069 val = exp->eval(needs_deref, xsink);
00070 else {
00071 val = 0;
00072 needs_deref = false;
00073 }
00074 }
00075
00077 DLLLOCAL ~QoreNodeEvalOptionalRefHolder()
00078 {
00079 discard_intern();
00080 }
00081
00083 DLLLOCAL void discard()
00084 {
00085 discard_intern();
00086 needs_deref = false;
00087 val = 0;
00088 }
00089
00091 DLLLOCAL void assign(bool n_needs_deref, AbstractQoreNode *n_val)
00092 {
00093 discard_intern();
00094 needs_deref = n_needs_deref;
00095 val = n_val;
00096 }
00097
00099 DLLLOCAL AbstractQoreNode *getReferencedValue()
00100 {
00101 if (needs_deref)
00102 needs_deref = false;
00103 else if (val)
00104 val->ref();
00105 return val;
00106 }
00107
00109 DLLLOCAL const AbstractQoreNode *operator->() const { return val; }
00110
00112 DLLLOCAL const AbstractQoreNode *operator*() const { return val; }
00113
00115 DLLLOCAL operator bool() const { return val != 0; }
00116 };
00117
00118 #endif