| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_ |
| 6 #define PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "ppapi/c/pp_var.h" |
| 11 #include "ppapi/cpp/dev/may_own_ptr_dev.h" |
| 12 |
| 13 namespace pp { |
| 14 namespace internal { |
| 15 |
| 16 // An optional string backed by a PP_Var. When the string is not set, the type |
| 17 // of the PP_Var is set to PP_VARTYPE_UNDEFINED; otherwise, it is set to |
| 18 // PP_VARTYPE_STRING. |
| 19 class OptionalStringWrapper { |
| 20 public: |
| 21 OptionalStringWrapper(); |
| 22 |
| 23 explicit OptionalStringWrapper(const std::string& value); |
| 24 |
| 25 // Creates an accessor to |storage| but doesn't take ownership of it. |
| 26 // |storage| must live longer than this object. The contents pointed to by |
| 27 // |storage| must be zero-initialized by the caller. |
| 28 OptionalStringWrapper(PP_Var* storage, NotOwned); |
| 29 |
| 30 OptionalStringWrapper(const OptionalStringWrapper& other); |
| 31 |
| 32 ~OptionalStringWrapper(); |
| 33 |
| 34 OptionalStringWrapper& operator=(const OptionalStringWrapper& other); |
| 35 OptionalStringWrapper& operator=(const PP_Var& other); |
| 36 |
| 37 bool is_set() const; |
| 38 void unset(); |
| 39 std::string get() const; |
| 40 void set(const std::string& value); |
| 41 |
| 42 const PP_Var& ToVar() const { return *storage_; } |
| 43 |
| 44 PP_Var* StartRawUpdate(); |
| 45 void EndRawUpdate(); |
| 46 |
| 47 private: |
| 48 MayOwnPtr<PP_Var> storage_; |
| 49 }; |
| 50 |
| 51 // A string backed by a PP_Var whose type is PP_VARTYPE_STRING. |
| 52 class StringWrapper { |
| 53 public: |
| 54 StringWrapper(); |
| 55 |
| 56 explicit StringWrapper(const std::string& value); |
| 57 |
| 58 // Creates an accessor to |storage| but doesn't take ownership of it. |
| 59 // |storage| must live longer than this object. The contents pointed to by |
| 60 // |storage| must be zero-initialized by the caller. |
| 61 StringWrapper(PP_Var* storage, NotOwned); |
| 62 |
| 63 StringWrapper(const StringWrapper& other); |
| 64 |
| 65 ~StringWrapper(); |
| 66 |
| 67 StringWrapper& operator=(const StringWrapper& other); |
| 68 StringWrapper& operator=(const PP_Var& other); |
| 69 |
| 70 std::string get() const { return storage_.get(); } |
| 71 void set(const std::string& value) { return storage_.set(value); } |
| 72 |
| 73 const PP_Var& ToVar() const { return storage_.ToVar(); } |
| 74 |
| 75 // Sets the underlying PP_Var to undefined before returning it. |
| 76 PP_Var* StartRawUpdate(); |
| 77 // If the underlying PP_Var wasn't updated to a valid string, sets it to an |
| 78 // empty string. |
| 79 void EndRawUpdate(); |
| 80 |
| 81 private: |
| 82 OptionalStringWrapper storage_; |
| 83 }; |
| 84 |
| 85 } // namespace internal |
| 86 } // namespace pp |
| 87 |
| 88 #endif // PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_ |
| OLD | NEW |