Qore Programming Language - C/C++ Library  0.8.13.8
ReferenceArgumentHelper.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  ReferenceArgumentHelper.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2017 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_REFERENCEARGUMENTHELPER_H
33 
34 #define _QORE_REFERENCEARGUMENTHELPER_H
35 
37 
59 private:
60  struct lvih_intern *priv;
61 
64 
66  DLLLOCAL ReferenceArgumentHelper& operator=(const ReferenceArgumentHelper&);
67 
68 public:
70 
76  DLLEXPORT ReferenceArgumentHelper(QoreValue val, ExceptionSink* xsink);
77 
78  // creates a fake local variable assigned to "val" and creates a reference to the local variable
79  /*
80  @param val the value to assign to the local variable
81  @param xsink this value is saved to be used for dereferencing the fake local variable in the destructor
82  */
83  //DLLEXPORT ReferenceArgumentHelper(AbstractQoreNode* val, ExceptionSink* xsink);
84  // creates a fake local variable assigned to "val" and creates a reference to the local variable
85  /*
86  @param val the value to assign to the local variable
87  @param typeInfo the type restriction for the lvalue
88  @param xsink this value is saved to be used for dereferencing the fake local variable in the destructor
89  @since %Qore 0.8.13
90 
91  Warning using this constructor may lead to memory leak when value is changed in Qore script. Problem is
92  when AbstractQoreNode is created and assigned to helper then QoreValue is taken but original reference in node
93  is not dereferenced. So when is AbstractQoreNode is to be destroyed then destroys invalid QoreValue which has been
94  destroyed is script. The other option is to leave AbstractQoreNode referenced but it causes memory leak.
95 
96  @code
97  // wrong
98  QoreBigIntNode *rc = new QoreBigIntNode(retCode); // 48 bytes in 2 blocks are definitely lost in loss record .... allocated here by: operator new(unsigned long)
99  ReferenceArgumentHelper rah(rc, &xsink2);
100 
101  // correct
102  ReferenceArgumentHelper rah(retCode, &xsink2);
103  @endcode
104 
105  */
106  //DLLEXPORT ReferenceArgumentHelper(AbstractQoreNode* val, const QoreTypeInfo* typeInfo, ExceptionSink* xsink);
107 
109  DLLEXPORT ~ReferenceArgumentHelper();
110 
112 
114  DLLEXPORT AbstractQoreNode* getArg() const;
115 
117 
119  DLLEXPORT AbstractQoreNode *getOutputValue();
120 
122 
126  DLLEXPORT QoreValue getOutputQoreValue();
127 };
128 
129 #endif
DLLEXPORT AbstractQoreNode * getArg() const
returns the reference to the fake local variable for use in an argument list, the caller owns the ref...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
allows a reference to be passed as an argument to Qore code
Definition: ReferenceArgumentHelper.h:58
DLLEXPORT AbstractQoreNode * getOutputValue()
returns the value of the reference and leaves the reference empty, the caller owns the reference retu...
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
DLLEXPORT QoreValue getOutputQoreValue()
returns the value of the reference and leaves the reference empty, the caller owns the reference retu...
DLLEXPORT ~ReferenceArgumentHelper()
frees all memory still managed by the object