Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ppapi / cpp / dev / var_dictionary_dev.cc
blob8fa3f6c10df9a29e66b2b912b4e7d457b738efc6
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.
5 #include "ppapi/cpp/dev/var_dictionary_dev.h"
7 #include "ppapi/c/dev/ppb_var_dictionary_dev.h"
8 #include "ppapi/cpp/logging.h"
9 #include "ppapi/cpp/module_impl.h"
11 namespace pp {
13 namespace {
15 template <> const char* interface_name<PPB_VarDictionary_Dev_0_1>() {
16 return PPB_VAR_DICTIONARY_DEV_INTERFACE_0_1;
19 } // namespace
21 VarDictionary_Dev::VarDictionary_Dev() : Var(Null()) {
22 if (has_interface<PPB_VarDictionary_Dev_0_1>())
23 var_ = get_interface<PPB_VarDictionary_Dev_0_1>()->Create();
24 else
25 PP_NOTREACHED();
28 VarDictionary_Dev::VarDictionary_Dev(const Var& var) : Var(var) {
29 if (!var.is_dictionary()) {
30 PP_NOTREACHED();
32 // This takes care of releasing the reference that this object holds.
33 Var::operator=(Var(Null()));
37 VarDictionary_Dev::VarDictionary_Dev(const PP_Var& var) : Var(var) {
38 if (var.type != PP_VARTYPE_DICTIONARY) {
39 PP_NOTREACHED();
41 // This takes care of releasing the reference that this object holds.
42 Var::operator=(Var(Null()));
46 VarDictionary_Dev::VarDictionary_Dev(const VarDictionary_Dev& other)
47 : Var(other) {
50 VarDictionary_Dev::~VarDictionary_Dev() {
53 VarDictionary_Dev& VarDictionary_Dev::operator=(
54 const VarDictionary_Dev& other) {
55 Var::operator=(other);
56 return *this;
59 Var& VarDictionary_Dev::operator=(const Var& other) {
60 if (other.is_dictionary()) {
61 Var::operator=(other);
62 } else {
63 PP_NOTREACHED();
64 Var::operator=(Var(Null()));
66 return *this;
69 Var VarDictionary_Dev::Get(const Var& key) const {
70 if (!has_interface<PPB_VarDictionary_Dev_0_1>())
71 return Var();
73 return Var(
74 PASS_REF,
75 get_interface<PPB_VarDictionary_Dev_0_1>()->Get(var_, key.pp_var()));
78 PP_Bool VarDictionary_Dev::Set(const Var& key, const Var& value) {
79 if (!has_interface<PPB_VarDictionary_Dev_0_1>())
80 return PP_FALSE;
82 return get_interface<PPB_VarDictionary_Dev_0_1>()->Set(var_, key.pp_var(),
83 value.pp_var());
86 void VarDictionary_Dev::Delete(const Var& key) {
87 if (has_interface<PPB_VarDictionary_Dev_0_1>())
88 get_interface<PPB_VarDictionary_Dev_0_1>()->Delete(var_, key.pp_var());
91 PP_Bool VarDictionary_Dev::HasKey(const Var& key) const {
92 if (!has_interface<PPB_VarDictionary_Dev_0_1>())
93 return PP_FALSE;
95 return get_interface<PPB_VarDictionary_Dev_0_1>()->HasKey(var_, key.pp_var());
98 VarArray_Dev VarDictionary_Dev::GetKeys() const {
99 if (!has_interface<PPB_VarDictionary_Dev_0_1>())
100 return VarArray_Dev();
102 Var result(PASS_REF,
103 get_interface<PPB_VarDictionary_Dev_0_1>()->GetKeys(var_));
104 if (result.is_array())
105 return VarArray_Dev(result);
106 else
107 return VarArray_Dev();
110 } // namespace pp