00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _QORE_PARAMS_H
00025
00026 #define _QORE_PARAMS_H
00027
00028 #include <qore/AbstractQoreNode.h>
00029
00034
00035
00038 static inline unsigned num_args(const QoreListNode *n) {
00039 return n ? (unsigned)n->size() : 0;
00040 }
00041
00043
00046 static inline unsigned num_params(const QoreListNode *n) {
00047 return n ? (unsigned)n->size() : 0;
00048 }
00049
00051
00056 static inline const AbstractQoreNode *get_param(const QoreListNode *n, qore_size_t i) {
00057 if (!n) return 0;
00058 const AbstractQoreNode *p = n->retrieve_entry(i);
00059 return is_nothing(p) ? 0 : p;
00060 }
00061
00063
00068 static inline qore_type_t get_param_type(const QoreListNode *n, qore_size_t i) {
00069 if (!n) return NT_NOTHING;
00070 const AbstractQoreNode *p = n->retrieve_entry(i);
00071 return p ? p->getType() : NT_NOTHING;
00072 }
00073
00075 static inline int get_int_param(const QoreListNode *n, qore_size_t i) {
00076 if (!n) return 0;
00077 const AbstractQoreNode *p = n->retrieve_entry(i);
00078 return is_nothing(p) ? 0 : p->getAsInt();
00079 }
00080
00082 static inline int64 get_bigint_param(const QoreListNode *n, qore_size_t i) {
00083 if (!n) return 0;
00084 const AbstractQoreNode *p = n->retrieve_entry(i);
00085 return is_nothing(p) ? 0 : p->getAsBigInt();
00086 }
00087
00089 static inline int get_int_param_with_default(const QoreListNode *n, qore_size_t i, int def) {
00090 if (!n) return def;
00091 const AbstractQoreNode *p = n->retrieve_entry(i);
00092 return is_nothing(p) ? def : p->getAsInt();
00093 }
00094
00096 static inline int64 get_bigint_param_with_default(const QoreListNode *n, qore_size_t i, int64 def) {
00097 if (!n) return def;
00098 const AbstractQoreNode *p = n->retrieve_entry(i);
00099 return is_nothing(p) ? def : p->getAsBigInt();
00100 }
00101
00103 static inline double get_float_param(const QoreListNode *n, qore_size_t i) {
00104 if (!n) return 0;
00105 const AbstractQoreNode *p = n->retrieve_entry(i);
00106 return is_nothing(p) ? 0 : p->getAsFloat();
00107 }
00108
00110 static inline bool get_bool_param(const QoreListNode *n, qore_size_t i) {
00111 if (!n) return 0;
00112 const AbstractQoreNode *p = n->retrieve_entry(i);
00113 return is_nothing(p) ? false : p->getAsBool();
00114 }
00115
00117
00122 static inline const BinaryNode *test_binary_param(const QoreListNode *n, qore_size_t i) {
00123 if (!n) return 0;
00124 const AbstractQoreNode *p = n->retrieve_entry(i);
00125
00126 return p && p->getType() == NT_BINARY ? reinterpret_cast<const BinaryNode *>(p) : 0;
00127 }
00128
00130
00135 static inline const QoreStringNode *test_string_param(const QoreListNode *n, qore_size_t i) {
00136 if (!n) return 0;
00137 const AbstractQoreNode *p = n->retrieve_entry(i);
00138
00139 return p && p->getType() == NT_STRING ? reinterpret_cast<const QoreStringNode *>(p) : 0;
00140 }
00141
00143
00148 static inline QoreObject *test_object_param(const QoreListNode *n, qore_size_t i) {
00149 if (!n) return 0;
00150 const AbstractQoreNode *p = n->retrieve_entry(i);
00151
00152 return p && p->getType() == NT_OBJECT ? const_cast<QoreObject *>(reinterpret_cast<const QoreObject *>(p)) : 0;
00153 }
00154
00156
00161 static inline const DateTimeNode *test_date_param(const QoreListNode *n, qore_size_t i) {
00162 if (!n) return 0;
00163 const AbstractQoreNode *p = n->retrieve_entry(i);
00164
00165 return p && p->getType() == NT_DATE ? reinterpret_cast<const DateTimeNode *>(p) : 0;
00166 }
00167
00169
00174 static inline const QoreHashNode *test_hash_param(const QoreListNode *n, qore_size_t i) {
00175 if (!n) return 0;
00176 const AbstractQoreNode *p = n->retrieve_entry(i);
00177
00178 return p && p->getType() == NT_HASH ? reinterpret_cast<const QoreHashNode *>(p) : 0;
00179 }
00180
00182
00187 static inline const QoreListNode *test_list_param(const QoreListNode *n, qore_size_t i) {
00188 if (!n) return 0;
00189 const AbstractQoreNode *p = n->retrieve_entry(i);
00190
00191 return p && p->getType() == NT_LIST ? reinterpret_cast<const QoreListNode *>(p) : 0;
00192 }
00193
00195
00200 static inline const ResolvedCallReferenceNode *test_callref_param(const QoreListNode *n, qore_size_t i) {
00201 if (!n) return 0;
00202 const AbstractQoreNode *p = n->retrieve_entry(i);
00203
00204 return p && (p->getType() == NT_FUNCREF || p->getType() == NT_RUNTIME_CLOSURE) ? reinterpret_cast<const ResolvedCallReferenceNode *>(p) : 0;
00205 }
00206
00208
00213 static inline const ResolvedCallReferenceNode *test_funcref_param(const QoreListNode *n, qore_size_t i) {
00214 return test_callref_param(n, i);
00215 }
00216
00218
00224 static inline const ReferenceNode *test_reference_param(const QoreListNode *n, qore_size_t i) {
00225 if (!n) return 0;
00226 const AbstractQoreNode *p = n->retrieve_entry(i);
00227
00228 return p && p->getType() == NT_REFERENCE ? reinterpret_cast<const ReferenceNode *>(p) : 0;
00229 }
00230
00232
00237 static inline bool test_nothing_param(const QoreListNode *n, qore_size_t i) {
00238 if (!n) return true;
00239 return is_nothing(n->retrieve_entry(i));
00240 }
00241
00243 static inline const QoreEncoding *get_encoding_param(const QoreListNode *n, qore_size_t i, const QoreEncoding *def = QCS_DEFAULT) {
00244 const QoreStringNode *str = test_string_param(n, i);
00245 return str ? QEM.findCreate(str) : def;
00246 }
00247
00249 template <typename T>
00250 static inline T *get_hard_param(const QoreListNode *n, qore_size_t i) {
00251 assert(n);
00252 assert(dynamic_cast<T *>(n->retrieve_entry(i)));
00253 return reinterpret_cast<T *>(n->retrieve_entry(i));
00254 }
00255
00257 #define HARD_QORE_PARAM(name, Type, list, i) Type *name = get_hard_param<Type>(list, i)
00258
00260 #define HARD_QORE_INT(list, i) get_hard_param<const QoreBigIntNode>(list, i)->val
00261
00263 #define HARD_QORE_FLOAT(list, i) get_hard_param<const QoreFloatNode>(list, i)->f
00264
00266 #define HARD_QORE_BOOL(list, i) get_hard_param<const QoreBoolNode>(list, i)->getValue()
00267
00269 #define HARD_QORE_STRING(list, i) get_hard_param<const QoreStringNode>(list, i)
00270
00272 #define HARD_QORE_DATE(list, i) get_hard_param<const DateTimeNode>(list, i)
00273
00275 #define HARD_QORE_BINARY(list, i) get_hard_param<const BinaryNode>(list, i)
00276
00278 #define HARD_QORE_LIST(list, i) get_hard_param<const QoreListNode>(list, i)
00279
00281 #define HARD_QORE_HASH(list, i) get_hard_param<const QoreHashNode>(list, i)
00282
00284 #define HARD_QORE_REF(list, i) get_hard_param<const ReferenceNode>(list, i)
00285
00287 #define HARD_QORE_OBJECT(list, i) const_cast<QoreObject *>(get_hard_param<const QoreObject>(list, i))
00288
00289
00290 #define HARD_QORE_OBJ_DATA(vname, Type, list, i, cid, dname, cname, xsink) HARD_QORE_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)
00291
00293 static inline const QoreEncoding *get_hard_qore_encoding_param(const QoreListNode *n, qore_size_t i) {
00294 HARD_QORE_PARAM(str, const QoreStringNode, n, i);
00295 return QEM.findCreate(str);
00296 }
00297
00298 #endif