aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes/MCUtils.h
blob: ef8f3cd3791c6a2b52084f796c574b066e59dff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef MAILCORE_MCUTILS_H

#define MAILCORE_MCUTILS_H

#ifdef __cplusplus

#define MC_SAFE_RETAIN(o) ((o) != NULL ? (o)->retain() : NULL)
#define MC_SAFE_COPY(o) ((o) != NULL ? (o)->copy() : NULL)

#define MC_SAFE_RELEASE(o) \
    do { \
        if ((o) != NULL) { \
            (o)->release(); \
            (o) = NULL; \
        } \
    } while (0)

#define MC_SAFE_REPLACE_RETAIN(type, mField, value) \
    do { \
        MC_SAFE_RELEASE(mField); \
        mField = (type *) MC_SAFE_RETAIN(value); \
    } while (0)

#define MC_SAFE_REPLACE_COPY(type, mField, value) \
    do { \
        MC_SAFE_RELEASE(mField); \
        mField = (type *) MC_SAFE_COPY(value); \
    } while (0)

#define MCSTR(str) mailcore::String::uniquedStringWithUTF8Characters("" str "")

#define MCUTF8(str) MCUTF8DESC(str)
#define MCUTF8DESC(obj) ((obj) != NULL ? (obj)->description()->UTF8Characters() : NULL )

#define MCLOCALIZEDSTRING(key) key

#define MCISKINDOFCLASS(instance, class) (dynamic_cast<class *>(instance) != NULL)

#endif

#ifdef _MSC_VER
#	ifdef MAILCORE_DLL
#		define MAILCORE_EXPORT __declspec(dllexport)
#	else
#		define MAILCORE_EXPORT __declspec(dllimport)
#   endif
#else
#	define MAILCORE_EXPORT
#endif

#ifdef __ANDROID_API__
#if __ANDROID_API__ < 21
#include <wchar.h>
extern int               iswblank(wint_t);
extern int vfwscanf(FILE*, const wchar_t*, va_list);
extern int vswscanf(const wchar_t*, const wchar_t*, va_list);
extern int vwscanf(const wchar_t*, va_list);
extern float wcstof(const wchar_t*, wchar_t**);
extern long double wcstold(const wchar_t*, wchar_t**);
extern long long wcstoll(const wchar_t*, wchar_t**, int);
extern unsigned long long wcstoull(const wchar_t*, wchar_t**, int);
#endif
#endif

#ifdef __clang__

#if __has_feature(attribute_analyzer_noreturn)
#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
#else
#define CLANG_ANALYZER_NORETURN
#endif

#define ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))

#else

#define CLANG_ANALYZER_NORETURN
#define ATTRIBUTE_RETURNS_NONNULL

#endif

#ifndef DEPRECATED_ATTRIBUTE
#define DEPRECATED_ATTRIBUTE        __attribute__((deprecated))
#endif

#endif