Qore Programming Language 0.8.8

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
params.h
Go to the documentation of this file.
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 params.h
4
5 Qore Programming Language
6
7 Copyright 2003 - 2013 David Nichols
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _QORE_PARAMS_H
25
26 #define _QORE_PARAMS_H
27
28 #include <qore/AbstractQoreNode.h>
29
34
38 static inline unsigned num_args(const QoreListNode *n) {
39 return n ? (unsigned)n->size() : 0;
40 }
41
43
46 static inline unsigned num_params(const QoreListNode *n) {
47 return n ? (unsigned)n->size() : 0;
48 }
49
51
56 static inline const AbstractQoreNode *get_param(const QoreListNode *n, qore_size_t i) {
57 if (!n) return 0;
58 const AbstractQoreNode *p = n->retrieve_entry(i);
59 return is_nothing(p) ? 0 : p;
60 }
61
63
68 static inline qore_type_t get_param_type(const QoreListNode *n, qore_size_t i) {
69 if (!n) return NT_NOTHING;
70 const AbstractQoreNode *p = n->retrieve_entry(i);
71 return p ? p->getType() : NT_NOTHING;
72 }
73
75 static inline int get_int_param(const QoreListNode *n, qore_size_t i) {
76 if (!n) return 0;
77 const AbstractQoreNode *p = n->retrieve_entry(i);
78 return is_nothing(p) ? 0 : p->getAsInt();
79 }
80
82 static inline int64 get_bigint_param(const QoreListNode *n, qore_size_t i) {
83 if (!n) return 0;
84 const AbstractQoreNode *p = n->retrieve_entry(i);
85 return is_nothing(p) ? 0 : p->getAsBigInt();
86 }
87
89 static inline int get_int_param_with_default(const QoreListNode *n, qore_size_t i, int def) {
90 if (!n) return def;
91 const AbstractQoreNode *p = n->retrieve_entry(i);
92 return is_nothing(p) ? def : p->getAsInt();
93 }
94
96 static inline int64 get_bigint_param_with_default(const QoreListNode *n, qore_size_t i, int64 def) {
97 if (!n) return def;
98 const AbstractQoreNode *p = n->retrieve_entry(i);
99 return is_nothing(p) ? def : p->getAsBigInt();
100 }
101
103 static inline double get_float_param(const QoreListNode *n, qore_size_t i) {
104 if (!n) return 0;
105 const AbstractQoreNode *p = n->retrieve_entry(i);
106 return is_nothing(p) ? 0 : p->getAsFloat();
107 }
108
110 static inline bool get_bool_param(const QoreListNode *n, qore_size_t i) {
111 if (!n) return 0;
112 const AbstractQoreNode *p = n->retrieve_entry(i);
113 return is_nothing(p) ? false : p->getAsBool();
114 }
115
117
122 static inline const BinaryNode *test_binary_param(const QoreListNode *n, qore_size_t i) {
123 if (!n) return 0;
124 const AbstractQoreNode *p = n->retrieve_entry(i);
125 // the following is faster than a dynamic_cast
126 return p && p->getType() == NT_BINARY ? reinterpret_cast<const BinaryNode *>(p) : 0;
127 }
128
130
135 static inline const QoreStringNode *test_string_param(const QoreListNode *n, qore_size_t i) {
136 if (!n) return 0;
137 const AbstractQoreNode *p = n->retrieve_entry(i);
138 // the following is faster than a dynamic_cast
139 return p && p->getType() == NT_STRING ? reinterpret_cast<const QoreStringNode *>(p) : 0;
140 }
141
143
148 static inline QoreObject *test_object_param(const QoreListNode *n, qore_size_t i) {
149 if (!n) return 0;
150 const AbstractQoreNode *p = n->retrieve_entry(i);
151 // the following is faster than a dynamic_cast
152 return p && p->getType() == NT_OBJECT ? const_cast<QoreObject *>(reinterpret_cast<const QoreObject *>(p)) : 0;
153 }
154
156
161 static inline const DateTimeNode *test_date_param(const QoreListNode *n, qore_size_t i) {
162 if (!n) return 0;
163 const AbstractQoreNode *p = n->retrieve_entry(i);
164 // the following is faster than a dynamic_cast
165 return p && p->getType() == NT_DATE ? reinterpret_cast<const DateTimeNode *>(p) : 0;
166 }
167
169
174 static inline const QoreHashNode *test_hash_param(const QoreListNode *n, qore_size_t i) {
175 if (!n) return 0;
176 const AbstractQoreNode *p = n->retrieve_entry(i);
177 // the following is faster than a dynamic_cast
178 return p && p->getType() == NT_HASH ? reinterpret_cast<const QoreHashNode *>(p) : 0;
179 }
180
182
187 static inline const QoreListNode *test_list_param(const QoreListNode *n, qore_size_t i) {
188 if (!n) return 0;
189 const AbstractQoreNode *p = n->retrieve_entry(i);
190 // the following is faster than a dynamic_cast
191 return p && p->getType() == NT_LIST ? reinterpret_cast<const QoreListNode *>(p) : 0;
192 }
193
195
200 static inline const ResolvedCallReferenceNode *test_callref_param(const QoreListNode *n, qore_size_t i) {
201 if (!n) return 0;
202 const AbstractQoreNode *p = n->retrieve_entry(i);
203 // the following is faster than a dynamic_cast
204 return p && (p->getType() == NT_FUNCREF || p->getType() == NT_RUNTIME_CLOSURE) ? reinterpret_cast<const ResolvedCallReferenceNode *>(p) : 0;
205 }
206
208
213 static inline const ResolvedCallReferenceNode *test_funcref_param(const QoreListNode *n, qore_size_t i) {
214 return test_callref_param(n, i);
215 }
216
218
224 static inline const ReferenceNode *test_reference_param(const QoreListNode *n, qore_size_t i) {
225 if (!n) return 0;
226 const AbstractQoreNode *p = n->retrieve_entry(i);
227 // the following is faster than a dynamic_cast
228 return p && p->getType() == NT_REFERENCE ? reinterpret_cast<const ReferenceNode *>(p) : 0;
229 }
230
232
237 static inline bool test_nothing_param(const QoreListNode *n, qore_size_t i) {
238 if (!n) return true;
239 return is_nothing(n->retrieve_entry(i));
240 }
241
243 static inline const QoreEncoding *get_encoding_param(const QoreListNode *n, qore_size_t i, const QoreEncoding *def = QCS_DEFAULT) {
244 const QoreStringNode *str = test_string_param(n, i);
245 return str ? QEM.findCreate(str) : def;
246 }
247
249 template <typename T>
250 static inline T *get_hard_param(const QoreListNode *n, qore_size_t i) {
251 assert(n);
252 assert(dynamic_cast<T *>(n->retrieve_entry(i)));
253 return reinterpret_cast<T *>(n->retrieve_entry(i));
254 }
255
256 static inline void HARD_QORE_DATA(const QoreListNode *n, qore_size_t i, const void *&ptr, qore_size_t &len) {
257 const AbstractQoreNode *p = get_hard_param<const AbstractQoreNode>(n, i);
258 if (p->getType() == NT_STRING) {
259 const QoreStringNode *str = reinterpret_cast<const QoreStringNode *>(p);
260 ptr = (const void *)str->getBuffer();
261 len = str->size();
262 return;
263 }
264 const BinaryNode *b = reinterpret_cast<const BinaryNode *>(p);
265 ptr = b->getPtr();
266 len = b->size();
267 }
268
270 #define HARD_QORE_PARAM(name, Type, list, i) Type *name = get_hard_param<Type>(list, i)
271
273 #define HARD_QORE_INT(list, i) get_hard_param<const QoreBigIntNode>(list, i)->val
274
276 #define HARD_QORE_FLOAT(list, i) get_hard_param<const QoreFloatNode>(list, i)->f
277
279 #define HARD_QORE_NUMBER(list, i) get_hard_param<const QoreNumberNode>(list, i)
280
282 #define HARD_QORE_BOOL(list, i) get_hard_param<const QoreBoolNode>(list, i)->getValue()
283
285 #define HARD_QORE_STRING(list, i) get_hard_param<const QoreStringNode>(list, i)
286
288 #define HARD_QORE_DATE(list, i) get_hard_param<const DateTimeNode>(list, i)
289
291 #define HARD_QORE_BINARY(list, i) get_hard_param<const BinaryNode>(list, i)
292
294 #define HARD_QORE_LIST(list, i) get_hard_param<const QoreListNode>(list, i)
295
297 #define HARD_QORE_HASH(list, i) get_hard_param<const QoreHashNode>(list, i)
298
300 #define HARD_QORE_REF(list, i) get_hard_param<const ReferenceNode>(list, i)
301
303 #define HARD_QORE_OBJECT(list, i) const_cast<QoreObject *>(get_hard_param<const QoreObject>(list, i))
304
305 // sets up an object pointer
306 #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)
307
309 static inline const QoreEncoding *get_hard_qore_encoding_param(const QoreListNode *n, qore_size_t i) {
310 HARD_QORE_PARAM(str, const QoreStringNode, n, i);
311 return QEM.findCreate(str);
312 }
313
314 #endif
NT_BINARY
const qore_type_t NT_BINARY
type value for BinaryNode
Definition: node_types.h:41
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:72
HARD_QORE_PARAM
#define HARD_QORE_PARAM(name, Type, list, i)
returns a hard typed parameter
Definition: params.h:270
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:41
AbstractQoreNode::getAsBool
DLLEXPORT bool getAsBool() const
returns the boolean value of the object
test_callref_param
static const ResolvedCallReferenceNode * test_callref_param(const QoreListNode *n, qore_size_t i)
returns a ResolvedCallReferenceNode pointer for the argument position given or 0 if there is no argum...
Definition: params.h:200
QCS_DEFAULT
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
get_int_param_with_default
static int get_int_param_with_default(const QoreListNode *n, qore_size_t i, int def)
returns an integer corresponding to the argument given or a default value if there is none ...
Definition: params.h:89
test_funcref_param
static const ResolvedCallReferenceNode * test_funcref_param(const QoreListNode *n, qore_size_t i)
returns a ResolvedCallReferenceNode pointer for the argument position given or 0 if there is no argum...
Definition: params.h:213
AbstractQoreNode::getAsFloat
DLLEXPORT double getAsFloat() const
returns the float value of the object
test_hash_param
static const QoreHashNode * test_hash_param(const QoreListNode *n, qore_size_t i)
returns a QoreHashNode pointer for the argument position given or 0 if there is no argument there or ...
Definition: params.h:174
NT_LIST
const qore_type_t NT_LIST
type value for QoreListNode
Definition: node_types.h:42
BinaryNode::size
DLLEXPORT qore_size_t size() const
returns the number of bytes in the object
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
NT_NOTHING
const qore_type_t NT_NOTHING
type value for QoreNothingNode
Definition: node_types.h:34
NT_OBJECT
const qore_type_t NT_OBJECT
type value for QoreObject
Definition: node_types.h:44
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:61
test_date_param
static const DateTimeNode * test_date_param(const QoreListNode *n, qore_size_t i)
returns a DateTimeNode pointer for the argument position given or 0 if there is no argument there or ...
Definition: params.h:161
test_reference_param
static const ReferenceNode * test_reference_param(const QoreListNode *n, qore_size_t i)
returns a ReferenceNode pointer for the argument position given or 0 if there is no argument there or...
Definition: params.h:224
NT_DATE
const qore_type_t NT_DATE
type value for DateTimeNode
Definition: node_types.h:38
get_hard_qore_encoding_param
static const QoreEncoding * get_hard_qore_encoding_param(const QoreListNode *n, qore_size_t i)
returns the QoreEncoding corresponding to the string passed or a default encoding ...
Definition: params.h:309
NT_FUNCREF
const qore_type_t NT_FUNCREF
type value for AbstractCallReferenceNode
Definition: node_types.h:63
test_object_param
static QoreObject * test_object_param(const QoreListNode *n, qore_size_t i)
returns a QoreObject pointer for the argument position given or 0 if there is no argument there or if...
Definition: params.h:148
test_binary_param
static const BinaryNode * test_binary_param(const QoreListNode *n, qore_size_t i)
returns a const BinaryNode pointer for the argument position given or 0 if there is no argument there...
Definition: params.h:122
AbstractQoreNode::getAsInt
DLLEXPORT int getAsInt() const
returns the integer value of the object
QoreListNode::retrieve_entry
DLLEXPORT AbstractQoreNode * retrieve_entry(qore_size_t index)
returns the element at &quot;index&quot; (first element is index 0)
AbstractQoreNode::getAsBigInt
DLLEXPORT int64 getAsBigInt() const
returns the 64-bit integer value of the object
qore_type_t
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:58
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
num_args
static unsigned num_args(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:38
is_nothing
static bool is_nothing(const AbstractQoreNode *n)
to check if an AbstractQoreNode object is NOTHING
Definition: QoreLib.h:278
get_hard_param
static T * get_hard_param(const QoreListNode *n, qore_size_t i)
returns the given type for hard typed parameters
Definition: params.h:250
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:44
QEM
DLLEXPORT QoreEncodingManager QEM
the QoreEncodingManager object
DateTimeNode
Qore&#39;s parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:36
get_bool_param
static bool get_bool_param(const QoreListNode *n, qore_size_t i)
returns a boolean value corresponding to the argument given or false if there is none ...
Definition: params.h:110
ReferenceNode
parse type: reference to a lvalue expression
Definition: ReferenceNode.h:37
NT_RUNTIME_CLOSURE
const qore_type_t NT_RUNTIME_CLOSURE
type value for ResolvedCallReferenceNode (QoreClosureNode, QoreObjectClosureNode) ...
Definition: node_types.h:66
NT_HASH
const qore_type_t NT_HASH
type value for QoreHashNode
Definition: node_types.h:43
test_nothing_param
static bool test_nothing_param(const QoreListNode *n, qore_size_t i)
returns true if the arugment position given is NOTHING
Definition: params.h:237
NT_REFERENCE
const qore_type_t NT_REFERENCE
type value for ReferenceNode
Definition: node_types.h:56
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;...
test_list_param
static const QoreListNode * test_list_param(const QoreListNode *n, qore_size_t i)
returns a QoreListNode pointer for the argument position given or 0 if there is no argument there or ...
Definition: params.h:187
NT_STRING
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:37
QoreListNode::size
DLLEXPORT qore_size_t size() const
returns the number of elements in the list
test_string_param
static const QoreStringNode * test_string_param(const QoreListNode *n, qore_size_t i)
returns a const QoreStringNode pointer for the argument position given or 0 if there is no argument t...
Definition: params.h:135
QoreObject
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:56
num_params
static unsigned num_params(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:46
get_bigint_param
static int64 get_bigint_param(const QoreListNode *n, qore_size_t i)
returns a 64-bit integer corresponding to the argument given or 0 if there is none ...
Definition: params.h:82
AbstractQoreNode::getType
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:286
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:120
get_bigint_param_with_default
static int64 get_bigint_param_with_default(const QoreListNode *n, qore_size_t i, int64 def)
returns a 64-bit integer corresponding to the argument given or a default value if there is none ...
Definition: params.h:96
get_encoding_param
static const QoreEncoding * get_encoding_param(const QoreListNode *n, qore_size_t i, const QoreEncoding *def=QCS_DEFAULT)
returns the QoreEncoding corresponding to the string passed or a default encoding ...
Definition: params.h:243
get_float_param
static double get_float_param(const QoreListNode *n, qore_size_t i)
returns a float corresponding to the argument given or 0 if there is none
Definition: params.h:103
BinaryNode::getPtr
DLLEXPORT const void * getPtr() const
returns the pointer to the data
get_int_param
static int get_int_param(const QoreListNode *n, qore_size_t i)
returns an integer corresponding to the argument given or 0 if there is none
Definition: params.h:75
get_param
static const AbstractQoreNode * get_param(const QoreListNode *n, qore_size_t i)
returns the argument in the position given or 0 if there is none
Definition: params.h:56
QoreString::size
DLLEXPORT qore_size_t size() const
returns number of bytes in the string (not including the null pointer)
get_param_type
static qore_type_t get_param_type(const QoreListNode *n, qore_size_t i)
returns the argument type in the position given or 0 if there is none
Definition: params.h:68
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:33
QoreString::getBuffer
DLLEXPORT const char * getBuffer() const
returns the string&#39;s buffer; this data should not be changed