Qore Programming Language - C/C++ Library  0.8.13.6
common.h
Go to the documentation of this file.
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  common.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2017 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_COMMON_H
33 
34 #define _QORE_COMMON_H
35 
40 #include <string.h>
41 #include <strings.h>
42 #include <stdarg.h>
43 #include <stddef.h>
44 #include <stdlib.h>
45 #include <inttypes.h>
46 
47 #include <string>
48 #include <functional>
49 #include <list>
50 #include <set>
51 #include <vector>
52 #include <algorithm>
53 #include <set>
54 
56 class QoreTypeInfo;
57 
59 #define Q_AF_UNSPEC -1
60 
62 #define Q_AF_INET -2
63 
65 #define Q_AF_INET6 -3
66 
68 #define Q_SOCK_STREAM -1
69 
71 typedef int16_t qore_type_t;
72 
74 typedef size_t qore_size_t;
75 
77 typedef intptr_t qore_offset_t;
78 
80 typedef unsigned qore_classid_t;
81 
83 typedef std::set<int> int_set_t;
84 
87  QL_GPL = 0,
88  QL_LGPL = 1,
89  QL_MIT = 2
90 };
91 
92 // class access values
93 enum ClassAccess : unsigned char {
94  Public = 0, // publicly accessible
95  Private = 1, // accessible only in the class hierarchy (like c++'s 'protected')
96  Internal = 2 // accessible only in the class itself
97 };
98 
99 #if defined _MSC_VER || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
100 #define _Q_WINDOWS 1
101 #ifdef _WIN64
102 #define _Q_WINDOWS64 1
103 #endif
104 #endif
105 
106 #ifdef _Q_WINDOWS
107  #ifdef BUILDING_DLL
108  #define DLLEXPORT __declspec(dllexport)
109  #else
110  #define DLLEXPORT __declspec(dllimport)
111  #endif
112  #define DLLLOCAL
113 
114  #define QLLD "%I64d"
115  #define QLLX "%I64x"
116  #define QLLDx(a) "%" #a "I64d"
117  #define QORE_DIR_SEP '\\'
118  #define QORE_DIR_SEP_STR "\\"
119  #define QORE_PATH_SEP ';'
120  #define QORE_PATH_SEP_STR ";"
121  #include <winsock2.h>
122 #else
123  #ifdef HAVE_GCC_VISIBILITY
124  #define DLLEXPORT __attribute__ ((visibility("default")))
125  #define DLLLOCAL __attribute__ ((visibility("hidden")))
126  #else
127  #define DLLEXPORT
128  #define DLLLOCAL
129  #endif
130  #define QLLD "%lld"
131  #define QLLX "%llx"
132  #define QLLDx(a) "%" #a "lld"
133  #define QORE_DIR_SEP '/'
134  #define QORE_DIR_SEP_STR "/"
135  #define QORE_PATH_SEP ':'
136  #define QORE_PATH_SEP_STR ":"
137 #endif
138 
139 #define _Q_MAKE_STRING(x) #x
140 #define MAKE_STRING_FROM_SYMBOL(x) _Q_MAKE_STRING(x)
141 
142 class AbstractQoreNode;
143 class QoreListNode;
144 class ExceptionSink;
145 class QoreObject;
146 class AbstractPrivateData;
147 class QoreMethod;
148 class QoreBuiltinMethod;
149 class QoreClass;
150 struct QoreValue;
151 class QoreValueList;
152 
154 template <typename T> struct free_ptr : std::unary_function <T*, void> {
155  DLLLOCAL void operator()(T* ptr) {
156  free(ptr);
157  }
158 };
159 
161 template <typename T> struct simple_delete {
162  DLLLOCAL void operator()(T* ptr) {
163  delete ptr;
164  }
165 };
166 
168 template <typename T> struct simple_deref {
169  DLLLOCAL void operator()(T* ptr) {
170  ptr->deref();
171  }
172  DLLLOCAL void operator()(T* ptr, ExceptionSink* xsink) {
173  ptr->deref(xsink);
174  }
175 };
176 
178 class ltstr {
179 public:
180  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
181  return strcmp(s1, s2) < 0;
182  }
183 };
184 
186 class ltcstrcase {
187 public:
188  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
189  return strcasecmp(s1, s2) < 0;
190  }
191 };
192 
194 class ltstrcase {
195 public:
196  DLLLOCAL bool operator()(std::string s1, std::string s2) const {
197  return strcasecmp(s1.c_str(), s2.c_str()) < 0;
198  }
199 };
200 
201 class eqstr {
202 public:
203  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
204  return !strcmp(s1, s2);
205  }
206 };
207 
208 class eqstrcase {
209 public:
210  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
211  return !strcasecmp(s1, s2);
212  }
213 };
214 
216 class ltchar {
217 public:
218  DLLLOCAL bool operator()(const char s1, const char s2) const {
219  return s1 < s2;
220  }
221 };
222 
224 class cstr_vector_t : public std::vector<char*> {
225 public:
226  DLLLOCAL ~cstr_vector_t() {
227  std::for_each(begin(), end(), free_ptr<char>());
228  }
229 };
230 
232 typedef std::vector<const QoreTypeInfo*> type_vec_t;
233 
235 typedef std::vector<AbstractQoreNode*> arg_vec_t;
236 
238 typedef std::vector<std::string> name_vec_t;
239 
241 typedef long long int64;
242 
244 typedef uint64_t q_rt_flags_t;
245 
247 
253 typedef QoreValue (*q_func_n_t)(const QoreValueList* args, q_rt_flags_t flags, ExceptionSink* xsink);
254 
256 
261 typedef AbstractQoreNode* (*q_func_t)(const QoreListNode* args, ExceptionSink* xsink);
262 
264 typedef int64 (*q_func_int64_t)(const QoreListNode* args, ExceptionSink* xsink);
265 
267 typedef bool (*q_func_bool_t)(const QoreListNode* args, ExceptionSink* xsink);
268 
270 typedef double (*q_func_double_t)(const QoreListNode* args, ExceptionSink* xsink);
271 
273 
281 typedef QoreValue (*q_method_n_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreValueList* args, q_rt_flags_t flags, ExceptionSink* xsink);
282 
284 
296 typedef QoreValue (*q_external_method_t)(const QoreMethod& method, const void* ptr, QoreObject* self, AbstractPrivateData* private_data, const QoreValueList* args, q_rt_flags_t flags, ExceptionSink* xsink);
297 
299 
306 typedef AbstractQoreNode* (*q_method_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
307 
309 
316 typedef int64 (*q_method_int64_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
317 
319 
326 typedef int (*q_method_int_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
327 
329 
336 typedef bool (*q_method_bool_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
337 
339 
346 typedef double (*q_method_double_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
347 
349 
357 typedef AbstractQoreNode* (*q_method2_t)(const QoreMethod& method, QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
358 
360 
370 typedef AbstractQoreNode* (*q_method3_t)(const QoreMethod& method, const type_vec_t& typeList, const void* ptr, QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
371 
373 
383 typedef QoreValue (*q_external_static_method_t)(const QoreMethod& method, const void* ptr, const QoreValueList* args, q_rt_flags_t flags, ExceptionSink* xsink);
384 
386 
392 typedef AbstractQoreNode* (*q_static_method2_t)(const QoreMethod& method, const QoreListNode* args, ExceptionSink* xsink);
393 
395 
403 typedef AbstractQoreNode* (*q_static_method3_t)(const QoreMethod& method, const type_vec_t& typeList, const void* ptr, const QoreListNode* args, ExceptionSink* xsink);
404 
406 
411 typedef void (*q_constructor_n_t)(QoreObject* self, const QoreValueList* args, q_rt_flags_t rtflags, ExceptionSink* xsink);
412 
414 
423 typedef void (*q_external_constructor_t)(const QoreMethod& method, const void* ptr, QoreObject* self, const QoreValueList* args, q_rt_flags_t rtflags, ExceptionSink* xsink);
424 
426 
430 typedef void (*q_constructor_t)(QoreObject* self, const QoreListNode* args, ExceptionSink* xsink);
431 
433 
438 typedef void (*q_constructor2_t)(const QoreClass& thisclass, QoreObject* self, const QoreListNode* args, ExceptionSink* xsink);
439 
441 
448 typedef void (*q_constructor3_t)(const QoreClass& thisclass, const type_vec_t& typeList, const void* ptr, QoreObject* self, const QoreListNode* args, ExceptionSink* xsink);
449 
451 
458 typedef void (*q_system_constructor_t)(QoreObject* self, int code, va_list args);
459 
461 
468 typedef void (*q_system_constructor2_t)(const QoreClass& thisclass, QoreObject* self, int code, va_list args);
469 
471 
476 typedef void (*q_destructor_t)(QoreObject* self, AbstractPrivateData* private_data, ExceptionSink* xsink);
477 
479 
485 typedef void (*q_destructor2_t)(const QoreClass& thisclass, QoreObject* self, AbstractPrivateData* private_data, ExceptionSink* xsink);
486 
488 
495 typedef void (*q_destructor3_t)(const QoreClass& thisclass, const void* ptr, QoreObject* self, AbstractPrivateData* private_data, ExceptionSink* xsink);
496 
498 
504 typedef void (*q_copy_t)(QoreObject* self, QoreObject* old, AbstractPrivateData* private_data, ExceptionSink* xsink);
505 
507 
514 typedef void (*q_copy2_t)(const QoreClass& thisclass, QoreObject* self, QoreObject* old, AbstractPrivateData* private_data, ExceptionSink* xsink);
515 
517 
525 typedef void (*q_copy3_t)(const QoreClass& thisclass, const void* ptr, QoreObject* self, QoreObject* old, AbstractPrivateData* private_data, ExceptionSink* xsink);
526 
528 
533 typedef bool (*q_delete_blocker_t)(QoreObject* self, AbstractPrivateData* private_data);
534 
536 
538 typedef unsigned q_trid_t;
539 
540 DLLEXPORT long long q_atoll(const char* str);
541 
542 #endif // _QORE_COMMON_H
int64(* q_method_int64_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass method signatures, returns int64
Definition: common.h:316
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
void(* q_destructor_t)(QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass destructor signatures
Definition: common.h:476
void(* q_copy2_t)(const QoreClass &thisclass, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures with the new generic calling convention ...
Definition: common.h:514
QoreValue(* q_method_n_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreValueList *args, q_rt_flags_t flags, ExceptionSink *xsink)
the new type used for builtin QoreClass method signatures
Definition: common.h:281
void(* q_constructor_n_t)(QoreObject *self, const QoreValueList *args, q_rt_flags_t rtflags, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:411
void(* q_system_constructor_t)(QoreObject *self, int code, va_list args)
the type used for builtin QoreClass system constructor method signatures
Definition: common.h:458
void(* q_system_constructor2_t)(const QoreClass &thisclass, QoreObject *self, int code, va_list args)
the type used for builtin QoreClass system constructor method signatures using the new generic callin...
Definition: common.h:468
void(* q_destructor2_t)(const QoreClass &thisclass, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass destructor signatures with the new generic calling convention ...
Definition: common.h:485
non-thread-safe vector for storing "char*" that you want to delete
Definition: common.h:224
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreValueList.h:45
int64(* q_func_int64_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an integer value
Definition: common.h:264
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
void(* q_constructor3_t)(const QoreClass &thisclass, const type_vec_t &typeList, const void *ptr, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures using the even newer generic callin...
Definition: common.h:448
code to be used under the LGPL license
Definition: common.h:88
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:74
for char less-than comparisons
Definition: common.h:216
for simple c-string less-than comparisons
Definition: common.h:178
QoreValue(* q_external_static_method_t)(const QoreMethod &method, const void *ptr, const QoreValueList *args, q_rt_flags_t flags, ExceptionSink *xsink)
the type used for external static methods
Definition: common.h:383
uint64_t q_rt_flags_t
runtime code execution flags
Definition: common.h:244
for simple c-string case-insensitive less-than comparisons
Definition: common.h:186
void(* q_constructor_t)(QoreObject *self, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:430
code to be used under the MIT license
Definition: common.h:89
std::vector< AbstractQoreNode * > arg_vec_t
vector of value information for default argument lists
Definition: common.h:235
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QoreValue(* q_func_n_t)(const QoreValueList *args, q_rt_flags_t flags, ExceptionSink *xsink)
the type used for builtin function signatures
Definition: common.h:253
defines a Qore-language class
Definition: QoreClass.h:214
bool(* q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data)
the typed used for QoreClass deleteBlocker signatures
Definition: common.h:533
void(* q_copy3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures with the new generic calling convention ...
Definition: common.h:525
functor template for deleting elements
Definition: common.h:161
unsigned q_trid_t
type for thread resource IDs (unique within a single running qore library process) ...
Definition: common.h:538
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
qore_license_t
qore library and module license type identifiers
Definition: common.h:86
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:62
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:80
for std::string case-insensitive less-than comparisons
Definition: common.h:194
bool(* q_method_bool_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass method signatures when called with the even newer generic calling...
Definition: common.h:336
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
double(* q_method_double_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass method signatures when called with the even newer generic calling...
Definition: common.h:346
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:238
void(* q_external_constructor_t)(const QoreMethod &method, const void *ptr, QoreObject *self, const QoreValueList *args, q_rt_flags_t rtflags, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:423
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:241
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:77
code to be used under the GPL license
Definition: common.h:87
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:71
std::set< int > int_set_t
set of integers
Definition: common.h:83
double(* q_func_double_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an double value
Definition: common.h:270
void(* q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures
Definition: common.h:504
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:232
a method in a QoreClass
Definition: QoreClass.h:94
void(* q_destructor3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass destructor signatures with the new generic calling convention and...
Definition: common.h:495
int(* q_method_int_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass method signatures when called with the even newer generic calling...
Definition: common.h:326
QoreValue(* q_external_method_t)(const QoreMethod &method, const void *ptr, QoreObject *self, AbstractPrivateData *private_data, const QoreValueList *args, q_rt_flags_t flags, ExceptionSink *xsink)
the new type used for builtin QoreClass method signatures
Definition: common.h:296
functor template for dereferencing elements
Definition: common.h:168
void(* q_constructor2_t)(const QoreClass &thisclass, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures using the new generic calling conve...
Definition: common.h:438
functor template for calling free() on pointers
Definition: common.h:154
bool(* q_func_bool_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning a boolean value
Definition: common.h:267