OLD | NEW |
1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2010 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_C_PP_VAR_H_ | 5 #ifndef PPAPI_C_PP_VAR_H_ |
6 #define PPAPI_C_PP_VAR_H_ | 6 #define PPAPI_C_PP_VAR_H_ |
7 | 7 |
8 /** | 8 /** |
9 * @file | 9 * @file |
10 * Defines the API ... | 10 * Defines the API ... |
11 * | |
12 * @addtogroup PP | |
13 * @{ | |
14 */ | 11 */ |
15 | 12 |
16 #include "ppapi/c/pp_bool.h" | 13 #include "ppapi/c/pp_bool.h" |
17 #include "ppapi/c/pp_macros.h" | 14 #include "ppapi/c/pp_macros.h" |
18 #include "ppapi/c/pp_stdint.h" | 15 #include "ppapi/c/pp_stdint.h" |
19 | 16 |
| 17 /** |
| 18 * |
| 19 * @addtogroup Enums |
| 20 * @{ |
| 21 */ |
20 typedef enum { | 22 typedef enum { |
21 PP_VARTYPE_UNDEFINED, | 23 PP_VARTYPE_UNDEFINED, |
22 PP_VARTYPE_NULL, | 24 PP_VARTYPE_NULL, |
23 PP_VARTYPE_BOOL, | 25 PP_VARTYPE_BOOL, |
24 PP_VARTYPE_INT32, | 26 PP_VARTYPE_INT32, |
25 PP_VARTYPE_DOUBLE, | 27 PP_VARTYPE_DOUBLE, |
26 PP_VARTYPE_STRING, | 28 PP_VARTYPE_STRING, |
27 PP_VARTYPE_OBJECT | 29 PP_VARTYPE_OBJECT |
28 } PP_VarType; | 30 } PP_VarType; |
29 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); | 31 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); |
| 32 /** |
| 33 * @} |
| 34 */ |
| 35 |
| 36 /** |
| 37 * @addtogroup Structs |
| 38 * @{ |
| 39 */ |
30 | 40 |
31 /** | 41 /** |
32 * Do not rely on having a predictable and reproducible | 42 * Do not rely on having a predictable and reproducible |
33 * int/double differentiation. | 43 * int/double differentiation. |
34 * JavaScript has a "number" type for holding a number, and | 44 * JavaScript has a "number" type for holding a number, and |
35 * does not differentiate between floating point and integer numbers. The | 45 * does not differentiate between floating point and integer numbers. The |
36 * JavaScript library will try to optimize operations by using integers | 46 * JavaScript library will try to optimize operations by using integers |
37 * when possible, but could end up with doubles depending on how the number | 47 * when possible, but could end up with doubles depending on how the number |
38 * was arrived at. | 48 * was arrived at. |
39 * | 49 * |
40 * Your best bet is to have a wrapper for variables | 50 * Your best bet is to have a wrapper for variables |
41 * that always gets out the type you expect, converting as necessary. | 51 * that always gets out the type you expect, converting as necessary. |
| 52 * |
42 */ | 53 */ |
43 struct PP_Var { | 54 struct PP_Var { |
44 PP_VarType type; | 55 PP_VarType type; |
45 | 56 |
46 /** Ensures @a value is aligned on an 8-byte boundary relative to the | 57 /** Ensures @a value is aligned on an 8-byte boundary relative to the |
47 * start of the struct. Some compilers align doubles on 8-byte boundaries | 58 * start of the struct. Some compilers align doubles on 8-byte boundaries |
48 * for 32-bit x86, and some align on 4-byte boundaries. | 59 * for 32-bit x86, and some align on 4-byte boundaries. |
49 */ | 60 */ |
50 int32_t padding; | 61 int32_t padding; |
51 | 62 |
52 union { | 63 union { |
53 PP_Bool as_bool; | 64 PP_Bool as_bool; |
54 int32_t as_int; | 65 int32_t as_int; |
55 double as_double; | 66 double as_double; |
56 | 67 |
57 /** | 68 /** |
58 * Internal ID for strings and objects. The identifier is an opaque handle | 69 * Internal ID for strings and objects. The identifier is an opaque handle |
59 * assigned by the browser to the plugin. It is guaranteed never to be 0, | 70 * assigned by the browser to the plugin. It is guaranteed never to be 0, |
60 * so a plugin can initialize this ID to 0 to indicate a "NULL handle." | 71 * so a plugin can initialize this ID to 0 to indicate a "NULL handle." |
61 */ | 72 */ |
62 int64_t as_id; | 73 int64_t as_id; |
63 } value; | 74 } value; |
64 }; | 75 }; |
65 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); | 76 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); |
| 77 /** |
| 78 * @} |
| 79 */ |
66 | 80 |
| 81 /** |
| 82 * @addtogroup Functions |
| 83 * @{ |
| 84 */ |
67 PP_INLINE struct PP_Var PP_MakeUndefined() { | 85 PP_INLINE struct PP_Var PP_MakeUndefined() { |
68 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; | 86 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; |
69 return result; | 87 return result; |
70 } | 88 } |
71 | 89 |
72 PP_INLINE struct PP_Var PP_MakeNull() { | 90 PP_INLINE struct PP_Var PP_MakeNull() { |
73 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; | 91 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; |
74 return result; | 92 return result; |
75 } | 93 } |
76 | 94 |
77 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { | 95 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { |
78 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; | 96 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; |
79 result.value.as_bool = value; | 97 result.value.as_bool = value; |
80 return result; | 98 return result; |
81 } | 99 } |
82 | 100 |
83 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { | 101 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { |
84 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; | 102 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; |
85 result.value.as_int = value; | 103 result.value.as_int = value; |
86 return result; | 104 return result; |
87 } | 105 } |
88 | 106 |
89 PP_INLINE struct PP_Var PP_MakeDouble(double value) { | 107 PP_INLINE struct PP_Var PP_MakeDouble(double value) { |
90 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; | 108 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; |
91 result.value.as_double = value; | 109 result.value.as_double = value; |
92 return result; | 110 return result; |
93 } | 111 } |
94 | |
95 /** | 112 /** |
96 * @} | 113 * @} |
97 * End addtogroup PP | |
98 */ | 114 */ |
| 115 |
99 #endif /* PPAPI_C_PP_VAR_H_ */ | 116 #endif /* PPAPI_C_PP_VAR_H_ */ |
100 | 117 |
OLD | NEW |