Blame view

ios/cocos2d/cocos/base/CCEnumClass.h 1.65 KB
520389e3   xiaoyu   接入cocos源码,编译未通过,继续修改
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
  #pragma once
  
  #include <type_traits>
  
  namespace cocos2d{
  
  template<typename Enum>
  struct EnableBitMaskOperators
  {
      static const bool enable = false;
  };
  
  template<typename Enum>
  typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
  operator |(Enum lhs, Enum rhs)
  {
      using underlying = typename std::underlying_type<Enum>::type;
      return static_cast<Enum> (
          static_cast<underlying>(lhs) |
          static_cast<underlying>(rhs)
      );
  }
  
  template<typename Enum>
  typename std::enable_if<EnableBitMaskOperators<Enum>::enable, bool>::type
  operator ==(Enum lhs, Enum rhs)
  {
      using underlying = typename std::underlying_type<Enum>::type;
          static_cast<underlying>(lhs) == static_cast<underlying>(rhs);
  }
  
  template<typename Enum>
  typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type&
  operator |=(Enum& lhs, Enum rhs)
  {
      using underlying = typename std::underlying_type<Enum>::type;
      lhs = static_cast<Enum> (
          static_cast<underlying>(lhs) |
          static_cast<underlying>(rhs)
      );
  
      return lhs;
  }
  
  template<typename Enum>
  typename std::enable_if<EnableBitMaskOperators<Enum>::enable, unsigned int>::type
  operator &(Enum lhs, Enum rhs)
  {
      using underlying = typename std::underlying_type<Enum>::type;
      using impl_type = typename std::make_unsigned<underlying>::type;
      return impl_type (
          static_cast<impl_type>(lhs) &
          static_cast<impl_type>(rhs)
      );
  }
  
  #define ENABLE_BITMASK_OPERATORS(x)  \
  template<>                           \
  struct EnableBitMaskOperators<x>     \
  {                                    \
      static const bool enable = true; \
  };
  
  } // end of namespace cocos2d{