| 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_CPP_VAR_H_ | 5 #ifndef PPAPI_CPP_VAR_H_ |
| 6 #define PPAPI_CPP_VAR_H_ | 6 #define PPAPI_CPP_VAR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ppapi/c/pp_module.h" | 11 #include "ppapi/c/pp_module.h" |
| 12 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
| 13 | 13 |
| 14 | 14 |
| 15 /// @file | 15 /// @file |
| 16 /// This file defines the API for handling the passing of data types between | 16 /// This file defines the API for handling the passing of data types between |
| 17 /// your module and the page. | 17 /// your module and the page. |
| 18 namespace pp { | 18 namespace pp { |
| 19 | 19 |
| 20 class Instance; | 20 class Instance; |
| 21 | 21 |
| 22 /// A generic type used for passing data types between the module and the page. | 22 /// A generic type used for passing data types between the module and the page. |
| 23 class Var { | 23 class Var { |
| 24 public: | 24 public: |
| 25 /// Special value passed to constructor to make </code>NULL<code>. | 25 /// Special value passed to constructor to make <code>NULL</code>. |
| 26 struct Null {}; | 26 struct Null {}; |
| 27 | 27 |
| 28 /// Default constructor. Creates a <code>Var</code> of type | 28 /// Default constructor. Creates a <code>Var</code> of type |
| 29 /// </code>Undefined</code>. | 29 /// <code>Undefined</code>. |
| 30 Var(); | 30 Var(); |
| 31 | 31 |
| 32 /// A constructor used to create a <code>Var</code> of type <code>Null</code>. | 32 /// A constructor used to create a <code>Var</code> of type <code>Null</code>. |
| 33 Var(Null); | 33 Var(Null); |
| 34 | 34 |
| 35 /// A constructor used to create a <code>Var</code> of type <code>Bool</code>. | 35 /// A constructor used to create a <code>Var</code> of type <code>Bool</code>. |
| 36 /// | 36 /// |
| 37 /// @param[in] b A boolean value. | 37 /// @param[in] b A boolean value. |
| 38 Var(bool b); | 38 Var(bool b); |
| 39 | 39 |
| 40 /// A constructor used to create a 32 bit integer <code>Var</code>. | 40 /// A constructor used to create a 32 bit integer <code>Var</code>. |
| 41 /// | 41 /// |
| 42 /// @param[in] i A 32 bit integer value. | 42 /// @param[in] i A 32 bit integer value. |
| 43 Var(int32_t i); | 43 Var(int32_t i); |
| 44 | 44 |
| 45 /// A constructor used to create a double value <code>Var</code>. | 45 /// A constructor used to create a double value <code>Var</code>. |
| 46 /// | 46 /// |
| 47 /// @param[in] d A double value. | 47 /// @param[in] d A double value. |
| 48 Var(double d); | 48 Var(double d); |
| 49 | 49 |
| 50 /// A constructor used to create a UTF-8 character <code>Var</code>. | 50 /// A constructor used to create a UTF-8 character <code>Var</code>. |
| 51 Var(const char* utf8_str); // Must be encoded in UTF-8. | 51 Var(const char* utf8_str); // Must be encoded in UTF-8. |
| 52 | 52 |
| 53 /// A constructor used to create a UTF-8 character <code>Var</code>. | 53 /// A constructor used to create a UTF-8 character <code>Var</code>. |
| 54 Var(const std::string& utf8_str); // Must be encoded in UTF-8. | 54 Var(const std::string& utf8_str); // Must be encoded in UTF-8. |
| 55 | 55 |
| 56 /// PassRef can be used to construct a <code>Var</code> with a | 56 /// PassRef can be used to construct a <code>Var</code> with a |
| 57 /// <code>PP_Var</code> when the </code>PP_Var</code> | 57 /// <code>PP_Var</code> when the <code>PP_Var</code> |
| 58 /// already has had its reference count incremented. For example: | 58 /// already has had its reference count incremented. For example: |
| 59 /// <code>pp::Var my_var(PassRef(), my_pp_var);</code> | 59 /// <code>pp::Var my_var(PassRef(), my_pp_var);</code> |
| 60 struct PassRef {}; | 60 struct PassRef {}; |
| 61 | 61 |
| 62 /// A constructor used when you have received a <code>Var</code> as a return | 62 /// A constructor used when you have received a <code>Var</code> as a return |
| 63 /// value that has had its reference count incremented for you. | 63 /// value that has had its reference count incremented for you. |
| 64 /// | 64 /// |
| 65 /// You will not normally need to use this constructor because | 65 /// You will not normally need to use this constructor because |
| 66 /// the reference count will not normally be incremented for you. | 66 /// the reference count will not normally be incremented for you. |
| 67 Var(PassRef, PP_Var var) { | 67 Var(PassRef, PP_Var var) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 /// @return True if this <code>Var</code> is null, otherwise False. | 116 /// @return True if this <code>Var</code> is null, otherwise False. |
| 117 bool is_null() const { return var_.type == PP_VARTYPE_NULL; } | 117 bool is_null() const { return var_.type == PP_VARTYPE_NULL; } |
| 118 | 118 |
| 119 /// This function determines if this <code>Var</code> is a bool value. | 119 /// This function determines if this <code>Var</code> is a bool value. |
| 120 /// | 120 /// |
| 121 /// @return True if this <code>Var</code> is a bool, otherwise False. | 121 /// @return True if this <code>Var</code> is a bool, otherwise False. |
| 122 bool is_bool() const { return var_.type == PP_VARTYPE_BOOL; } | 122 bool is_bool() const { return var_.type == PP_VARTYPE_BOOL; } |
| 123 | 123 |
| 124 /// This function determines if this <code>Var</code> is a string value. | 124 /// This function determines if this <code>Var</code> is a string value. |
| 125 /// | 125 /// |
| 126 /// @return True if this <code>Var </code>is a string, otherwise False. | 126 /// @return True if this <code>Var</code> is a string, otherwise False. |
| 127 bool is_string() const { return var_.type == PP_VARTYPE_STRING; } | 127 bool is_string() const { return var_.type == PP_VARTYPE_STRING; } |
| 128 | 128 |
| 129 /// This function determines if this </ode>Var</code> is an object. | 129 /// This function determines if this <code>Var</code> is an object. |
| 130 /// | 130 /// |
| 131 /// @return True if this <code>Var</code> is an object, otherwise False. | 131 /// @return True if this <code>Var</code> is an object, otherwise False. |
| 132 bool is_object() const { return var_.type == PP_VARTYPE_OBJECT; } | 132 bool is_object() const { return var_.type == PP_VARTYPE_OBJECT; } |
| 133 | 133 |
| 134 /// This function determines if this <code>Var</code> is an integer value. | 134 /// This function determines if this <code>Var</code> is an integer value. |
| 135 /// The <code>is_int</code> function returns the internal representation. | 135 /// The <code>is_int</code> function returns the internal representation. |
| 136 /// The JavaScript runtime may convert between the two as needed, so the | 136 /// The JavaScript runtime may convert between the two as needed, so the |
| 137 /// distinction may not be relevant in all cases (int is really an | 137 /// distinction may not be relevant in all cases (int is really an |
| 138 /// optimization inside the runtime). So most of the time, you will want | 138 /// optimization inside the runtime). So most of the time, you will want |
| 139 /// to check is_number(). | 139 /// to check is_number(). |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // Prevent an arbitrary pointer argument from being implicitly converted to | 292 // Prevent an arbitrary pointer argument from being implicitly converted to |
| 293 // a bool at Var construction. If somebody makes such a mistake, (s)he will | 293 // a bool at Var construction. If somebody makes such a mistake, (s)he will |
| 294 // get a compilation error. | 294 // get a compilation error. |
| 295 Var(void* non_scriptable_object_pointer); | 295 Var(void* non_scriptable_object_pointer); |
| 296 | 296 |
| 297 }; | 297 }; |
| 298 | 298 |
| 299 } // namespace pp | 299 } // namespace pp |
| 300 | 300 |
| 301 #endif // PPAPI_CPP_VAR_H_ | 301 #endif // PPAPI_CPP_VAR_H_ |
| OLD | NEW |