All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
common.h
Go to the documentation of this file.
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
common.h
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_COMMON_H
#define _QORE_COMMON_H
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <stddef.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 signed short qore_type_t;
typedef size_t qore_size_t;
typedef long 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
};
#if defined _MSC_VER || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
#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;
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 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 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_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