Qore Programming Language: include/qore/QoreNodeEvalOptionalRefHolder.h (6585) Source File

Qore Programming Language 0.8.11

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreNodeEvalOptionalRefHolder.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreNodeEvalOptionalRefHolder.h
4
5 Qore Programming Language
6
7 Copyright 2003 - 2013 David Nichols
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _QORE_QORENODEEVALOPTIONALREFHOLDER_H
25
26 #define _QORE_QORENODEEVALOPTIONALREFHOLDER_H
27
29
37 class QoreNodeEvalOptionalRefHolder {
38 private:
39 AbstractQoreNode *val;
40 ExceptionSink *xsink;
41 bool needs_deref;
42
43 DLLLOCAL void discard_intern() {
44 if (needs_deref && val)
45 val->deref(xsink);
46 }
47
49 DLLLOCAL QoreNodeEvalOptionalRefHolder(const QoreNodeEvalOptionalRefHolder&);
50
52 DLLLOCAL QoreNodeEvalOptionalRefHolder& operator=(const QoreNodeEvalOptionalRefHolder&);
53
55
57 DLLLOCAL void *operator new(size_t);
58
59 public:
61 DLLLOCAL QoreNodeEvalOptionalRefHolder(ExceptionSink *n_xsink) : val(0), xsink(n_xsink), needs_deref(false) {
62 }
63
65 DLLLOCAL QoreNodeEvalOptionalRefHolder(const AbstractQoreNode *exp, ExceptionSink *n_xsink) : xsink(n_xsink) {
66 if (exp)
67 val = exp->eval(needs_deref, xsink);
68 else {
69 val = 0;
70 needs_deref = false;
71 }
72 }
73
75 DLLLOCAL ~QoreNodeEvalOptionalRefHolder() {
76 discard_intern();
77 }
78
80 DLLLOCAL void discard() {
81 discard_intern();
82 needs_deref = false;
83 val = 0;
84 }
85
87 DLLLOCAL void assign(bool n_needs_deref, AbstractQoreNode *n_val) {
88 discard_intern();
89 needs_deref = n_needs_deref;
90 val = n_val;
91 }
92
94 DLLLOCAL AbstractQoreNode *getReferencedValue() {
95 if (needs_deref)
96 needs_deref = false;
97 else if (val)
98 val->ref();
99 return val;
100 }
101
103 DLLLOCAL const AbstractQoreNode *operator->() const { return val; }
104
106 DLLLOCAL const AbstractQoreNode *operator*() const { return val; }
107
109 DLLLOCAL operator bool() const { return val != 0; }
110
112 DLLLOCAL bool isTemp() const { return needs_deref; }
113
114 };
115
116 #endif
QoreNodeEvalOptionalRefHolder::assign
DLLLOCAL void assign(bool n_needs_deref, AbstractQoreNode *n_val)
assigns a new value to this holder object
Definition: QoreNodeEvalOptionalRefHolder.h:87
QoreNodeEvalOptionalRefHolder::operator*
DLLLOCAL const AbstractQoreNode * operator*() const
returns the object being managed
Definition: QoreNodeEvalOptionalRefHolder.h:106
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 "assign()" ...
Definition: QoreNodeEvalOptionalRefHolder.h:80
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
QoreNodeEvalOptionalRefHolder::QoreNodeEvalOptionalRefHolder
DLLLOCAL QoreNodeEvalOptionalRefHolder(ExceptionSink *n_xsink)
constructor used to create a holder object
Definition: QoreNodeEvalOptionalRefHolder.h:61
AbstractQoreNode::ref
DLLEXPORT void ref() const
increments the reference count
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:35
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:103
QoreNodeEvalOptionalRefHolder::QoreNodeEvalOptionalRefHolder
DLLLOCAL QoreNodeEvalOptionalRefHolder(const AbstractQoreNode *exp, ExceptionSink *n_xsink)
constructor with a value that will call the class' eval(needs_deref) method
Definition: QoreNodeEvalOptionalRefHolder.h:65
QoreNodeEvalOptionalRefHolder::getReferencedValue
DLLLOCAL AbstractQoreNode * getReferencedValue()
returns a referenced value - the caller will own the reference
Definition: QoreNodeEvalOptionalRefHolder.h:94
QoreNodeEvalOptionalRefHolder::~QoreNodeEvalOptionalRefHolder
DLLLOCAL ~QoreNodeEvalOptionalRefHolder()
discards any temporary value evaluated by the constructor or assigned by "assign()" ...
Definition: QoreNodeEvalOptionalRefHolder.h:75
QoreNodeEvalOptionalRefHolder
this class manages reference counts for the optional evaluation of AbstractQoreNode objects ...
Definition: QoreNodeEvalOptionalRefHolder.h:37
QoreNodeEvalOptionalRefHolder::isTemp
DLLLOCAL bool isTemp() const
returns true if the value is temporary (needs dereferencing)
Definition: QoreNodeEvalOptionalRefHolder.h:112