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

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

Powered by Google App Engine
This is Rietveld 408576698