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

Unified Diff: ppapi/cpp/var_dictionary.cc

Issue 16136009: Move PPB_VarArray and PPB_VarDictionary out of dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/cpp/var_dictionary.cc
diff --git a/ppapi/cpp/var_dictionary.cc b/ppapi/cpp/var_dictionary.cc
new file mode 100644
index 0000000000000000000000000000000000000000..45c4ad9bddc9e400c280c77bff75b84702131652
--- /dev/null
+++ b/ppapi/cpp/var_dictionary.cc
@@ -0,0 +1,110 @@
+// 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.
+
+#include "ppapi/cpp/var_dictionary.h"
+
+#include "ppapi/c/ppb_var_dictionary.h"
+#include "ppapi/cpp/logging.h"
+#include "ppapi/cpp/module_impl.h"
+
+namespace pp {
+
+namespace {
+
+template <> const char* interface_name<PPB_VarDictionary_1_0>() {
+ return PPB_VAR_DICTIONARY_INTERFACE_1_0;
+}
+
+} // namespace
+
+VarDictionary::VarDictionary() : Var(Null()) {
+ if (has_interface<PPB_VarDictionary_1_0>())
+ var_ = get_interface<PPB_VarDictionary_1_0>()->Create();
+ else
+ PP_NOTREACHED();
+}
+
+VarDictionary::VarDictionary(const Var& var) : Var(var) {
+ if (!var.is_dictionary()) {
+ PP_NOTREACHED();
+
+ // This takes care of releasing the reference that this object holds.
+ Var::operator=(Var(Null()));
+ }
+}
+
+VarDictionary::VarDictionary(const PP_Var& var) : Var(var) {
+ if (var.type != PP_VARTYPE_DICTIONARY) {
+ PP_NOTREACHED();
+
+ // This takes care of releasing the reference that this object holds.
+ Var::operator=(Var(Null()));
+ }
+}
+
+VarDictionary::VarDictionary(const VarDictionary& other)
+ : Var(other) {
+}
+
+VarDictionary::~VarDictionary() {
+}
+
+VarDictionary& VarDictionary::operator=(
+ const VarDictionary& other) {
+ Var::operator=(other);
+ return *this;
+}
+
+Var& VarDictionary::operator=(const Var& other) {
+ if (other.is_dictionary()) {
+ Var::operator=(other);
+ } else {
+ PP_NOTREACHED();
+ Var::operator=(Var(Null()));
+ }
+ return *this;
+}
+
+Var VarDictionary::Get(const Var& key) const {
+ if (!has_interface<PPB_VarDictionary_1_0>())
+ return Var();
+
+ return Var(
+ PASS_REF,
+ get_interface<PPB_VarDictionary_1_0>()->Get(var_, key.pp_var()));
+}
+
+PP_Bool VarDictionary::Set(const Var& key, const Var& value) {
+ if (!has_interface<PPB_VarDictionary_1_0>())
+ return PP_FALSE;
+
+ return get_interface<PPB_VarDictionary_1_0>()->Set(var_, key.pp_var(),
+ value.pp_var());
+}
+
+void VarDictionary::Delete(const Var& key) {
+ if (has_interface<PPB_VarDictionary_1_0>())
+ get_interface<PPB_VarDictionary_1_0>()->Delete(var_, key.pp_var());
+}
+
+PP_Bool VarDictionary::HasKey(const Var& key) const {
+ if (!has_interface<PPB_VarDictionary_1_0>())
+ return PP_FALSE;
+
+ return get_interface<PPB_VarDictionary_1_0>()->HasKey(var_, key.pp_var());
+}
+
+VarArray VarDictionary::GetKeys() const {
+ if (!has_interface<PPB_VarDictionary_1_0>())
+ return VarArray();
+
+ Var result(PASS_REF,
+ get_interface<PPB_VarDictionary_1_0>()->GetKeys(var_));
+ if (result.is_array())
+ return VarArray(result);
+ else
+ return VarArray();
+}
+
+} // namespace pp

Powered by Google App Engine
This is Rietveld 408576698