Qore Programming Language  1.7.0
ReferenceArgumentHelper Class Reference

allows a reference to be passed as an argument to Qore code More...

#include <ReferenceArgumentHelper.h>

Public Member Methods

DLLEXPORT ReferenceArgumentHelper (QoreValue val, const QoreTypeInfo *typeInfo, ExceptionSink *xsink)
 creates a fake local variable assigned to "val" and creates a reference to the local variable More...
 
DLLEXPORT ReferenceArgumentHelper (QoreValue val, ExceptionSink *xsink)
 creates a fake local variable assigned to "val" and creates a reference to the local variable More...
 
DLLEXPORT ~ReferenceArgumentHelper ()
 frees all memory still managed by the object
 
DLLEXPORT ReferenceNodegetArg () const
 returns the reference to the fake local variable for use in an argument list, the caller owns the reference returned More...
 
DLLEXPORT QoreValue getOutputValue ()
 returns the value of the reference and leaves the reference empty, the caller owns the reference returned More...
 

Detailed Description

allows a reference to be passed as an argument to Qore code

this class creates a fake local variable and then creates a reference the local variable that can be used in an argument list to be passed to a function. Then the ReferenceArgumentHelper::getOutputValue() function can be called to retrieve the value of the local variable after the Qore-language code has been executed. This allows values to be passed by reference to Qore-language code and then the value of the variable read back out and processed.

// create an argument list
ReferenceHolder<QoreListNode> args(new QoreListNode(autoTypeInfo), &xsink);
// instantiate "val" as a reference as the only argument in the argument list
ReferenceArgumentHelper lvh(val, &xsink);
args->push(lvh.getArg());
// execute method "m_fixup" and discard any return value
discard(m_fixup->eval(qore_obj, *args, &xsink), &xsink);
// return the value of the reference after executing the method
return lvh.getOutputValue();
static void discard(AbstractQoreNode *n, ExceptionSink *xsink)
to deref an AbstractQoreNode (when the pointer may be 0)
Definition: QoreLib.h:324
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
allows a reference to be passed as an argument to Qore code
Definition: ReferenceArgumentHelper.h:58

Constructor & Destructor Documentation

◆ ReferenceArgumentHelper() [1/2]

DLLEXPORT ReferenceArgumentHelper::ReferenceArgumentHelper ( QoreValue  val,
ExceptionSink xsink 
)

creates a fake local variable assigned to "val" and creates a reference to the local variable

Parameters
valthe value to assign to the local variable
xsinkthis value is saved to be used for dereferencing the fake local variable in the destructor
// incorrect - MEMORY LEAK!
ReferenceArgumentHelper rah(new QoreHashNode(autoTypeInfo), &xsink2);
// correct
ValueHolder holder(new QoreHashNode(autoTypeInfo), &xsink2);
ReferenceArgumentHelper rah(*holder, &xsink2);
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
holds an object and dereferences it in the destructor
Definition: QoreValue.h:476

◆ ReferenceArgumentHelper() [2/2]

DLLEXPORT ReferenceArgumentHelper::ReferenceArgumentHelper ( QoreValue  val,
const QoreTypeInfo *  typeInfo,
ExceptionSink xsink 
)

creates a fake local variable assigned to "val" and creates a reference to the local variable

Parameters
valthe value to assign to the local variable
typeInfotype information for the lvalue
xsinkthis value is saved to be used for dereferencing the fake local variable in the destructor
// incorrect - MEMORY LEAK!
ReferenceArgumentHelper rah(new QoreHashNode(autoTypeInfo), autoHashTypeInfo, &xsink2);
// correct
ValueHolder holder(new QoreHashNode(autoTypeInfo), &xsink2);
ReferenceArgumentHelper rah(*holder, autoHashTypeInfo, &xsink2);

Member Function Documentation

◆ getArg()

DLLEXPORT ReferenceNode* ReferenceArgumentHelper::getArg ( ) const

returns the reference to the fake local variable for use in an argument list, the caller owns the reference returned

Returns
the reference to the fake local variable for use in an argument list, the caller owns the reference returned

◆ getOutputValue()

DLLEXPORT QoreValue ReferenceArgumentHelper::getOutputValue ( )

returns the value of the reference and leaves the reference empty, the caller owns the reference returned

Returns
the value of the reference and leaves the reference empty, the caller owns the reference returned

The documentation for this class was generated from the following file: