All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreNodeEvalOptionalRefHolder.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreNodeEvalOptionalRefHolder.h
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QORENODEEVALOPTIONALREFHOLDER_H
#define _QORE_QORENODEEVALOPTIONALREFHOLDER_H
class QoreNodeEvalOptionalRefHolder {
private:
AbstractQoreNode *val;
ExceptionSink *xsink;
bool needs_deref;
DLLLOCAL void discard_intern() {
if (needs_deref && val)
val->deref(xsink);
}
DLLLOCAL QoreNodeEvalOptionalRefHolder(const QoreNodeEvalOptionalRefHolder&);
DLLLOCAL QoreNodeEvalOptionalRefHolder& operator=(const QoreNodeEvalOptionalRefHolder&);
DLLLOCAL void *operator new(size_t);
public:
DLLLOCAL QoreNodeEvalOptionalRefHolder(ExceptionSink *n_xsink) : val(0), xsink(n_xsink), needs_deref(false) {
}
DLLLOCAL QoreNodeEvalOptionalRefHolder(const AbstractQoreNode *exp, ExceptionSink *n_xsink) : xsink(n_xsink) {
if (exp)
val = exp->eval(needs_deref, xsink);
else {
val = 0;
needs_deref = false;
}
}
DLLLOCAL ~QoreNodeEvalOptionalRefHolder() {
discard_intern();
}
DLLLOCAL void discard() {
discard_intern();
needs_deref = false;
val = 0;
}
DLLLOCAL void assign(bool n_needs_deref, AbstractQoreNode *n_val) {
discard_intern();
needs_deref = n_needs_deref;
val = n_val;
}
DLLLOCAL AbstractQoreNode *getReferencedValue() {
if (needs_deref)
needs_deref = false;
else if (val)
val->ref();
return val;
}
DLLLOCAL const AbstractQoreNode *operator->() const { return val; }
DLLLOCAL const AbstractQoreNode *operator*() const { return val; }
DLLLOCAL operator bool() const { return val != 0; }
DLLLOCAL bool isTemp() const { return needs_deref; }
};
#endif