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

Unified 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 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/cpp/dev/string_wrapper_dev.h
diff --git a/ppapi/cpp/dev/string_wrapper_dev.h b/ppapi/cpp/dev/string_wrapper_dev.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c6ceb4e7a50a902365b0969384a37311701989c
--- /dev/null
+++ b/ppapi/cpp/dev/string_wrapper_dev.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_
+#define PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_
+
+#include <string>
+
+#include "ppapi/c/pp_var.h"
+#include "ppapi/cpp/dev/may_own_ptr_dev.h"
+
+namespace pp {
+namespace internal {
+
+// An optional string backed by a PP_Var. When the string is not set, the type
+// of the PP_Var is set to PP_VARTYPE_UNDEFINED; otherwise, it is set to
+// PP_VARTYPE_STRING.
+class OptionalStringWrapper {
+ public:
+ OptionalStringWrapper();
+
+ explicit OptionalStringWrapper(const std::string& value);
+
+ // Creates an accessor to |storage| but doesn't take ownership of the memory.
+ // |storage| must live longer than this object.
+ //
+ // Although this object doesn't own the memory of |storage|, it manages the
+ // ref count and sets the var to undefined when destructed.
+ OptionalStringWrapper(PP_Var* storage, NotOwned);
+
+ OptionalStringWrapper(const OptionalStringWrapper& other);
+
+ ~OptionalStringWrapper();
+
+ OptionalStringWrapper& operator=(const OptionalStringWrapper& other);
+ OptionalStringWrapper& operator=(const PP_Var& other);
+
+ bool is_set() const;
+ void unset();
+ std::string get() const;
+ void set(const std::string& value);
+
+ const PP_Var& ToVar() const { return *storage_; }
+
+ // Sets the underlying PP_Var to undefined before returning it.
+ PP_Var* StartRawUpdate();
+ void EndRawUpdate();
+
+ private:
+ MayOwnPtr<PP_Var> storage_;
+};
+
+// A string backed by a PP_Var whose type is PP_VARTYPE_STRING.
+class StringWrapper {
+ public:
+ StringWrapper();
+
+ explicit StringWrapper(const std::string& value);
+
+ // Creates an accessor to |storage| but doesn't take ownership of the memory.
+ // |storage| must live longer than this object.
+ //
+ // Although this object doesn't own the memory of |storage|, it manages the
+ // ref count and sets the var to undefined when destructed.
+ StringWrapper(PP_Var* storage, NotOwned);
+
+ StringWrapper(const StringWrapper& other);
+
+ ~StringWrapper();
+
+ StringWrapper& operator=(const StringWrapper& other);
+ StringWrapper& operator=(const PP_Var& other);
+
+ std::string get() const { return storage_.get(); }
+ void set(const std::string& value) { return storage_.set(value); }
+
+ const PP_Var& ToVar() const { return storage_.ToVar(); }
+
+ // Sets the underlying PP_Var to undefined before returning it.
+ PP_Var* StartRawUpdate();
+ // If the underlying PP_Var wasn't updated to a valid string, sets it to an
+ // empty string.
+ void EndRawUpdate();
+
+ private:
+ OptionalStringWrapper storage_;
+};
+
+} // namespace internal
+} // namespace pp
+
+#endif // PPAPI_CPP_DEV_STRING_WRAPPER_DEV_H_
« 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