aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sfnt/SkTypedEnum.h
blob: 73d731488506b6bb993046b073a60f8880b238ba (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
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkTypedEnum_DEFINED
#define SkTypedEnum_DEFINED

#include "SkPreprocessorSeq.h"

//Compatibility with non-clang compilers.
#ifndef __has_feature
    #define __has_feature(x) 0
#endif
#ifndef __has_extension
    #define __has_extension __has_feature
#endif

//Detect if typed enums are supported.
#if defined(_MSC_VER) && _MSC_VER >= 1400
    #define SK_TYPED_ENUMS

#elif defined(__clang__) && __has_extension(cxx_strong_enums)
    #define SK_TYPED_ENUMS

// Scoped enums are buggy in GCC 4.4.0 through 4.5.1.
// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064
// __cplusplus should actually be accurate now.
// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773
#elif defined(__GNUC__) && (((__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ >= 40501) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || __cplusplus >= 201103L)
    #define SK_TYPED_ENUMS
#endif

//Define what a typed enum looks like.
#ifdef SK_TYPED_ENUMS

    #define SK_TYPED_ENUM_VALUES(data, elem) \
        SK_PAIR_FIRST(elem) = SK_PAIR_SECOND(elem),

    #define SK_TYPED_ENUM_IDS(data, elem) \
        elem,

    #define SK_TYPED_ENUM_IDS_L(data, elem) \
        elem

    #define SK_TYPED_ENUM(enumName, enumType, enumSeq, idSeq) \
        enum enumName : enumType { \
            SK_SEQ_FOREACH(SK_TYPED_ENUM_VALUES, _, enumSeq) \
        } SK_SEQ_FOREACH_L(SK_TYPED_ENUM_IDS, SK_TYPED_ENUM_IDS_L, _, idSeq);

#else

    #define SK_TYPED_ENUM_VALUES(enumType, elem) \
        static const enumType SK_PAIR_FIRST(elem) = SK_PAIR_SECOND(elem);

    #define SK_TYPED_ENUM_IDS(enumType, elem) \
        enumType elem;

    #define SK_TYPED_ENUM(enumName, enumType, enumSeq, idSeq) \
        typedef enumType enumName; \
        SK_SEQ_FOREACH(SK_TYPED_ENUM_VALUES, enumType, enumSeq) \
        SK_SEQ_FOREACH(SK_TYPED_ENUM_IDS, enumType, idSeq)

#endif

#endif