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

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

Issue 4310002: Make PPAPI headers compile with C compilers (gcc on Linux & Mac and MSVS on W... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | « ppapi/c/pp_size.h ('k') | ppapi/c/ppb_class.h » ('j') | no next file with comments »
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 /** 8 /**
9 * @file 9 * @file
10 * Defines the API ... 10 * Defines the API ...
11 * 11 *
12 * @addtogroup PP 12 * @addtogroup PP
13 * @{ 13 * @{
14 */ 14 */
15 15
16 #include "ppapi/c/pp_bool.h"
17 #include "ppapi/c/pp_macros.h"
16 #include "ppapi/c/pp_stdint.h" 18 #include "ppapi/c/pp_stdint.h"
17 19
18 typedef enum { 20 typedef enum {
19 PP_VARTYPE_UNDEFINED, 21 PP_VARTYPE_UNDEFINED,
20 PP_VARTYPE_NULL, 22 PP_VARTYPE_NULL,
21 PP_VARTYPE_BOOL, 23 PP_VARTYPE_BOOL,
22 PP_VARTYPE_INT32, 24 PP_VARTYPE_INT32,
23 PP_VARTYPE_DOUBLE, 25 PP_VARTYPE_DOUBLE,
24 PP_VARTYPE_STRING, 26 PP_VARTYPE_STRING,
25 PP_VARTYPE_OBJECT 27 PP_VARTYPE_OBJECT
26 } PP_VarType; 28 } PP_VarType;
27 29
28 /** 30 /**
29 * Do not rely on having a predictable and reproducible 31 * Do not rely on having a predictable and reproducible
30 * int/double differentiation. 32 * int/double differentiation.
31 * JavaScript has a "number" type for holding a number, and 33 * JavaScript has a "number" type for holding a number, and
32 * does not differentiate between floating point and integer numbers. The 34 * does not differentiate between floating point and integer numbers. The
33 * JavaScript library will try to optimize operations by using integers 35 * JavaScript library will try to optimize operations by using integers
34 * when possible, but could end up with doubles depending on how the number 36 * when possible, but could end up with doubles depending on how the number
35 * was arrived at. 37 * was arrived at.
36 * 38 *
37 * Your best bet is to have a wrapper for variables 39 * Your best bet is to have a wrapper for variables
38 * that always gets out the type you expect, converting as necessary. 40 * that always gets out the type you expect, converting as necessary.
39 */ 41 */
40 struct PP_Var { 42 struct PP_Var {
41 PP_VarType type; 43 PP_VarType type;
42 union { 44 union {
43 bool as_bool; 45 PP_Bool as_bool;
44 int32_t as_int; 46 int32_t as_int;
45 double as_double; 47 double as_double;
46 48
47 /** 49 /**
48 * Internal ID for strings and objects. The identifier is an opaque handle 50 * Internal ID for strings and objects. The identifier is an opaque handle
49 * assigned by the browser to the plugin. It is guaranteed never to be 0, 51 * assigned by the browser to the plugin. It is guaranteed never to be 0,
50 * so a plugin can initialize this ID to 0 to indicate a "NULL handle." 52 * so a plugin can initialize this ID to 0 to indicate a "NULL handle."
51 */ 53 */
52 int64_t as_id; 54 int64_t as_id;
53 } value; 55 } value;
54 }; 56 };
55 57
56 inline struct PP_Var PP_MakeUndefined() { 58 PP_INLINE struct PP_Var PP_MakeUndefined() {
57 struct PP_Var result = { PP_VARTYPE_UNDEFINED, {0} }; 59 struct PP_Var result = { PP_VARTYPE_UNDEFINED, {PP_FALSE} };
58 return result; 60 return result;
59 } 61 }
60 62
61 inline struct PP_Var PP_MakeNull() { 63 PP_INLINE struct PP_Var PP_MakeNull() {
62 struct PP_Var result = { PP_VARTYPE_NULL, {0} }; 64 struct PP_Var result = { PP_VARTYPE_NULL, {PP_FALSE} };
63 return result; 65 return result;
64 } 66 }
65 67
66 inline struct PP_Var PP_MakeBool(bool value) { 68 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) {
67 struct PP_Var result = { PP_VARTYPE_BOOL, {0} }; 69 struct PP_Var result = { PP_VARTYPE_BOOL, {PP_FALSE} };
68 result.value.as_bool = value; 70 result.value.as_bool = value;
69 return result; 71 return result;
70 } 72 }
71 73
72 inline struct PP_Var PP_MakeInt32(int32_t value) { 74 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) {
73 PP_Var result = { PP_VARTYPE_INT32, {0} }; 75 struct PP_Var result = { PP_VARTYPE_INT32, {PP_FALSE} };
74 result.value.as_int = value; 76 result.value.as_int = value;
75 return result; 77 return result;
76 } 78 }
77 79
78 inline struct PP_Var PP_MakeDouble(double value) { 80 PP_INLINE struct PP_Var PP_MakeDouble(double value) {
79 PP_Var result = { PP_VARTYPE_DOUBLE, {0} }; 81 struct PP_Var result = { PP_VARTYPE_DOUBLE, {PP_FALSE} };
80 result.value.as_double = value; 82 result.value.as_double = value;
81 return result; 83 return result;
82 } 84 }
83 85
84 /** 86 /**
85 * @} 87 * @}
86 * End addtogroup PP 88 * End addtogroup PP
87 */ 89 */
88 #endif // PPAPI_C_PP_VAR_H_ 90 #endif // PPAPI_C_PP_VAR_H_
OLDNEW
« no previous file with comments | « ppapi/c/pp_size.h ('k') | ppapi/c/ppb_class.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698