params.h
Go to the documentation of this file.
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
params.h
Qore Programming Language
Copyright (C) 2003 - 2018 Qore Technologies, s.r.o.
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_PARAMS_H
#define _QORE_PARAMS_H
#include <qore/AbstractQoreNode.h>
static inline unsigned num_args(const QoreListNode* n) {
return n ? (unsigned)n->size() : 0;
}
static inline unsigned num_params(const QoreListNode* n) {
return n ? (unsigned)n->size() : 0;
}
static inline const ReferenceNode* test_reference_param(const QoreListNode* n, size_t i) {
if (!n) return nullptr;
QoreValue p = n->retrieveEntry(i);
// the following is faster than a dynamic_cast
return p.getType() == NT_REFERENCE ? p.get<const ReferenceNode>() : nullptr;
}
static inline QoreValue get_param_value(const QoreListNode* n, size_t i) {
if (!n)
return QoreValue();
return n->retrieveEntry(i);
}
template <typename T>
static inline T* get_hard_value_or_nothing_param(const QoreListNode* n, size_t i) {
assert(n);
return n->retrieveEntry(i).get<T>();
}
static QoreValue get_hard_value_param(const QoreListNode* n, size_t i) {
assert(n);
return n->retrieveEntry(i);
}
#define HARD_QORE_VALUE_OR_NOTHING_PARAM(name, Type, list, i) Type* name = get_hard_value_or_nothing_param<Type>(list, i)
#define HARD_QORE_VALUE_PARAM(name, Type, list, i) Type* name = get_hard_value_param(list, i).get<Type>()
#define HARD_QORE_VALUE_INT(list, i) get_hard_value_param(list, i).getAsBigInt()
#define HARD_QORE_VALUE_FLOAT(list, i) get_hard_value_param(list, i).getAsFloat()
#define HARD_QORE_VALUE_NUMBER(list, i) get_hard_value_param(list, i).get<const QoreNumberNode>()
#define HARD_QORE_VALUE_BOOL(list, i) get_hard_value_param(list, i).getAsBool()
#define HARD_QORE_VALUE_STRING(list, i) get_hard_value_param(list, i).get<const QoreStringNode>()
#define HARD_QORE_VALUE_DATE(list, i) get_hard_value_param(list, i).get<const DateTimeNode>()
#define HARD_QORE_VALUE_BINARY(list, i) get_hard_value_param(list, i).get<const BinaryNode>()
#define HARD_QORE_VALUE_LIST(list, i) get_hard_value_param(list, i).get<const QoreListNode>()
#define HARD_QORE_VALUE_HASH(list, i) get_hard_value_param(list, i).get<const QoreHashNode>()
#define HARD_QORE_VALUE_REF(list, i) get_hard_value_param(list, i).get<const ReferenceNode>()
#define HARD_QORE_VALUE_OBJECT(list, i) const_cast<QoreObject*>(get_hard_value_param(list, i).get<const QoreObject>())
#define HARD_QORE_VALUE_OBJ_DATA(vname, Type, list, i, cid, dname, cname, xsink) HARD_QORE_VALUE_PARAM(obj_##vname, const QoreObject, list, i); Type* vname = reinterpret_cast<Type*>(obj_##vname->getReferencedPrivateData(cid, xsink)); if (!vname && !*xsink) xsink->raiseException("OBJECT-ALREADY-DELETED", "cannot complete call setup to %s() because parameter %d (<class %s>) has already been deleted", cname, i + 1, dname)
#define TAKE_HARD_QORE_VALUE_OBJ_DATA(vname, Type, list, i, cid, dname, cname, xsink) HARD_QORE_VALUE_PARAM(obj_##vname, const QoreObject, list, i); Type* vname = reinterpret_cast<Type*>(const_cast<QoreObject*>(obj_##vname)->getAndClearPrivateData(cid, xsink)); if (!vname && !*xsink) xsink->raiseException("OBJECT-ALREADY-DELETED", "cannot complete call setup to %s() because parameter %d (<class %s>) has already been deleted", cname, i + 1, dname); else if (vname) const_cast<QoreObject*>(obj_##vname)->doDelete(xsink)
#define HARD_QORE_VALUE_OBJ_OR_NOTHING_DATA(vname, Type, list, i, cid, xsink) HARD_QORE_VALUE_OR_NOTHING_PARAM(obj_##vname, const QoreObject, list, i); Type* vname = obj_##vname ? reinterpret_cast<Type*>(obj_##vname->getReferencedPrivateData(cid, xsink)) : 0;
static inline const QoreEncoding* get_value_encoding_param(const QoreListNode* n, size_t i, const QoreEncoding* def = QCS_DEFAULT) {
const QoreStringNode* str = HARD_QORE_VALUE_STRING(n, i);
return str ? QEM.findCreate(str) : def;
}
static inline const QoreEncoding* get_hard_qore_value_encoding_param(const QoreListNode* n, size_t i) {
HARD_QORE_VALUE_PARAM(str, const QoreStringNode, n, i);
return QEM.findCreate(str);
}
#endif
get_param_value
static QoreValue get_param_value(const QoreListNode *n, size_t i)
returns the argument in the position given or 0 if there is none
Definition: params.h:78
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
test_reference_param
static const ReferenceNode * test_reference_param(const QoreListNode *n, size_t i)
returns a ReferenceNode pointer for the argument position given or 0 if there is no argument there or...
Definition: params.h:65
QCS_DEFAULT
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
get_hard_value_or_nothing_param
static T * get_hard_value_or_nothing_param(const QoreListNode *n, size_t i)
returns the given type for hard typed parameters
Definition: params.h:86
QoreListNode::retrieveEntry
DLLEXPORT QoreValue retrieveEntry(size_t index)
returns the element at "index" (first element is index 0)
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
num_args
static unsigned num_args(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:46
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QEM
DLLEXPORT QoreEncodingManager QEM
the QoreEncodingManager object
QoreListNode::size
DLLEXPORT size_t size() const
returns the number of elements in the list
ReferenceNode
parse type: reference to a lvalue expression
Definition: ReferenceNode.h:45
get_hard_value_param
static QoreValue get_hard_value_param(const QoreListNode *n, size_t i)
returns the given type for hard typed parameters
Definition: params.h:92
NT_REFERENCE
const qore_type_t NT_REFERENCE
type value for ReferenceNode
Definition: node_types.h:64
QoreEncodingManager::findCreate
static DLLEXPORT const QoreEncoding * findCreate(const char *name)
finds an encoding if it exists (also looks up against alias names) and creates a new one if it doesn&#39;...
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
num_params
static unsigned num_params(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:54
HARD_QORE_VALUE_PARAM
#define HARD_QORE_VALUE_PARAM(name, Type, list, i)
returns a hard typed parameter
Definition: params.h:101
HARD_QORE_VALUE_STRING
#define HARD_QORE_VALUE_STRING(list, i)
returns a const QoreStringNode* from a hard typed string param
Definition: params.h:116
get_value_encoding_param
static const QoreEncoding * get_value_encoding_param(const QoreListNode *n, size_t i, const QoreEncoding *def=QCS_DEFAULT)
returns the QoreEncoding corresponding to the string passed or a default encoding ...
Definition: params.h:146