helper class to manage variable references passed to functions and class methods, stack only, cannot be dynamically allocated
More...
#include <QoreTypeSafeReferenceHelper.h>
helper class to manage variable references passed to functions and class methods, stack only, cannot be dynamically allocated
Takes care of safely accessing ReferenceNode objects, for example when they are passed as arguments to a builtin function or method. Locks are automatically acquired in the constructor if necessary and released in the destructor. The constructor could raise a Qore-language exception if there is a deadlock acquiring any locks to access the ReferenceNode's value as given by the lvalue expression, so the object should be checked for this state right after the constructor as in the following example:
initializes the object and tries to get the pointer to the pointer of the lvalue expression target
- Parameters
-
ref | the ReferenceNode to use |
xsink | Qore-language exceptions raised will be added here (for example, a deadlock accessing the object) |
initializes the object and tries to get the pointer to the pointer of the lvalue expression target
- Parameters
-
ref | the ReferenceNode to use |
vl | this argument is ignored in this deprecated version of the function |
xsink | Qore-language exceptions raised will be added here (for example, a deadlock accessing the object) |
- Deprecated:
- the AutoVLock argument is ignored in this deprecated version
assigns a value to the reference, assumes the reference is valid
- Parameters
-
val | the value to assign (must be already referenced for the assignment) |
- Returns
- 0 if there was no error and the variable was assigned, -1 if a Qore-language exception occured dereferencing the current value, in this case no assignment was made and the reference count for val is dereferenced automatically by the QoreTypeSafeReferenceHelper object
- Note
- you must check that the reference is valid before calling this function
if (!rh)
return;
rh.assign(val->refSelf());
assigns a value to the reference, assumes the reference is valid
- Parameters
-
val | the value to assign (must be already referenced for the assignment) |
xsink | this argument is ignored; the ExceptionSink argument used in the constructor is used instead |
- Returns
- 0 if there was no error and the variable was assigned, -1 if a Qore-language exception occured dereferencing the current value, in this case no assignment was made and the reference count for val is dereferenced automatically by the QoreTypeSafeReferenceHelper object
- Note
- you must check that the reference is valid before calling this function
if (!rh)
return;
rh.assign(val->refSelf());
- Deprecated:
- use QoreTypeSafeReferenceHelper::assign(AbstractQoreNode *val) instead
DLLEXPORT int QoreTypeSafeReferenceHelper::assignBigInt |
( |
int64 |
v | ) |
|
assigns an integer value to the reference
- Parameters
-
- Returns
- 0 if there was no error and the variable was assigned, -1 if a Qore-language exception occured dereferencing the current value, in this case no assignment was made
DLLEXPORT int QoreTypeSafeReferenceHelper::assignFloat |
( |
double |
v | ) |
|
assigns an integer value to the reference
- Parameters
-
- Returns
- 0 if there was no error and the variable was assigned, -1 if a Qore-language exception occured dereferencing the current value, in this case no assignment was made
DLLEXPORT qore_type_t QoreTypeSafeReferenceHelper::getType |
( |
| ) |
const |
returns the type of the reference's value
- Returns
- the type of the reference's value
DLLEXPORT const char* QoreTypeSafeReferenceHelper::getTypeName |
( |
| ) |
const |
returns the type name of the reference's value
- Returns
- the type name of the reference's value
returns a pointer to the value with a unique reference count (so it can be updated in place), assumes the reference is valid
- Parameters
-
- Returns
- a pointer to the reference's value with a unique reference count (so it can be modified), or 0 if the value was 0 to start with or if a Qore-language exception was raised
- Note
- you must check that the reference is valid before calling this function
-
take care to only call this function on types where the AbstractQoreNode::realCopy() function has a valid implementation (on all value types suitable for in-place modification this function has a valid implementation), as in debugging builds other types will abort(); in non-debugging builds this function will simply do nothing
if (!rh)
return;
if (*xsink)
return;
DLLEXPORT const AbstractQoreNode* QoreTypeSafeReferenceHelper::getValue |
( |
| ) |
const |
returns a constant pointer to the reference's value
- Returns
- the value of the lvalue reference (may be 0)
DLLEXPORT QoreTypeSafeReferenceHelper::operator bool |
( |
| ) |
const |
returns true if the reference is valid, false if not
false will only be returned if a Qore-language exception was raised in the constructor
The documentation for this class was generated from the following file: