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 (C) 2003 - 2015 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#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
QoreNodeEvalOptionalRefHolder::assign
DLLLOCAL void assign(bool n_needs_deref, AbstractQoreNode *n_val)
assigns a new value to this holder object
Definition: QoreNodeEvalOptionalRefHolder.h:95
QoreNodeEvalOptionalRefHolder::operator*
DLLLOCAL const AbstractQoreNode * operator*() const
returns the object being managed
Definition: QoreNodeEvalOptionalRefHolder.h:114
AbstractQoreNode::eval
DLLEXPORT AbstractQoreNode * eval(ExceptionSink *xsink) const
evaluates the object and returns a value (or 0)
QoreNodeEvalOptionalRefHolder::discard
DLLLOCAL void discard()
discards any temporary value evaluated by the constructor or assigned by &quot;assign()&quot; ...
Definition: QoreNodeEvalOptionalRefHolder.h:88
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
QoreNodeEvalOptionalRefHolder::QoreNodeEvalOptionalRefHolder
DLLLOCAL QoreNodeEvalOptionalRefHolder(ExceptionSink *n_xsink)
constructor used to create a holder object
Definition: QoreNodeEvalOptionalRefHolder.h:69
AbstractQoreNode::ref
DLLEXPORT void ref() const
increments the reference count
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:43
AbstractQoreNode::deref
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing
QoreNodeEvalOptionalRefHolder::operator->
DLLLOCAL const AbstractQoreNode * operator->() const
returns the object being managed
Definition: QoreNodeEvalOptionalRefHolder.h:111
QoreNodeEvalOptionalRefHolder::QoreNodeEvalOptionalRefHolder
DLLLOCAL QoreNodeEvalOptionalRefHolder(const AbstractQoreNode *exp, ExceptionSink *n_xsink)
constructor with a value that will call the class&#39; eval(needs_deref) method
Definition: QoreNodeEvalOptionalRefHolder.h:73
QoreNodeEvalOptionalRefHolder::getReferencedValue
DLLLOCAL AbstractQoreNode * getReferencedValue()
returns a referenced value - the caller will own the reference
Definition: QoreNodeEvalOptionalRefHolder.h:102
QoreNodeEvalOptionalRefHolder::~QoreNodeEvalOptionalRefHolder
DLLLOCAL ~QoreNodeEvalOptionalRefHolder()
discards any temporary value evaluated by the constructor or assigned by &quot;assign()&quot; ...
Definition: QoreNodeEvalOptionalRefHolder.h:83
QoreNodeEvalOptionalRefHolder
this class manages reference counts for the optional evaluation of AbstractQoreNode objects ...
Definition: QoreNodeEvalOptionalRefHolder.h:45
QoreNodeEvalOptionalRefHolder::isTemp
DLLLOCAL bool isTemp() const
returns true if the value is temporary (needs dereferencing)
Definition: QoreNodeEvalOptionalRefHolder.h:120