summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/dev/var_dictionary_dev.cc
blob: 8fa3f6c10df9a29e66b2b912b4e7d457b738efc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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/dev/var_dictionary_dev.h"

#include "ppapi/c/dev/ppb_var_dictionary_dev.h"
#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/module_impl.h"

namespace pp {

namespace {

template <> const char* interface_name<PPB_VarDictionary_Dev_0_1>() {
  return PPB_VAR_DICTIONARY_DEV_INTERFACE_0_1;
}

}  // namespace

VarDictionary_Dev::VarDictionary_Dev() : Var(Null()) {
  if (has_interface<PPB_VarDictionary_Dev_0_1>())
    var_ = get_interface<PPB_VarDictionary_Dev_0_1>()->Create();
  else
    PP_NOTREACHED();
}

VarDictionary_Dev::VarDictionary_Dev(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_Dev::VarDictionary_Dev(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_Dev::VarDictionary_Dev(const VarDictionary_Dev& other)
    : Var(other) {
}

VarDictionary_Dev::~VarDictionary_Dev() {
}

VarDictionary_Dev& VarDictionary_Dev::operator=(
    const VarDictionary_Dev& other) {
  Var::operator=(other);
  return *this;
}

Var& VarDictionary_Dev::operator=(const Var& other) {
  if (other.is_dictionary()) {
    Var::operator=(other);
  } else {
    PP_NOTREACHED();
    Var::operator=(Var(Null()));
  }
  return *this;
}

Var VarDictionary_Dev::Get(const Var& key) const {
  if (!has_interface<PPB_VarDictionary_Dev_0_1>())
    return Var();

  return Var(
      PASS_REF,
      get_interface<PPB_VarDictionary_Dev_0_1>()->Get(var_, key.pp_var()));
}

PP_Bool VarDictionary_Dev::Set(const Var& key, const Var& value) {
  if (!has_interface<PPB_VarDictionary_Dev_0_1>())
    return PP_FALSE;

  return get_interface<PPB_VarDictionary_Dev_0_1>()->Set(var_, key.pp_var(),
                                                         value.pp_var());
}

void VarDictionary_Dev::Delete(const Var& key) {
  if (has_interface<PPB_VarDictionary_Dev_0_1>())
    get_interface<PPB_VarDictionary_Dev_0_1>()->Delete(var_, key.pp_var());
}

PP_Bool VarDictionary_Dev::HasKey(const Var& key) const {
  if (!has_interface<PPB_VarDictionary_Dev_0_1>())
    return PP_FALSE;

  return get_interface<PPB_VarDictionary_Dev_0_1>()->HasKey(var_, key.pp_var());
}

VarArray_Dev VarDictionary_Dev::GetKeys() const {
  if (!has_interface<PPB_VarDictionary_Dev_0_1>())
    return VarArray_Dev();

  Var result(PASS_REF,
             get_interface<PPB_VarDictionary_Dev_0_1>()->GetKeys(var_));
  if (result.is_array())
    return VarArray_Dev(result);
  else
    return VarArray_Dev();
}

}  // namespace pp