Qore Programming Language  0.8.11.1
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 - 2014 David Nichols
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 
46 #include <string>
47 #include <functional>
48 #include <list>
49 #include <set>
50 #include <vector>
51 #include <algorithm>
52 #include <set>
53 
55 #define Q_AF_UNSPEC -1
56 
58 #define Q_AF_INET -2
59 
61 #define Q_AF_INET6 -3
62 
64 #define Q_SOCK_STREAM -1
65 
67 typedef signed short qore_type_t;
68 
70 typedef size_t qore_size_t;
71 
73 typedef long qore_offset_t;
74 
76 typedef unsigned qore_classid_t;
77 
79 typedef std::set<int> int_set_t;
80 
83  QL_GPL = 0,
84  QL_LGPL = 1,
85  QL_MIT = 2
86 };
87 
88 #if defined _MSC_VER || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
89  #ifdef BUILDING_DLL
90  #define DLLEXPORT __declspec(dllexport)
91  #else
92  #define DLLEXPORT __declspec(dllimport)
93  #endif
94  #define DLLLOCAL
95 
96  #define QLLD "%I64d"
97  #define QLLX "%I64x"
98  #define QLLDx(a) "%" #a "I64d"
99  #define QORE_DIR_SEP '\\'
100  #define QORE_DIR_SEP_STR "\\"
101 #else
102  #ifdef HAVE_GCC_VISIBILITY
103  #define DLLEXPORT __attribute__ ((visibility("default")))
104  #define DLLLOCAL __attribute__ ((visibility("hidden")))
105  #else
106  #define DLLEXPORT
107  #define DLLLOCAL
108  #endif
109  #define QLLD "%lld"
110  #define QLLX "%llx"
111  #define QLLDx(a) "%" #a "lld"
112  #define QORE_DIR_SEP '/'
113  #define QORE_DIR_SEP_STR "/"
114 #endif
115 
116 #define _Q_MAKE_STRING(x) #x
117 #define MAKE_STRING_FROM_SYMBOL(x) _Q_MAKE_STRING(x)
118 
119 class AbstractQoreNode;
120 class QoreListNode;
121 class ExceptionSink;
122 class QoreObject;
123 class AbstractPrivateData;
124 class QoreMethod;
125 class QoreBuiltinMethod;
126 class QoreClass;
127 class QoreTypeInfo;
128 
130 template <typename T> struct free_ptr : std::unary_function <T*, void> {
131  DLLLOCAL void operator()(T *ptr) {
132  free(ptr);
133  }
134 };
135 
137 template <typename T> struct simple_delete {
138  DLLLOCAL void operator()(T *ptr) {
139  delete ptr;
140  }
141 };
142 
144 template <typename T> struct simple_deref {
145  DLLLOCAL void operator()(T *ptr) {
146  ptr->deref();
147  }
148  DLLLOCAL void operator()(T *ptr, ExceptionSink *xsink) {
149  ptr->deref(xsink);
150  }
151 };
152 
154 class ltstr {
155 public:
156  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
157  return strcmp(s1, s2) < 0;
158  }
159 };
160 
162 class ltcstrcase {
163 public:
164  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
165  return strcasecmp(s1, s2) < 0;
166  }
167 };
168 
170 class ltstrcase {
171 public:
172  DLLLOCAL bool operator()(std::string s1, std::string s2) const {
173  return strcasecmp(s1.c_str(), s2.c_str()) < 0;
174  }
175 };
176 
177 class eqstr {
178 public:
179  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
180  return !strcmp(s1, s2);
181  }
182 };
183 
184 class eqstrcase {
185 public:
186  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
187  return !strcasecmp(s1, s2);
188  }
189 };
190 
192 class ltchar {
193 public:
194  DLLLOCAL bool operator()(const char s1, const char s2) const {
195  return s1 < s2;
196  }
197 };
198 
200 class cstr_vector_t : public std::vector<char *> {
201 public:
202  DLLLOCAL ~cstr_vector_t() {
203  std::for_each(begin(), end(), free_ptr<char>());
204  }
205 };
206 
208 typedef std::vector<const QoreTypeInfo *> type_vec_t;
209 
211 typedef std::vector<AbstractQoreNode *> arg_vec_t;
212 
214 typedef std::vector<std::string> name_vec_t;
215 
216 typedef long long int64;
217 
219 
223 typedef AbstractQoreNode *(*q_func_t)(const QoreListNode *args, ExceptionSink *xsink);
224 
226 typedef int64 (*q_func_int64_t)(const QoreListNode* args, ExceptionSink* xsink);
227 
229 typedef bool (*q_func_bool_t)(const QoreListNode* args, ExceptionSink* xsink);
230 
232 typedef double (*q_func_double_t)(const QoreListNode* args, ExceptionSink* xsink);
233 
235 
241 typedef AbstractQoreNode *(*q_method_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
242 
244 
250 typedef int64 (*q_method_int64_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
251 
253 
259 typedef int (*q_method_int_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
260 
262 
268 typedef bool (*q_method_bool_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
269 
271 
277 typedef double (*q_method_double_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
278 
280 
287 typedef AbstractQoreNode *(*q_method2_t)(const QoreMethod &method, QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
288 
290 
299 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);
300 
302 
307 typedef AbstractQoreNode *(*q_static_method2_t)(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
308 
310 
317 typedef AbstractQoreNode *(*q_static_method3_t)(const QoreMethod &method, const type_vec_t &typeList, const void *ptr, const QoreListNode *args, ExceptionSink *xsink);
318 
320 
324 typedef void (*q_constructor_t)(QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
325 
327 
332 typedef void (*q_constructor2_t)(const QoreClass &thisclass, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
333 
335 
342 typedef void (*q_constructor3_t)(const QoreClass &thisclass, const type_vec_t &typeList, const void *ptr, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
343 
345 
352 typedef void (*q_system_constructor_t)(QoreObject *self, int code, va_list args);
353 
355 
362 typedef void (*q_system_constructor2_t)(const QoreClass &thisclass, QoreObject *self, int code, va_list args);
363 
365 
370 typedef void (*q_destructor_t)(QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
371 
373 
379 typedef void (*q_destructor2_t)(const QoreClass &thisclass, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
380 
382 
389 typedef void (*q_destructor3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
390 
392 
398 typedef void (*q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
399 
401 
408 typedef void (*q_copy2_t)(const QoreClass &thisclass, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
409 
411 
419 typedef void (*q_copy3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
420 
422 
427 typedef bool (*q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data);
428 
430 
432 typedef unsigned q_trid_t;
433 
434 DLLEXPORT long long q_atoll(const char *str);
435 
436 #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:250
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:370
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:408
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:352
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:362
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:379
non-thread-safe vector for storing "char *" that you want to delete
Definition: common.h:200
int64(* q_func_int64_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an integer value
Definition: common.h:226
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
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:342
code to be used under the LGPL license
Definition: common.h:84
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:70
for char less-than comparisons
Definition: common.h:192
for simple c-string less-than comparisons
Definition: common.h:154
long qore_offset_t
used for offsets that could be negative
Definition: common.h:73
std::vector< AbstractQoreNode * > arg_vec_t
vector of value information for default argument lists
Definition: common.h:211
for simple c-string case-insensitive less-than comparisons
Definition: common.h:162
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:67
void(* q_constructor_t)(QoreObject *self, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:324
code to be used under the MIT license
Definition: common.h:85
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
defines a Qore-language class
Definition: QoreClass.h:194
bool(* q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data)
the typed used for QoreClass deleteBlocker signatures
Definition: common.h:427
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:419
functor template for deleting elements
Definition: common.h:137
unsigned q_trid_t
type for thread resource IDs (unique within a single running qore library process) ...
Definition: common.h:432
qore_license_t
qore library and module license type identifiers
Definition: common.h:82
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:64
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:76
for std::string case-insensitive less-than comparisons
Definition: common.h:170
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:268
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
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:277
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:214
code to be used under the GPL license
Definition: common.h:83
std::set< int > int_set_t
set of integers
Definition: common.h:79
double(* q_func_double_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an double value
Definition: common.h:232
void(* q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures
Definition: common.h:398
a method in a QoreClass
Definition: QoreClass.h:91
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:389
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:208
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:259
functor template for dereferencing elements
Definition: common.h:144
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:332
functor template for calling free() on pointers
Definition: common.h:130
bool(* q_func_bool_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning a boolean value
Definition: common.h:229