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

Side by Side Diff: ppapi/cpp/dev/string_wrapper_dev.h

Issue 116963003: App APIs in Pepper: C++ APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes according to Sam's suggestions. Created 6 years, 11 months 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
« no previous file with comments | « ppapi/cpp/dev/optional_dev.h ('k') | ppapi/cpp/dev/string_wrapper_dev.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 the memory.
26 // |storage| must live longer than this object.
27 //
28 // Although this object doesn't own the memory of |storage|, it manages the
29 // ref count and sets the var to undefined when destructed.
30 OptionalStringWrapper(PP_Var* storage, NotOwned);
31
32 OptionalStringWrapper(const OptionalStringWrapper& other);
33
34 ~OptionalStringWrapper();
35
36 OptionalStringWrapper& operator=(const OptionalStringWrapper& other);
37 OptionalStringWrapper& operator=(const PP_Var& other);
38
39 bool is_set() const;
40 void unset();
41 std::string get() const;
42 void set(const std::string& value);
43
44 const PP_Var& ToVar() const { return *storage_; }
45
46 // Sets the underlying PP_Var to undefined before returning it.
47 PP_Var* StartRawUpdate();
48 void EndRawUpdate();
49
50 private:
51 MayOwnPtr<PP_Var> storage_;
52 };
53
54 // A string backed by a PP_Var whose type is PP_VARTYPE_STRING.
55 class StringWrapper {
56 public:
57 StringWrapper();
58
59 explicit StringWrapper(const std::string& value);
60
61 // Creates an accessor to |storage| but doesn't take ownership of the memory.
62 // |storage| must live longer than this object.
63 //
64 // Although this object doesn't own the memory of |storage|, it manages the
65 // ref count and sets the var to undefined when destructed.
66 StringWrapper(PP_Var* storage, NotOwned);
67
68 StringWrapper(const StringWrapper& other);
69
70 ~StringWrapper();
71
72 StringWrapper& operator=(const StringWrapper& other);
73 StringWrapper& operator=(const PP_Var& other);
74
75 std::string get() const { return storage_.get(); }
76 void set(const std::string& value) { return storage_.set(value); }
77
78 const PP_Var& ToVar() const { return storage_.ToVar(); }
79
80 // Sets the underlying PP_Var to undefined before returning it.
81 PP_Var* StartRawUpdate();
82 // If the underlying PP_Var wasn't updated to a valid string, sets it to an
83 // empty string.
84 void EndRawUpdate();
85
86 private:
87 OptionalStringWrapper storage_;
88 };
89
90 } // namespace internal
91 } // namespace pp
92
93 #endif // PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/optional_dev.h ('k') | ppapi/cpp/dev/string_wrapper_dev.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698