| 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 // It doesn't take ownership of |storage|, therefore |storage| must live |
| 26 // longer than this object. |storage| must be zero-initialized. |
| 27 OptionalStringWrapper(PP_Var* storage, NotOwned); |
| 28 |
| 29 OptionalStringWrapper(const OptionalStringWrapper& other); |
| 30 |
| 31 ~OptionalStringWrapper(); |
| 32 |
| 33 OptionalStringWrapper& operator=(const OptionalStringWrapper& other); |
| 34 OptionalStringWrapper& operator=(const PP_Var& other); |
| 35 |
| 36 bool is_set() const; |
| 37 void unset(); |
| 38 std::string get() const; |
| 39 void set(const std::string& value); |
| 40 |
| 41 const PP_Var& ToVar() const { return *storage_; } |
| 42 |
| 43 PP_Var* StartRawUpdate(); |
| 44 void EndRawUpdate(); |
| 45 |
| 46 private: |
| 47 MayOwnPtr<PP_Var> storage_; |
| 48 }; |
| 49 |
| 50 // A string backed by a PP_Var whose type is PP_VARTYPE_STRING. |
| 51 class StringWrapper { |
| 52 public: |
| 53 StringWrapper(); |
| 54 |
| 55 explicit StringWrapper(const std::string& value); |
| 56 |
| 57 // It doesn't take ownership of |storage|, therefore |storage| must live |
| 58 // longer than this object. |storage| must be zero-initialized. |
| 59 StringWrapper(PP_Var* storage, NotOwned); |
| 60 |
| 61 StringWrapper(const StringWrapper& other); |
| 62 |
| 63 ~StringWrapper(); |
| 64 |
| 65 StringWrapper& operator=(const StringWrapper& other); |
| 66 StringWrapper& operator=(const PP_Var& other); |
| 67 |
| 68 std::string get() const { return storage_.get(); } |
| 69 void set(const std::string& value) { return storage_.set(value); } |
| 70 |
| 71 const PP_Var& ToVar() const { return storage_.ToVar(); } |
| 72 |
| 73 // Sets the underlying PP_Var to undefined before returning it. |
| 74 PP_Var* StartRawUpdate(); |
| 75 // If the underlying PP_Var wasn't updated to a valid string, sets it to an |
| 76 // empty string. |
| 77 void EndRawUpdate(); |
| 78 |
| 79 private: |
| 80 OptionalStringWrapper storage_; |
| 81 }; |
| 82 |
| 83 } // namespace internal |
| 84 } // namespace pp |
| 85 |
| 86 #endif // PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_ |
| OLD | NEW |