Qore Programming Language  0.8.7
 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 
37 #include <string>
38 #include <functional>
39 #include <list>
40 #include <set>
41 #include <vector>
42 #include <algorithm>
43 #include <set>
44 
46 #define Q_AF_UNSPEC -1
47 
49 #define Q_AF_INET -2
50 
52 #define Q_AF_INET6 -3
53 
55 #define Q_SOCK_STREAM -1
56 
58 typedef signed short qore_type_t;
59 
61 typedef size_t qore_size_t;
62 
64 typedef long qore_offset_t;
65 
67 typedef unsigned qore_classid_t;
68 
70 typedef std::set<int> int_set_t;
71 
73 enum qore_license_t { QL_GPL = 0,
74  QL_LGPL = 1
75 };
76 
77 #if defined _MSC_VER || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
78  #ifdef BUILDING_DLL
79  #define DLLEXPORT __declspec(dllexport)
80  #else
81  #define DLLEXPORT __declspec(dllimport)
82  #endif
83  #define DLLLOCAL
84 
85  #define QLLD "%I64d"
86  #define QLLX "%I64x"
87  #define QLLDx(a) "%" #a "I64d"
88  #define QORE_DIR_SEP '\\'
89  #define QORE_DIR_SEP_STR "\\"
90 #else
91  #ifdef HAVE_GCC_VISIBILITY
92  #define DLLEXPORT __attribute__ ((visibility("default")))
93  #define DLLLOCAL __attribute__ ((visibility("hidden")))
94  #else
95  #define DLLEXPORT
96  #define DLLLOCAL
97  #endif
98  #define QLLD "%lld"
99  #define QLLX "%llx"
100  #define QLLDx(a) "%" #a "lld"
101  #define QORE_DIR_SEP '/'
102  #define QORE_DIR_SEP_STR "/"
103 #endif
104 
105 #define _Q_MAKE_STRING(x) #x
106 #define MAKE_STRING_FROM_SYMBOL(x) _Q_MAKE_STRING(x)
107 
108 class AbstractQoreNode;
109 class QoreListNode;
110 class ExceptionSink;
111 class QoreObject;
112 class AbstractPrivateData;
113 class QoreMethod;
114 class QoreBuiltinMethod;
115 class QoreClass;
116 class QoreTypeInfo;
117 
119 template <typename T> struct free_ptr : std::unary_function <T*, void> {
120  DLLLOCAL void operator()(T *ptr) {
121  free(ptr);
122  }
123 };
124 
126 template <typename T> struct simple_delete {
127  DLLLOCAL void operator()(T *ptr) {
128  delete ptr;
129  }
130 };
131 
133 template <typename T> struct simple_deref {
134  DLLLOCAL void operator()(T *ptr) {
135  ptr->deref();
136  }
137  DLLLOCAL void operator()(T *ptr, ExceptionSink *xsink) {
138  ptr->deref(xsink);
139  }
140 };
141 
143 class ltstr {
144 public:
145  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
146  return strcmp(s1, s2) < 0;
147  }
148 };
149 
151 class ltcstrcase {
152 public:
153  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
154  return strcasecmp(s1, s2) < 0;
155  }
156 };
157 
159 class ltstrcase {
160 public:
161  DLLLOCAL bool operator()(std::string s1, std::string s2) const {
162  return strcasecmp(s1.c_str(), s2.c_str()) < 0;
163  }
164 };
165 
166 class eqstr {
167 public:
168  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
169  return !strcmp(s1, s2);
170  }
171 };
172 
173 class eqstrcase {
174 public:
175  DLLLOCAL bool operator()(const char* s1, const char* s2) const {
176  return !strcasecmp(s1, s2);
177  }
178 };
179 
181 class ltchar {
182 public:
183  DLLLOCAL bool operator()(const char s1, const char s2) const {
184  return s1 < s2;
185  }
186 };
187 
189 class cstr_vector_t : public std::vector<char *> {
190 public:
191  DLLLOCAL ~cstr_vector_t() {
192  std::for_each(begin(), end(), free_ptr<char>());
193  }
194 };
195 
197 typedef std::vector<const QoreTypeInfo *> type_vec_t;
198 
200 typedef std::vector<AbstractQoreNode *> arg_vec_t;
201 
203 typedef std::vector<std::string> name_vec_t;
204 
205 typedef long long int64;
206 
208 
212 typedef AbstractQoreNode *(*q_func_t)(const QoreListNode *args, ExceptionSink *xsink);
213 
215 typedef int64 (*q_func_int64_t)(const QoreListNode* args, ExceptionSink* xsink);
216 
218 typedef bool (*q_func_bool_t)(const QoreListNode* args, ExceptionSink* xsink);
219 
221 typedef double (*q_func_double_t)(const QoreListNode* args, ExceptionSink* xsink);
222 
224 
230 typedef AbstractQoreNode *(*q_method_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
231 
233 
239 typedef int64 (*q_method_int64_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
240 
242 
248 typedef int (*q_method_int_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
249 
251 
257 typedef bool (*q_method_bool_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
258 
260 
266 typedef double (*q_method_double_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
267 
269 
276 typedef AbstractQoreNode *(*q_method2_t)(const QoreMethod &method, QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, ExceptionSink *xsink);
277 
279 
288 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);
289 
291 
296 typedef AbstractQoreNode *(*q_static_method2_t)(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
297 
299 
306 typedef AbstractQoreNode *(*q_static_method3_t)(const QoreMethod &method, const type_vec_t &typeList, const void *ptr, const QoreListNode *args, ExceptionSink *xsink);
307 
309 
313 typedef void (*q_constructor_t)(QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
314 
316 
321 typedef void (*q_constructor2_t)(const QoreClass &thisclass, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
322 
324 
331 typedef void (*q_constructor3_t)(const QoreClass &thisclass, const type_vec_t &typeList, const void *ptr, QoreObject *self, const QoreListNode *args, ExceptionSink *xsink);
332 
334 
341 typedef void (*q_system_constructor_t)(QoreObject *self, int code, va_list args);
342 
344 
351 typedef void (*q_system_constructor2_t)(const QoreClass &thisclass, QoreObject *self, int code, va_list args);
352 
354 
359 typedef void (*q_destructor_t)(QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
360 
362 
368 typedef void (*q_destructor2_t)(const QoreClass &thisclass, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
369 
371 
378 typedef void (*q_destructor3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink);
379 
381 
387 typedef void (*q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
388 
390 
397 typedef void (*q_copy2_t)(const QoreClass &thisclass, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
398 
400 
408 typedef void (*q_copy3_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink);
409 
411 
416 typedef bool (*q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data);
417 
419 
421 typedef unsigned q_trid_t;
422 
423 DLLEXPORT long long q_atoll(const char *str);
424 
425 #endif // _QORE_COMMON_H