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

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 David'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
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..b4064d3003c6a38aa9ddc46fef0d76b3e949b86b
--- /dev/null
+++ b/ppapi/cpp/dev/string_wrapper_dev.h
@@ -0,0 +1,88 @@
+// 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 it.
+ // |storage| must live longer than this object. The contents pointed to by
+ // |storage| must be zero-initialized by the caller.
+ 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_; }
+
+ 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 it.
+ // |storage| must live longer than this object. The contents pointed to by
+ // |storage| must be zero-initialized by the caller.
+ 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_

Powered by Google App Engine
This is Rietveld 408576698