All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreLib.h
Go to the documentation of this file.
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreLib.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_QORELIB_H
#define _QORE_QORELIB_H
#include <qore/common.h>
#include <qore/QoreThreadLock.h>
#include <qore/qore_bitopts.h>
#include <qore/safe_dslist>
#include <time.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#undef _QORE_HAS_QORE_XMLNODE_CLASS
#undef _QORE_HAS_QORE_XMLREADER_CLASS
#undef _QORE_HAS_QORE_XMLDOC_CLASS
#define _QORE_HAS_HARD_TYPING 1
#define _QORE_HAS_DBI_EXECRAW 1
#define _QORE_HAS_TIME_ZONES 1
#define _QORE_HAS_THREAD_RESOURCE_IDS 1
#define _QORE_HAS_PREPARED_STATMENT_API 1
#define _QORE_HAS_DATASOURCE_ACTIVETRANSACTION 1
#define _QORE_HAS_DBI_SELECT_ROW 1
#define _QORE_HAS_NUMBER_TYPE 1
#define _QORE_HAS_PATH_IS_READABLE 1
#define _QORE_HAS_DBI_OPTIONS 1
#define _QORE_HAS_FIND_CREATE_TIMEZONE 1
#define _QORE_HAS_NUMBER_CONS_WITH_PREC 1
#define _QORE_HAS_FILE_OBJECT_HELPER 1
#define _QORE_HAS_QUEUE_OBJECT_HELPER 1
// qore code flags
#define QC_NO_FLAGS 0
#define QC_NOOP (1 << 0)
#define QC_USES_EXTRA_ARGS (1 << 1)
#define QC_CONSTANT_INTERN (1 << 2)
#define QC_DEPRECATED (1 << 3)
#define QC_RET_VALUE_ONLY (1 << 4)
#define QC_RUNTIME_NOOP (1 << 5)
// composite flags
#define QC_CONSTANT (QC_CONSTANT_INTERN | QC_RET_VALUE_ONLY)
DLLEXPORT char *make_class_name(const char *fn);
DLLEXPORT QoreStringNode *q_sprintf(const class QoreListNode *params, int field, int offset, class ExceptionSink *xsink);
DLLEXPORT QoreStringNode *q_vsprintf(const class QoreListNode *params, int field, int offset, class ExceptionSink *xsink);
DLLEXPORT struct tm *q_localtime(const time_t *clock, struct tm *tms);
DLLEXPORT struct tm *q_gmtime(const time_t *clock, struct tm *tms);
DLLEXPORT int64 q_epoch();
DLLEXPORT int64 q_epoch_us(int &us);
DLLEXPORT int64 q_epoch_ns(int &us);
DLLEXPORT char *q_basename(const char *path);
DLLEXPORT char *q_basenameptr(const char *path);
DLLEXPORT char *q_dirname(const char *path);
DLLEXPORT void *q_realloc(void *ptr, size_t size);
#if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
DLLEXPORT QoreHashNode *q_getpwuid(uid_t uid);
DLLEXPORT QoreHashNode *q_getpwnam(const char *name);
DLLEXPORT QoreHashNode *q_getgrgid(uid_t uid);
DLLEXPORT QoreHashNode *q_getgrnam(const char *name);
int q_uname2uid(const char *name, uid_t &uid);
int q_gname2gid(const char *name, gid_t &gid);
#endif // ! windows
DLLEXPORT void qore_setup_argv(int pos, int argc, char *argv[]);
DLLEXPORT qore_license_t qore_get_license();
DLLEXPORT void qore_exit_process(int rc);
class FeatureList : public safe_dslist<std::string> {
private:
DLLLOCAL FeatureList(const FeatureList&);
DLLLOCAL FeatureList& operator=(const FeatureList&);
public:
DLLLOCAL FeatureList();
DLLLOCAL ~FeatureList();
};
DLLEXPORT extern FeatureList qoreFeatureList;
static inline char *strchrs(const char *str, const char *chars) {
while (*str) {
if (strchr(chars, *str))
return (char *)str;
str++;
}
return 0;
}
static inline char *strnchr(const char *str, int len, char c) {
int i = 0;
while (i++ != len) {
if (*str == c)
return (char *)str;
++str;
}
return 0;
}
static inline void strtolower(char *str) {
while (*(str)) {
(*str) = tolower(*str);
str++;
}
}
static inline char *strtoupper(char *str) {
char *p = str;
while (*(p)) {
*p = toupper(*p);
p++;
}
return str;
}
DLLEXPORT int getSecZeroInt(const AbstractQoreNode *a);
DLLEXPORT int64 getSecZeroBigInt(const AbstractQoreNode *a);
DLLEXPORT int getSecMinusOneInt(const AbstractQoreNode *a);
DLLEXPORT int64 getSecMinusOneBigInt(const AbstractQoreNode *a);
DLLEXPORT int getMsZeroInt(const AbstractQoreNode *a);
DLLEXPORT int64 getMsZeroBigInt(const AbstractQoreNode *a);
DLLEXPORT int getMsMinusOneInt(const AbstractQoreNode *a);
DLLEXPORT int64 getMsMinusOneBigInt(const AbstractQoreNode *a);
DLLEXPORT int getMicroSecZeroInt(const AbstractQoreNode *a);
DLLEXPORT int64 getMicroSecZeroInt64(const AbstractQoreNode *a);
static inline bool is_nothing(const AbstractQoreNode *n) {
if (!n || n->getType() == NT_NOTHING)
return true;
return false;
}
static inline void discard(AbstractQoreNode *n, ExceptionSink *xsink) {
if (n)
n->deref(xsink);
}
static inline const char *get_type_name(const AbstractQoreNode *n) {
return n ? n->getTypeName() : "NOTHING";
}
static inline qore_type_t get_node_type(const AbstractQoreNode *n) {
return n ? n->getType() : NT_NOTHING;
}
class BinaryNode;
class QoreStringNode;
class ExceptionSink;
DLLEXPORT BinaryNode *qore_deflate(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
DLLEXPORT QoreStringNode *qore_inflate_to_string(const BinaryNode *b, const QoreEncoding *enc, ExceptionSink *xsink);
DLLEXPORT BinaryNode *qore_inflate_to_binary(const BinaryNode *b, ExceptionSink *xsink);
DLLEXPORT BinaryNode *qore_gzip(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
DLLEXPORT QoreStringNode *qore_gunzip_to_string(const BinaryNode *bin, const QoreEncoding *enc, ExceptionSink *xsink);
DLLEXPORT BinaryNode *qore_gunzip_to_binary(const BinaryNode *bin, ExceptionSink *xsink);
DLLEXPORT BinaryNode *qore_bzip2(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
DLLEXPORT QoreStringNode *qore_bunzip2_to_string(const BinaryNode *bin, const QoreEncoding *enc, ExceptionSink *xsink);
DLLEXPORT BinaryNode *qore_bunzip2_to_binary(const BinaryNode *bin, ExceptionSink *xsink);
DLLEXPORT BinaryNode *parseBase64(const char *buf, int len, ExceptionSink *xsink);
DLLEXPORT BinaryNode *parseHex(const char *buf, int len, ExceptionSink *xsink);
class AbstractQoreZoneInfo;
DLLEXPORT const AbstractQoreZoneInfo* findCreateOffsetZone(int seconds_east);
DLLEXPORT const AbstractQoreZoneInfo* find_create_timezone(const char* name, ExceptionSink* xsink);
DLLEXPORT int tz_get_utc_offset(const AbstractQoreZoneInfo* tz, int64 epoch_offset, bool &is_dst, const char *&zone_name);
DLLEXPORT bool tz_has_dst(const AbstractQoreZoneInfo* tz);
DLLEXPORT const char* tz_get_region_name(const AbstractQoreZoneInfo* tz);
#define QORE_OPT_ATOMIC_OPERATIONS "atomic operations"
#define QORE_OPT_STACK_GUARD "stack guard"
#define QORE_OPT_SIGNAL_HANDLING "signal handling"
#define QORE_OPT_RUNTIME_STACK_TRACE "runtime stack tracing"
#define QORE_OPT_LIBRARY_DEBUGGING "library debugging"
#define QORE_OPT_SHA224 "openssl sha224"
#define QORE_OPT_SHA256 "openssl sha256"
#define QORE_OPT_SHA384 "openssl sha384"
#define QORE_OPT_SHA512 "openssl sha512"
#define QORE_OPT_MDC2 "openssl mdc2"
#define QORE_OPT_RC5 "openssl rc5"
#define QORE_OPT_MD2 "openssl md2"
#define QORE_OPT_TERMIOS "termios"
#define QORE_OPT_FILE_LOCKING "file locking"
#define QORE_OPT_UNIX_USERMGT "unix user management"
#define QORE_OPT_UNIX_FILEMGT "unix file management"
#define QORE_OPT_FUNC_ROUND "round()"
#define QORE_OPT_FUNC_TIMEGM "timegm()"
#define QORE_OPT_FUNC_SETEUID "seteuid()"
#define QORE_OPT_FUNC_SETEGID "setegid()"
#define QORE_OPT_FUNC_SYSTEM "system()"
#define QORE_OPT_FUNC_KILL "kill()"
#define QORE_OPT_FUNC_FORK "fork()"
#define QORE_OPT_FUNC_GETPPID "getppid()"
#define QORE_OPT_FUNC_STATVFS "statvfs()"
#define QORE_OPT_FUNC_SETSID "setsid()"
#define QORE_OPT_FUNC_IS_EXECUTABLE "is_executable()"
#define QO_OPTION 0
#define QO_ALGORITHM 1
#define QO_FUNCTION 2
struct qore_option_s {
const char* option;
const char* constant;
int type;
bool value;
};
DLLEXPORT QoreStringNode *q_strerror(int errnum);
DLLEXPORT void q_strerror(QoreString &str, int errnum);
DLLEXPORT extern const qore_option_s *qore_option_list;
DLLEXPORT extern size_t qore_option_list_size;
DLLEXPORT QoreStringNode *qore_reassign_signal(int sig, const char *name);
#define QORE_MAX(a, b) ((a) > (b) ? (a) : (b))
#define QORE_MIN(a, b) ((a) < (b) ? (a) : (b))
#define QORE_PARAM_NO_ARG (NULL)
// define QORE_PATH_MAX
#ifndef QORE_PATH_MAX
#ifdef _XOPEN_PATH_MAX
#define QORE_PATH_MAX _XOPEN_PATH_MAX
#else
#define QORE_PATH_MAX 1024
#endif
#endif
DLLEXPORT void parse_set_time_zone(const char *zone);
DLLEXPORT int qore_usleep(int64 usecs);
DLLEXPORT bool q_path_is_readable(const char* path);
DLLEXPORT bool q_parse_bool(const AbstractQoreNode* n);
DLLEXPORT bool q_parse_bool(const char* str);
DLLEXPORT bool q_get_option_value(const char* opt);
DLLEXPORT bool q_get_option_constant_value(const char* opt);
#endif // _QORE_QORELIB_H