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.
5 #include "ppapi/cpp/var_array.h"
7 #include "ppapi/c/ppb_var_array.h"
8 #include "ppapi/cpp/logging.h"
9 #include "ppapi/cpp/module_impl.h"
15 template <> const char* interface_name
<PPB_VarArray_1_0
>() {
16 return PPB_VAR_ARRAY_INTERFACE_1_0
;
21 VarArray::VarArray() : Var(Null()) {
22 if (has_interface
<PPB_VarArray_1_0
>())
23 var_
= get_interface
<PPB_VarArray_1_0
>()->Create();
28 VarArray::VarArray(const Var
& var
) : Var(var
) {
29 if (!var
.is_array()) {
32 // This takes care of releasing the reference that this object holds.
33 Var::operator=(Var(Null()));
37 VarArray::VarArray(const PP_Var
& var
) : Var(var
) {
38 if (var
.type
!= PP_VARTYPE_ARRAY
) {
41 // This takes care of releasing the reference that this object holds.
42 Var::operator=(Var(Null()));
46 VarArray::VarArray(const VarArray
& other
) : Var(other
) {
49 VarArray::~VarArray() {
52 VarArray
& VarArray::operator=(const VarArray
& other
) {
53 Var::operator=(other
);
57 Var
& VarArray::operator=(const Var
& other
) {
58 if (other
.is_array()) {
59 Var::operator=(other
);
62 Var::operator=(Var(Null()));
67 Var
VarArray::Get(uint32_t index
) const {
68 if (!has_interface
<PPB_VarArray_1_0
>())
71 return Var(PASS_REF
, get_interface
<PPB_VarArray_1_0
>()->Get(var_
, index
));
74 bool VarArray::Set(uint32_t index
, const Var
& value
) {
75 if (!has_interface
<PPB_VarArray_1_0
>())
78 return PP_ToBool(get_interface
<PPB_VarArray_1_0
>()->Set(var_
, index
,
82 uint32_t VarArray::GetLength() const {
83 if (!has_interface
<PPB_VarArray_1_0
>())
86 return get_interface
<PPB_VarArray_1_0
>()->GetLength(var_
);
89 bool VarArray::SetLength(uint32_t length
) {
90 if (!has_interface
<PPB_VarArray_1_0
>())
93 return PP_ToBool(get_interface
<PPB_VarArray_1_0
>()->SetLength(var_
, length
));