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

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 * This file defines the API for handling the passing of data types between
15 * your module and the page.
15 */ 16 */
16 17
17 /** 18 /**
18 * 19 *
19 * @addtogroup Enums 20 * @addtogroup Enums
20 * @{ 21 * @{
21 */ 22 */
23
24 /**
25 * PP_VarType is an enumeration of the different types that can be contained
26 * within a PP_VAR structure.
27 */
22 typedef enum { 28 typedef enum {
23 PP_VARTYPE_UNDEFINED, 29 PP_VARTYPE_UNDEFINED,
24 PP_VARTYPE_NULL, 30 PP_VARTYPE_NULL,
25 PP_VARTYPE_BOOL, 31 PP_VARTYPE_BOOL,
26 PP_VARTYPE_INT32, 32 PP_VARTYPE_INT32,
27 PP_VARTYPE_DOUBLE, 33 PP_VARTYPE_DOUBLE,
28 PP_VARTYPE_STRING, 34 PP_VARTYPE_STRING,
29 PP_VARTYPE_OBJECT 35 PP_VARTYPE_OBJECT
30 } PP_VarType; 36 } PP_VarType;
31 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); 37 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4);
32 /** 38 /**
33 * @} 39 * @}
34 */ 40 */
35 41
36 /** 42 /**
37 * @addtogroup Structs 43 * @addtogroup Structs
38 * @{ 44 * @{
39 */ 45 */
40 46
41 /** 47 /**
42 * Do not rely on having a predictable and reproducible 48 * The PP_VAR struct is a variant data type and can contain any
43 * int/double differentiation. 49 * value represented by the PP_VarType enum. This structure is for
dmichael(do not use this one) 2011/02/02 20:12:59 maybe instead of 'any value represented by the PP_
jond 2011/02/02 20:34:39 Done.
44 * JavaScript has a "number" type for holding a number, and 50 * passing data between native code which can be strongly typed and the browser
45 * does not differentiate between floating point and integer numbers. The 51 * (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 * 52 *
50 * Your best bet is to have a wrapper for variables 53 * JavaScript has a "number" type for holding a number, and does not
51 * that always gets out the type you expect, converting as necessary. 54 * differentiate between floating point and integer numbers. The
52 * 55 * JavaScript operations will try to optimize operations by using
56 * integers when possible, but could end up with doubles. Therefore,
57 * you can't assume a numeric PP_Var will be the type you expect.
58 * Your code should be capable of handle either int32_t or double for numeric
dmichael(do not use this one) 2011/02/02 20:12:59 handle->handling (my fault)
jond 2011/02/02 20:34:39 Done.
jond 2011/02/02 20:34:39 Done.
59 * PP_Vars sent from JavaScript.
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