aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes/MCUtils.h
blob: e1bef84143e0d3cd16e8875fe1dcdf63c834b9e3 (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
#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) ((str) != NULL ? (str)->UTF8Characters() : NULL )
#define MCUTF8DESC(obj) ((obj) != NULL ? (obj)->description()->UTF8Characters() : NULL )

#define MCLOCALIZEDSTRING(key) key

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

#endif

#endif