Pepper_47_C++_interfaces
var_dictionary.cc
Go to the documentation of this file.
1 // Copyright 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 
6 
7 #include "ppapi/c/ppb_var_dictionary.h"
8 #include "ppapi/cpp/logging.h"
10 
11 namespace pp {
12 
13 namespace {
14 
15 template <> const char* interface_name<PPB_VarDictionary_1_0>() {
16  return PPB_VAR_DICTIONARY_INTERFACE_1_0;
17 }
18 
19 } // namespace
20 
22  if (has_interface<PPB_VarDictionary_1_0>())
23  var_ = get_interface<PPB_VarDictionary_1_0>()->Create();
24  else
25  PP_NOTREACHED();
26 }
27 
28 VarDictionary::VarDictionary(const Var& var) : Var(var) {
29  if (!var.is_dictionary()) {
30  PP_NOTREACHED();
31 
32  // This takes care of releasing the reference that this object holds.
34  }
35 }
36 
38  if (var.type != PP_VARTYPE_DICTIONARY) {
39  PP_NOTREACHED();
40 
41  // This takes care of releasing the reference that this object holds.
43  }
44 }
45 
47  : Var(other) {
48 }
49 
51 }
52 
54  const VarDictionary& other) {
55  Var::operator=(other);
56  return *this;
57 }
58 
60  if (other.is_dictionary()) {
61  Var::operator=(other);
62  } else {
63  PP_NOTREACHED();
65  }
66  return *this;
67 }
68 
69 Var VarDictionary::Get(const Var& key) const {
70  if (!has_interface<PPB_VarDictionary_1_0>())
71  return Var();
72 
73  return Var(
74  PASS_REF,
75  get_interface<PPB_VarDictionary_1_0>()->Get(var_, key.pp_var()));
76 }
77 
78 bool VarDictionary::Set(const Var& key, const Var& value) {
79  if (!has_interface<PPB_VarDictionary_1_0>())
80  return false;
81 
82  return PP_ToBool(get_interface<PPB_VarDictionary_1_0>()->Set(
83  var_, key.pp_var(), value.pp_var()));
84 }
85 
86 void VarDictionary::Delete(const Var& key) {
87  if (has_interface<PPB_VarDictionary_1_0>())
88  get_interface<PPB_VarDictionary_1_0>()->Delete(var_, key.pp_var());
89 }
90 
91 bool VarDictionary::HasKey(const Var& key) const {
92  if (!has_interface<PPB_VarDictionary_1_0>())
93  return false;
94 
95  return PP_ToBool(get_interface<PPB_VarDictionary_1_0>()->HasKey(
96  var_, key.pp_var()));
97 }
98 
100  if (!has_interface<PPB_VarDictionary_1_0>())
101  return VarArray();
102 
103  Var result(PASS_REF,
104  get_interface<PPB_VarDictionary_1_0>()->GetKeys(var_));
105  if (result.is_array())
106  return VarArray(result);
107  else
108  return VarArray();
109 }
110 
111 } // namespace pp
virtual Var & operator=(const Var &other)
Definition: var.cc:176
bool HasKey(const Var &key) const
bool is_dictionary() const
Definition: var.h:138
#define PP_NOTREACHED()
Definition: logging.h:32
Special value passed to constructor to make NULL.
Definition: var.h:24
VarDictionary()
Constructs a new dictionary var.
void Delete(const Var &key)
bool Set(const Var &key, const Var &value)
bool is_array() const
Definition: var.h:133
Var Get(const Var &key) const
const PP_Var & pp_var() const
Definition: var.h:226
Var()
Definition: var.cc:94
virtual ~VarDictionary()
A generic type used for passing data types between the module and the page.
Definition: var.h:21
VarArray GetKeys() const
VarDictionary & operator=(const VarDictionary &other)
Assignment operator.
PP_Var var_
Definition: var.h:308