OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_ | 5 #ifndef PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_ |
6 #define PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_ | 6 #define PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <limits> | 10 #include <limits> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "ppapi/shared_impl/ppapi_shared_export.h" | 12 #include "ppapi/shared_impl/ppapi_shared_export.h" |
12 | 13 |
13 namespace ppapi { | 14 namespace ppapi { |
14 | 15 |
15 enum PPIdType { | 16 enum PPIdType { |
16 PP_ID_TYPE_MODULE, | 17 PP_ID_TYPE_MODULE, |
17 PP_ID_TYPE_INSTANCE, | 18 PP_ID_TYPE_INSTANCE, |
18 PP_ID_TYPE_RESOURCE, | 19 PP_ID_TYPE_RESOURCE, |
19 PP_ID_TYPE_VAR, | 20 PP_ID_TYPE_VAR, |
20 | 21 |
21 // Not a real type, must be last. | 22 // Not a real type, must be last. |
22 PP_ID_TYPE_COUNT | 23 PP_ID_TYPE_COUNT |
23 }; | 24 }; |
24 | 25 |
25 PPAPI_SHARED_EXPORT extern const unsigned int kPPIdTypeBits; | 26 PPAPI_SHARED_EXPORT extern const unsigned int kPPIdTypeBits; |
26 | 27 |
27 extern const int32 kMaxPPId; | 28 extern const int32_t kMaxPPId; |
28 | 29 |
29 // The least significant bits are the type, the rest are the value. | 30 // The least significant bits are the type, the rest are the value. |
30 template <typename T> | 31 template <typename T> |
31 inline T MakeTypedId(T value, PPIdType type) { | 32 inline T MakeTypedId(T value, PPIdType type) { |
32 return (value << kPPIdTypeBits) | static_cast<T>(type); | 33 return (value << kPPIdTypeBits) | static_cast<T>(type); |
33 } | 34 } |
34 | 35 |
35 template <typename T> | 36 template <typename T> |
36 inline bool CheckIdType(T id, PPIdType type) { | 37 inline bool CheckIdType(T id, PPIdType type) { |
37 // Say a resource of 0 is always valid, since that means "no resource." | 38 // Say a resource of 0 is always valid, since that means "no resource." |
38 // You shouldn't be passing 0 var, instance, or module IDs around so those | 39 // You shouldn't be passing 0 var, instance, or module IDs around so those |
39 // are still invalid. | 40 // are still invalid. |
40 if (type == PP_ID_TYPE_RESOURCE && !id) | 41 if (type == PP_ID_TYPE_RESOURCE && !id) |
41 return true; | 42 return true; |
42 const T mask = (static_cast<T>(1) << kPPIdTypeBits) - 1; | 43 const T mask = (static_cast<T>(1) << kPPIdTypeBits) - 1; |
43 return (id & mask) == type; | 44 return (id & mask) == type; |
44 } | 45 } |
45 | 46 |
46 } // namespace ppapi | 47 } // namespace ppapi |
47 | 48 |
48 #endif // PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_ | 49 #endif // PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_ |
OLD | NEW |