common.h
Go to the documentation of this file.
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
common.h
Qore Programming Language
Copyright (C) 2003 - 2016 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_COMMON_H
#define _QORE_COMMON_H
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string>
#include <functional>
#include <list>
#include <set>
#include <vector>
#include <algorithm>
#include <set>
#define Q_AF_UNSPEC -1
#define Q_AF_INET -2
#define Q_AF_INET6 -3
#define Q_SOCK_STREAM -1
typedef int16_t qore_type_t;
typedef size_t qore_size_t;
typedef intptr_t qore_offset_t;
typedef unsigned qore_classid_t;
typedef std::set<int> int_set_t;
enum qore_license_t {
QL_GPL = 0,
QL_LGPL = 1,
QL_MIT = 2
};
#if defined _MSC_VER || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
#define _Q_WINDOWS 1
#ifdef _WIN64
#define _Q_WINDOWS 1
#define _Q_WINDOWS64 1
#endif
#endif
#ifdef _Q_WINDOWS
#ifdef BUILDING_DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
#define DLLLOCAL
#define QLLD "%I64d"
#define QLLX "%I64x"
#define QLLDx(a) "%" #a "I64d"
#define QORE_DIR_SEP '\\'
#define QORE_DIR_SEP_STR "\\"
#else
#ifdef HAVE_GCC_VISIBILITY
#define DLLEXPORT __attribute__ ((visibility("default")))
#define DLLLOCAL __attribute__ ((visibility("hidden")))
#else
#define DLLEXPORT
#define DLLLOCAL
#endif
#define QLLD "%lld"
#define QLLX "%llx"
#define QLLDx(a) "%" #a "lld"
#define QORE_DIR_SEP '/'
#define QORE_DIR_SEP_STR "/"
#endif
#define _Q_MAKE_STRING(x) #x
#define MAKE_STRING_FROM_SYMBOL(x) _Q_MAKE_STRING(x)
class AbstractQoreNode;
class QoreListNode;
class ExceptionSink;
class QoreObject;
class AbstractPrivateData;
class QoreMethod;
class QoreBuiltinMethod;
class QoreClass;
class QoreTypeInfo;
struct QoreValue;
class QoreValueList;
template <typename T> struct free_ptr : std::unary_function <T*, void> {
DLLLOCAL void operator()(T* ptr) {
free(ptr);
}
};
template <typename T> struct simple_delete {
DLLLOCAL void operator()(T* ptr) {
delete ptr;
}
};
template <typename T> struct simple_deref {
DLLLOCAL void operator()(T* ptr) {
ptr->deref();
}
DLLLOCAL void operator()(T* ptr, ExceptionSink* xsink) {
ptr->deref(xsink);
}
};
class ltstr {
public:
DLLLOCAL bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) < 0;
}
};
class ltcstrcase {
public:
DLLLOCAL bool operator()(const char* s1, const char* s2) const {
return strcasecmp(s1, s2) < 0;
}
};
class ltstrcase {
public:
DLLLOCAL bool operator()(std::string s1, std::string s2) const {
return strcasecmp(s1.c_str(), s2.c_str()) < 0;
}
};
class eqstr {
public:
DLLLOCAL bool operator()(const char* s1, const char* s2) const {
return !strcmp(s1, s2);
}
};
class eqstrcase {
public:
DLLLOCAL bool operator()(const char* s1, const char* s2) const {
return !strcasecmp(s1, s2);
}
};
class ltchar {
public:
DLLLOCAL bool operator()(const char s1, const char s2) const {
return s1 < s2;
}
};
class cstr_vector_t : public std::vector<char*> {
public:
DLLLOCAL ~cstr_vector_t() {
std::for_each(begin(), end(), free_ptr<char>());
}
};
typedef std::vector<const QoreTypeInfo*> type_vec_t;
typedef std::vector<AbstractQoreNode*> arg_vec_t;
typedef std::vector<std::string> name_vec_t;
typedef long long int64;
typedef uint64_t q_rt_flags_t;
typedef QoreValue (*q_func_n_t)(const QoreValueList* args, q_rt_flags_t flags, ExceptionSink* xsink);
typedef AbstractQoreNode* (*q_func_t)(const QoreListNode* args, ExceptionSink* xsink);
typedef int64 (*q_func_int64_t)(const QoreListNode* args, ExceptionSink* xsink);
typedef bool (*q_func_bool_t)(const QoreListNode* args, ExceptionSink* xsink);
typedef double (*q_func_double_t)(const QoreListNode* args, ExceptionSink* xsink);
typedef QoreValue (*q_method_n_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreValueList* args, q_rt_flags_t flags, ExceptionSink* xsink);
typedef AbstractQoreNode* (*q_method_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
typedef int64 (*q_method_int64_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
typedef int (*q_method_int_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
typedef bool (*q_method_bool_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
typedef double (*q_method_double_t)(QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
typedef AbstractQoreNode* (*q_method2_t)(const QoreMethod& method, QoreObject* self, AbstractPrivateData* private_data, const QoreListNode* args, ExceptionSink* xsink);
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);
typedef AbstractQoreNode* (*q_static_method2_t)(const QoreMethod& method, const QoreListNode* args, ExceptionSink* xsink);
typedef AbstractQoreNode* (*q_static_method3_t)(const QoreMethod& method, const type_vec_t& typeList, const void* ptr, const QoreListNode* args, ExceptionSink* xsink);
typedef void (*q_constructor_n_t)(QoreObject* self, const QoreValueList* args, q_rt_flags_t rtflags, ExceptionSink* xsink);
typedef void (*q_constructor_t)(QoreObject* self, const QoreListNode* args, ExceptionSink* xsink);
typedef void (*q_constructor2_t)(const QoreClass& thisclass, QoreObject* self, const QoreListNode* args, ExceptionSink* xsink);
typedef void (*q_constructor3_t)(const QoreClass& thisclass, const type_vec_t& typeList, const void* ptr, QoreObject* self, const QoreListNode* args, ExceptionSink* xsink);
typedef void (*q_system_constructor_t)(QoreObject* self, int code, va_list args);
typedef void (*q_system_constructor2_t)(const QoreClass& thisclass, QoreObject* self, int code, va_list args);
typedef void (*q_destructor_t)(QoreObject* self, AbstractPrivateData* private_data, ExceptionSink* xsink);
typedef void (*q_destructor2_t)(const QoreClass& thisclass, QoreObject* self, AbstractPrivateData* private_data, ExceptionSink* xsink);
typedef void (*q_destructor3_t)(const QoreClass& thisclass, const void* ptr, QoreObject* self, AbstractPrivateData* private_data, ExceptionSink* xsink);
typedef void (*q_copy_t)(QoreObject* self, QoreObject* old, AbstractPrivateData* private_data, ExceptionSink* xsink);
typedef void (*q_copy2_t)(const QoreClass& thisclass, QoreObject* self, QoreObject* old, AbstractPrivateData* private_data, ExceptionSink* xsink);
typedef void (*q_copy3_t)(const QoreClass& thisclass, const void* ptr, QoreObject* self, QoreObject* old, AbstractPrivateData* private_data, ExceptionSink* xsink);
typedef bool (*q_delete_blocker_t)(QoreObject* self, AbstractPrivateData* private_data);
typedef unsigned q_trid_t;
DLLEXPORT long long q_atoll(const char* str);
#endif // _QORE_COMMON_H
q_method_int64_t
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:286
AbstractPrivateData
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
q_destructor_t
void(* q_destructor_t)(QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass destructor signatures
Definition: common.h:420
q_copy2_t
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:458
q_method_n_t
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:266
q_constructor_n_t
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:367
q_system_constructor_t
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:402
q_system_constructor2_t
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:412
q_destructor2_t
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:429
cstr_vector_t
non-thread-safe vector for storing "char*" that you want to delete
Definition: common.h:211
QoreValueList
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreValueList.h:45
q_func_int64_t
int64(* q_func_int64_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an integer value
Definition: common.h:250
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
q_constructor3_t
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:392
QL_LGPL
code to be used under the LGPL license
Definition: common.h:85
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:71
ltchar
for char less-than comparisons
Definition: common.h:203
ltstr
for simple c-string less-than comparisons
Definition: common.h:165
q_rt_flags_t
uint64_t q_rt_flags_t
runtime code execution flags
Definition: common.h:231
ltcstrcase
for simple c-string case-insensitive less-than comparisons
Definition: common.h:173
q_constructor_t
void(* q_constructor_t)(QoreObject *self, const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:374
QL_MIT
code to be used under the MIT license
Definition: common.h:86
arg_vec_t
std::vector< AbstractQoreNode * > arg_vec_t
vector of value information for default argument lists
Definition: common.h:222
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
q_func_n_t
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:239
QoreClass
defines a Qore-language class
Definition: QoreClass.h:195
q_delete_blocker_t
bool(* q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data)
the typed used for QoreClass deleteBlocker signatures
Definition: common.h:477
q_copy3_t
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:469
simple_delete
functor template for deleting elements
Definition: common.h:148
q_trid_t
unsigned q_trid_t
type for thread resource IDs (unique within a single running qore library process) ...
Definition: common.h:482
qore_license_t
qore_license_t
qore library and module license type identifiers
Definition: common.h:83
QoreObject
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:64
qore_classid_t
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:77
ltstrcase
for std::string case-insensitive less-than comparisons
Definition: common.h:181
q_method_bool_t
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:306
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
q_method_double_t
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:316
name_vec_t
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:225
int64
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:228
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:74
QL_GPL
code to be used under the GPL license
Definition: common.h:84
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68
int_set_t
std::set< int > int_set_t
set of integers
Definition: common.h:80
q_func_double_t
double(* q_func_double_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an double value
Definition: common.h:256
q_copy_t
void(* q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures
Definition: common.h:448
type_vec_t
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:219
QoreMethod
a method in a QoreClass
Definition: QoreClass.h:91
q_destructor3_t
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:439
q_method_int_t
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:296
simple_deref
functor template for dereferencing elements
Definition: common.h:155
q_constructor2_t
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:382
free_ptr
functor template for calling free() on pointers
Definition: common.h:141
q_func_bool_t
bool(* q_func_bool_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning a boolean value
Definition: common.h:253