cfad47cfa3/src/common.h

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
#ifndef COMMON_H
2
#define COMMON_H
3
4
#ifdef HAVE_CONFIG_H
5
#include <config.h>
6
#endif
7
8
/* ushort, uint, and ulong are usually in <sys/types.h>
9
 */
10
#ifdef HAVE_SYS_TYPES_H
11
#include <sys/types.h>
12
#endif
13
14
/* Check for the existence of uchar, ushort, uint and ulong and define
15
 * the appropriate OS_*_DEFINED macros.
16
 */
17
#ifdef __cplusplus
18
#ifdef CXX_UCHAR_DEFINED
19
#define OS_UCHAR_DEFINED
20
#endif
21
#ifdef CXX_USHORT_DEFINED
22
#define OS_USHORT_DEFINED
23
#endif
24
#ifdef CXX_UINT_DEFINED
25
#define OS_UINT_DEFINED
26
#endif
27
#ifdef CXX_ULONG_DEFINED
28
#define OS_ULONG_DEFINED
29
#endif
30
#else /* !__cplusplus */
31
#ifdef C_UCHAR_DEFINED
32
#define OS_UCHAR_DEFINED
33
#endif
34
#ifdef C_USHORT_DEFINED
35
#define OS_USHORT_DEFINED
36
#endif
37
#ifdef C_UINT_DEFINED
38
#define OS_UINT_DEFINED
39
#endif
40
#ifdef C_ULONG_DEFINED
41
#define OS_ULONG_DEFINED
42
#endif
43
#endif /* __cplusplus */
44
45
/* The intention is to work around a bug on old systems where we cannot
46
 * include both <time.h> and <sys/time.h>.  Anyway, for now, this does
47
 * not work, since the TADS base code includes <time.h> on its own.
48
 * This may be fixed in the future though.
49
 */
50
#ifdef __cplusplus
51
extern "C" {
52
#endif
53
#if TIME_WITH_SYS_TIME
54
# include <sys/time.h>
55
# include <time.h>
56
#else
57
# if HAVE_SYS_TIME_H
58
#  include <sys/time.h>
59
# else
60
#  include <time.h>
61
# endif
62
#endif
63
#ifdef __cplusplus
64
}
65
#endif
66
67
#ifdef __cplusplus
68
69
// Define the "and", "or" and "not" keywords if the C++ compiler lacks
70
// them.  Normally, if just one of them is available, the others are
71
// too.  But there is no harm in checking them individually.  We only
72
// define them when compiling C++, since a) these keywords are not valid
73
// in C and b) some C compilers define them either for convenience or to
74
// support C99.
75
#ifndef HAVE_AND_KEYWORD
76
#define and &&
77
#endif
78
#ifndef HAVE_OR_KEYWORD
79
#define or ||
80
#endif
81
#ifndef HAVE_NOT_KEYWORD
82
#define not !
83
#endif
84
85
// For casting, C++ code should *not* use X_cast<type>(value) but rather
86
// X_cast(type)(value).  If the compiler supports the X_cast keywords,
87
// we define the X_cast macros to use the right syntax.  If not, we make
88
// them use old-style syntax.
89
#ifdef HAVE_STATIC_CAST
90
#define static_cast(a) static_cast<a>
91
#else
92
#define static_cast(a) (a)
93
#endif
94
95
#ifdef HAVE_DYNAMIC_CAST
96
#define dynamic_cast(a) dynamic_cast<a>
97
#else
98
#define dynamic_cast(a) (a)
99
#endif
100
101
#ifdef HAVE_REINTERPRET_CAST
102
#define reinterpret_cast(a) reinterpret_cast<a>
103
#else
104
#define reinterpret_cast(a) (a)
105
#endif
106
107
#ifndef HAVE_BOOL
108
// The C++ compiler lacks "bool".  Define it.  We do not use macros for
109
// this; with an enum and typedef we always have the same type-safety as
110
// with a compiler that has native bool-support.  Implicit casts to
111
// "int" still work as they should.
112
enum booleanValues { false, true };
113
typedef enum booleanValues bool;
114
#endif
115
116
#endif /* __cplusplus */
117
118
#endif /* COMMON_H */