OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_var.h" | 11 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/cpp/pass_ref.h" | 12 #include "ppapi/cpp/pass_ref.h" |
13 #include "ppapi/cpp/resource.h" | |
13 | 14 |
14 /// @file | 15 /// @file |
15 /// 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 |
16 /// your module and the page. | 17 /// your module and the page. |
17 namespace pp { | 18 namespace pp { |
18 | 19 |
19 /// A generic type used for passing data types between the module and the page. | 20 /// A generic type used for passing data types between the module and the page. |
20 class Var { | 21 class Var { |
21 public: | 22 public: |
22 /// Special value passed to constructor to make <code>NULL</code>. | 23 /// Special value passed to constructor to make <code>NULL</code>. |
(...skipping 20 matching lines...) Expand all Loading... | |
43 /// | 44 /// |
44 /// @param[in] d A double value. | 45 /// @param[in] d A double value. |
45 Var(double d); | 46 Var(double d); |
46 | 47 |
47 /// A constructor used to create a UTF-8 character <code>Var</code>. | 48 /// A constructor used to create a UTF-8 character <code>Var</code>. |
48 Var(const char* utf8_str); // Must be encoded in UTF-8. | 49 Var(const char* utf8_str); // Must be encoded in UTF-8. |
49 | 50 |
50 /// A constructor used to create a UTF-8 character <code>Var</code>. | 51 /// A constructor used to create a UTF-8 character <code>Var</code>. |
51 Var(const std::string& utf8_str); // Must be encoded in UTF-8. | 52 Var(const std::string& utf8_str); // Must be encoded in UTF-8. |
52 | 53 |
54 /// A constructor used to create a resource <code>Var</code>. | |
55 explicit Var(const pp::Resource& resource); | |
yzshen1
2014/02/06 18:02:58
Now that all the others are not 'explicit', maybe
dmichael (off chromium)
2014/02/06 18:33:14
I think I prefer that the developer has to know th
yzshen1
2014/02/06 19:58:18
I slightly prefer to be consistent. But I am fine
Matt Giuca
2014/02/07 03:11:22
I briefly discussed this with sammc@ yesterday. He
dmichael (off chromium)
2014/02/07 17:45:28
I agree in thinking this one is a little different
yzshen1
2014/02/07 17:49:36
Yeah. Your argument makes good sense. I agree we s
| |
56 | |
53 /// A constructor used when you have received a <code>Var</code> as a return | 57 /// A constructor used when you have received a <code>Var</code> as a return |
54 /// value that has had its reference count incremented for you. | 58 /// value that has had its reference count incremented for you. |
55 /// | 59 /// |
56 /// You will not normally need to use this constructor because | 60 /// You will not normally need to use this constructor because |
57 /// the reference count will not normally be incremented for you. | 61 /// the reference count will not normally be incremented for you. |
58 Var(PassRef, const PP_Var& var) { | 62 Var(PassRef, const PP_Var& var) { |
59 var_ = var; | 63 var_ = var; |
60 is_managed_ = true; | 64 is_managed_ = true; |
61 } | 65 } |
62 | 66 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 /// | 208 /// |
205 /// @return An double version of this <code>Var</code>. | 209 /// @return An double version of this <code>Var</code>. |
206 double AsDouble() const; | 210 double AsDouble() const; |
207 | 211 |
208 /// AsString() converts this <code>Var</code> to a string. If this object is | 212 /// AsString() converts this <code>Var</code> to a string. If this object is |
209 /// not a string, it will assert in debug mode, and return an empty string. | 213 /// not a string, it will assert in debug mode, and return an empty string. |
210 /// | 214 /// |
211 /// @return A string version of this <code>Var</code>. | 215 /// @return A string version of this <code>Var</code>. |
212 std::string AsString() const; | 216 std::string AsString() const; |
213 | 217 |
218 /// Gets the resource contained in the var. | |
219 /// | |
220 /// @return The <code>pp::Resource</code> that is contained in the var. | |
221 pp::Resource AsResource() const; | |
222 | |
214 /// This function returns the internal <code>PP_Var</code> | 223 /// This function returns the internal <code>PP_Var</code> |
215 /// managed by this <code>Var</code> object. | 224 /// managed by this <code>Var</code> object. |
216 /// | 225 /// |
217 /// @return A const reference to a <code>PP_Var</code>. | 226 /// @return A const reference to a <code>PP_Var</code>. |
218 const PP_Var& pp_var() const { | 227 const PP_Var& pp_var() const { |
219 return var_; | 228 return var_; |
220 } | 229 } |
221 | 230 |
222 /// Detach() detaches from the internal <code>PP_Var</code> of this | 231 /// Detach() detaches from the internal <code>PP_Var</code> of this |
223 /// object, keeping the reference count the same. This is used when returning | 232 /// object, keeping the reference count the same. This is used when returning |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 private: | 315 private: |
307 // Prevent an arbitrary pointer argument from being implicitly converted to | 316 // Prevent an arbitrary pointer argument from being implicitly converted to |
308 // a bool at Var construction. If somebody makes such a mistake, (s)he will | 317 // a bool at Var construction. If somebody makes such a mistake, (s)he will |
309 // get a compilation error. | 318 // get a compilation error. |
310 Var(void* non_scriptable_object_pointer); | 319 Var(void* non_scriptable_object_pointer); |
311 }; | 320 }; |
312 | 321 |
313 } // namespace pp | 322 } // namespace pp |
314 | 323 |
315 #endif // PPAPI_CPP_VAR_H_ | 324 #endif // PPAPI_CPP_VAR_H_ |
OLD | NEW |