Qore Programming Language  0.8.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 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_COMMON_H
25 
26 #define _QORE_COMMON_H
27 
32 #include <string.h>
33 #include <strings.h>
34 #include <stdarg.h>
35 #include <stddef.h>
36 #include <stdlib.h>
37 
38 #include <string>
39 #include <functional>
40 #include <list>
41 #include <set>
42 #include <vector>
43 #include <algorithm>
44 #include <set>
45 
47 #define Q_AF_UNSPEC -1
48 
50 #define Q_AF_INET -2
51 
53 #define Q_AF_INET6 -3
54 
56 #define Q_SOCK_STREAM -1
57 
59 typedef signed short qore_type_t;
60 
62 typedef size_t qore_size_t;
63 
65 typedef long qore_offset_t;
66 
68 typedef unsigned qore_classid_t;
69 
71 typedef std::set<int> int_set_t;
72 
75  QL_GPL = 0,
76  QL_LGPL = 1,
77  QL_MIT = 2
78 };
79 
80 #if defined _MSC_VER || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
81  #ifdef BUILDING_DLL
82  #define DLLEXPORT __declspec(dllexport)
83  #else
84  #define DLLEXPORT __declspec(dllimport)
85  #endif
86  #define DLLLOCAL
87 
88  #define QLLD "%I64d"
89  #define QLLX "%I64x"
90  #define QLLDx(a) "%" #a "I64d"
91  #define QORE_DIR_SEP '\\'
92  #define QORE_DIR_SEP_STR "\\"
93 #else
94  #ifdef HAVE_GCC_VISIBILITY
95  #define DLLEXPORT __attribute__ ((visibility("default")))
96  #define DLLLOCAL __attribute__ ((visibility("hidden")))
97  #else
98  #define DLLEXPORT
99  #define DLLLOCAL
100  #endif
101  #define QLLD "%lld"
102  #define QLLX "%llx"
103  #define QLLDx(a) "%" #a "lld"
104  #define QORE_DIR_SEP '/'
105  #define QORE_DIR_SEP_STR "/"
106 #endif
107 
108 #define _Q_MAKE_STRING(x) #x
109 #define MAKE_STRING_FROM_SYMBOL(x) _Q_MAKE_STRING(x)
110 
111 class AbstractQoreNode;
112 class QoreListNode;
113 class ExceptionSink;
114 class QoreObject;
115 class AbstractPrivateData;
116 class QoreMethod;
117 class QoreBuiltinMethod;
118 class QoreClass;
119 class QoreTypeInfo;
120 
122 template <typename T> struct free_ptr : std::unary_function <T*, void> {
123  DLLLOCAL void operator()(T *ptr) {
124  free(ptr);
125  }
126 };
127 
129 template <typename T> struct simple_delete {
130  DLLLOCAL void operator()(T *ptr) {
131  delete ptr;
132  }
133 };
134 
136 template <typename T> struct simple_deref {
137  DLLLOCAL void operator()(T *ptr) {
138  ptr->deref();
139  }
140  DLLLOCAL void operator()(T *ptr, ExceptionSink *xsink) {
141  ptr->deref(xsink);
142  }
143 };
144 
146 class ltstr {
147 public:
148  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
149  return strcmp(s1, s2) < 0;
150  }
151 };
152 
154 class ltcstrcase {
155 public:
156  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
157  return strcasecmp(s1, s2) < 0;
158  }
159 };
160 
162 class ltstrcase {
163 public:
164  DLLLOCAL bool operator()(std::string s1, std::string s2) const {
165  return strcasecmp(s1.c_str(), s2.c_str()) < 0;
166  }
167 };
168 
169 class eqstr {
170 public:
171  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
172  return !strcmp(s1, s2);
173  }
174 };
175 
176 class eqstrcase {
177 public:
178  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
179  return !strcasecmp(s1, s2);
180  }
181 };
182 
184 class ltchar {
185 public:
186  DLLLOCAL bool operator()(const char s1, const char s2) const {
187  return s1 < s2;
188  }
189 };
190 
192 class cstr_vector_t : public std::vector<char *> {
193 public:
194  DLLLOCAL ~cstr_vector_t() {
195  std::for_each(begin(), end(), free_ptr<char>());
196  }
197 };
198 
200 typedef std::vector<const QoreTypeInfo *> type_vec_t;
201 
203 typedef std::vector<AbstractQoreNode *> arg_vec_t;
204 
206 typedef std::vector<std::string> name_vec_t;
207 
208 typedef long long int64;
209 
211 
215 typedef AbstractQoreNode *(*q_func_t)(const QoreListNode *args, ExceptionSink *xsink);
216 
218 typedef int64 (*q_func_int64_t)(const QoreListNode* args, ExceptionSink* xsink);
219 
221 typedef bool (*q_func_bool_t)(const QoreListNode* args, ExceptionSink* xsink);
222 
224 typedef double (*q_func_double_t)(const QoreListNode* args, ExceptionSink* xsink);
225 
227 
233 typedef AbstractQoreNode *(*q_method_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
234 
236 
242 typedef int64 (*q_method_int64_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
243 
245 
251 typedef int (*q_method_int_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
252 
254 
260 typedef bool (*q_method_bool_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
261 
263 
269 typedef double (*q_method_double_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
270 
272 
279 typedef AbstractQoreNode *(*q_method2_t)(const QoreMethod &method, QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
280 
282 
291 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);
292 
294 
299 typedef AbstractQoreNode *(*q_static_method2_t)(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
300 
302 
309 typedef AbstractQoreNode *(*q_static_method3_t)(const QoreMethod &method, const type_vec_t &typeList, const void *ptr, const QoreListNode *args, ExceptionSink *xsink);
310 
312 
316 typedef void (*q_constructor_t)(QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
317 
319 
324 typedef void (*q_constructor2_t)(const QoreClass &thisclass, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
325 
327 
334 typedef void (*q_constructor3_t)(const QoreClass &thisclass, const type_vec_t &typeList, const void *ptr, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
335 
337 
344 typedef void (*q_system_constructor_t)(QoreObject *self, int code, va_list args);
345 
347 
354 typedef void (*q_system_constructor2_t)(const QoreClass &thisclass, QoreObject *self, int code, va_list args);
355 
357 
362 typedef void (*q_destructor_t)(QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
363 
365 
371 typedef void (*q_destructor2_t)(const QoreClass &thisclass, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
372 
374 
381 typedef void (*q_destructor3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
382 
384 
390 typedef void (*q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
391 
393 
400 typedef void (*q_copy2_t)(const QoreClass &thisclass, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
401 
403 
411 typedef void (*q_copy3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
412 
414 
419 typedef bool (*q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data);
420 
422 
424 typedef unsigned q_trid_t;
425 
426 DLLEXPORT long long q_atoll(const char *str);
427 
428 #endif // _QORE_COMMON_H
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:411
bool(* q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data)
the typed used for QoreClass deleteBlocker signatures
Definition: common.h:419
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:36
non-thread-safe vector for storing &quot;char *&quot; that you want to delete
Definition: common.h:192
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
code to be used under the LGPL license
Definition: common.h:76
int64(* q_func_int64_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an integer value
Definition: common.h:218
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:62
for char less-than comparisons
Definition: common.h:184
for simple c-string less-than comparisons
Definition: common.h:146
long qore_offset_t
used for offsets that could be negative
Definition: common.h:65
std::vector< AbstractQoreNode * > arg_vec_t
vector of value information for default argument lists
Definition: common.h:203
for simple c-string case-insensitive less-than comparisons
Definition: common.h:154
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:354
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:242
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:269
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:59
code to be used under the MIT license
Definition: common.h:77
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:44
void(* q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures
Definition: common.h:390
void(* q_destructor_t)(QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass destructor signatures
Definition: common.h:362
double(* q_func_double_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an double value
Definition: common.h:224
defines a Qore-language class
Definition: QoreClass.h:186
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:371
functor template for deleting elements
Definition: common.h:129
void(* q_constructor_t)(QoreObject *self, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:316
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:344
unsigned q_trid_t
type for thread resource IDs (unique within a single running qore library process) ...
Definition: common.h:424
qore_license_t
qore library and module license type identifiers
Definition: common.h:74
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:56
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:68
for std::string case-insensitive less-than comparisons
Definition: common.h:162
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
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:324
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:206
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:260
code to be used under the GPL license
Definition: common.h:75
std::set< int > int_set_t
set of integers
Definition: common.h:71
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:334
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:251
a method in a QoreClass
Definition: QoreClass.h:83
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:200
bool(* q_func_bool_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning a boolean value
Definition: common.h:221
functor template for dereferencing elements
Definition: common.h:136
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:400
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:381
functor template for calling free() on pointers
Definition: common.h:122