Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: ppapi/c/pp_var.h

Issue 6286018: Updated descriptions to several functions, structs, enums (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/c/ppp.h » ('j') | ppapi/c/ppp.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ppapi/c/pp_bool.h" 8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_macros.h" 9 #include "ppapi/c/pp_macros.h"
10 #include "ppapi/c/pp_stdint.h" 10 #include "ppapi/c/pp_stdint.h"
11 11
12 /** 12 /**
13 * @file 13 * @file
14 * Defines the API ... 14 * Defines the API ...
15 */ 15 */
16 16
17 /** 17 /**
18 * 18 *
19 * @addtogroup Enums 19 * @addtogroup Enums
20 * @{ 20 * @{
21 */ 21 */
22
23 /**
24 * PP_VarType is an enumeration of the different types that can be contained
25 * within a PP_VAR structure.
26 */
22 typedef enum { 27 typedef enum {
23 PP_VARTYPE_UNDEFINED, 28 PP_VARTYPE_UNDEFINED,
24 PP_VARTYPE_NULL, 29 PP_VARTYPE_NULL,
25 PP_VARTYPE_BOOL, 30 PP_VARTYPE_BOOL,
26 PP_VARTYPE_INT32, 31 PP_VARTYPE_INT32,
27 PP_VARTYPE_DOUBLE, 32 PP_VARTYPE_DOUBLE,
28 PP_VARTYPE_STRING, 33 PP_VARTYPE_STRING,
29 PP_VARTYPE_OBJECT 34 PP_VARTYPE_OBJECT
30 } PP_VarType; 35 } PP_VarType;
31 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); 36 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4);
32 /** 37 /**
33 * @} 38 * @}
34 */ 39 */
35 40
36 /** 41 /**
37 * @addtogroup Structs 42 * @addtogroup Structs
38 * @{ 43 * @{
39 */ 44 */
40 45
41 /** 46 /**
42 * Do not rely on having a predictable and reproducible 47 * PP_VAR is a struct that represents a variant data type and can contain any
Sang Ahn 2011/02/01 19:19:00 PP_VAR does not represent a variant data type; it
jond 2011/02/02 16:54:51 Fixed.
43 * int/double differentiation. 48 * value, such as a bool, int32, double, or string. This structure is for
dmichael(do not use this one) 2011/02/01 22:17:22 'int32' -> int32_t 'or string' -> 'string, or obje
jond 2011/02/02 16:54:51 It says this now: "The PP_VAR struct is a variant
44 * JavaScript has a "number" type for holding a number, and 49 * passing data between native code which can be strongly typed and the browser
45 * does not differentiate between floating point and integer numbers. The 50 * (JavaScript) which isn't strongly typed.
46 * JavaScript library will try to optimize operations by using integers
47 * when possible, but could end up with doubles depending on how the number
48 * was arrived at.
49 * 51 *
50 * Your best bet is to have a wrapper for variables 52 * You cannot rely on having a predictable and reproducible int/double
51 * that always gets out the type you expect, converting as necessary. 53 * differentiation in JavaScript. JavaScript has a "number" type for holding
54 * a number, and does not differentiate between floating point and integer
55 * numbers. The JavaScript library will try to optimize operations by using
Sang Ahn 2011/02/01 19:19:00 Javascript library -> Javascript operations ie "Ja
jond 2011/02/02 16:54:51 Fixed. On 2011/02/01 19:19:00, Sang Ahn wrote:
56 * integers when possible, but could end up with doubles.
52 * 57 *
58 * PP_Var represents the best solution of using a wrapper for variables
59 * that always returns the type you expect (converting as necessary).
dmichael(do not use this one) 2011/02/01 22:17:22 I don't believe this is true. PPB_Var has a funct
53 */ 60 */
54 struct PP_Var { 61 struct PP_Var {
55 PP_VarType type; 62 PP_VarType type;
56 63
57 /** Ensures @a value is aligned on an 8-byte boundary relative to the 64 /** Ensures @a value is aligned on an 8-byte boundary relative to the
58 * start of the struct. Some compilers align doubles on 8-byte boundaries 65 * start of the struct. Some compilers align doubles on 8-byte boundaries
59 * for 32-bit x86, and some align on 4-byte boundaries. 66 * for 32-bit x86, and some align on 4-byte boundaries.
60 */ 67 */
61 int32_t padding; 68 int32_t padding;
62 69
(...skipping 12 matching lines...) Expand all
75 }; 82 };
76 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); 83 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16);
77 /** 84 /**
78 * @} 85 * @}
79 */ 86 */
80 87
81 /** 88 /**
82 * @addtogroup Functions 89 * @addtogroup Functions
83 * @{ 90 * @{
84 */ 91 */
92
93 /**
94 * PP_MakeUndefined() is a utility function used to wrap an undefined value
95 * into a PP_VAR struct for passing to the browser.
96 * @return A PP_Var structure
97 */
85 PP_INLINE struct PP_Var PP_MakeUndefined() { 98 PP_INLINE struct PP_Var PP_MakeUndefined() {
86 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; 99 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} };
87 return result; 100 return result;
88 } 101 }
89 102
103 /**
104 * PP_MakeNull() is a utility function used to wrap a null value into a
105 * PP_VAR struct for passing to the browser.
106 * @return A PP_Var structure
107 */
90 PP_INLINE struct PP_Var PP_MakeNull() { 108 PP_INLINE struct PP_Var PP_MakeNull() {
91 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; 109 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} };
92 return result; 110 return result;
93 } 111 }
94 112
113 /**
114 * PP_MakeBool() is a utility function used to wrap a boolean value into a
115 * PP_VAR struct for passing to the browser.
116 * @param[in] value A PP_Bool enumeration
117 * @return A PP_Var structure
118 */
95 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { 119 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) {
96 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; 120 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} };
97 result.value.as_bool = value; 121 result.value.as_bool = value;
98 return result; 122 return result;
99 } 123 }
100 124
125 /**
126 * PP_MakeInt32() is a utility function used to wrap a 32 bit integer value
127 * into a PP_VAR struct for passing to the browser.
128 * @param[in] value An int32
129 * @return A PP_Var structure
130 */
101 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { 131 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) {
102 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; 132 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} };
103 result.value.as_int = value; 133 result.value.as_int = value;
104 return result; 134 return result;
105 } 135 }
106 136
137 /**
138 * PP_MakeDouble() is a utility function used to wrap a double value into a
139 * PP_VAR struct for passing to the browser.
140 * @param[in] value A double
141 * @return A PP_Var structure
142 */
107 PP_INLINE struct PP_Var PP_MakeDouble(double value) { 143 PP_INLINE struct PP_Var PP_MakeDouble(double value) {
108 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; 144 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} };
109 result.value.as_double = value; 145 result.value.as_double = value;
110 return result; 146 return result;
111 } 147 }
112 /** 148 /**
113 * @} 149 * @}
114 */ 150 */
115 151
116 #endif /* PPAPI_C_PP_VAR_H_ */ 152 #endif /* PPAPI_C_PP_VAR_H_ */
117 153
OLDNEW
« no previous file with comments | « no previous file | ppapi/c/ppp.h » ('j') | ppapi/c/ppp.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698