Pepper_47_C++_interfaces
var_array.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 
5 #include "ppapi/cpp/var_array.h"
6 
7 #include "ppapi/c/ppb_var_array.h"
8 #include "ppapi/cpp/logging.h"
10 
11 namespace pp {
12 
13 namespace {
14 
15 template <> const char* interface_name<PPB_VarArray_1_0>() {
16  return PPB_VAR_ARRAY_INTERFACE_1_0;
17 }
18 
19 } // namespace
20 
22  if (has_interface<PPB_VarArray_1_0>())
23  var_ = get_interface<PPB_VarArray_1_0>()->Create();
24  else
25  PP_NOTREACHED();
26 }
27 
28 VarArray::VarArray(const Var& var) : Var(var) {
29  if (!var.is_array()) {
30  PP_NOTREACHED();
31 
32  // This takes care of releasing the reference that this object holds.
34  }
35 }
36 
37 VarArray::VarArray(const PP_Var& var) : Var(var) {
38  if (var.type != PP_VARTYPE_ARRAY) {
39  PP_NOTREACHED();
40 
41  // This takes care of releasing the reference that this object holds.
43  }
44 }
45 
46 VarArray::VarArray(const VarArray& other) : Var(other) {
47 }
48 
50 }
51 
53  Var::operator=(other);
54  return *this;
55 }
56 
57 Var& VarArray::operator=(const Var& other) {
58  if (other.is_array()) {
59  Var::operator=(other);
60  } else {
61  PP_NOTREACHED();
63  }
64  return *this;
65 }
66 
67 Var VarArray::Get(uint32_t index) const {
68  if (!has_interface<PPB_VarArray_1_0>())
69  return Var();
70 
71  return Var(PASS_REF, get_interface<PPB_VarArray_1_0>()->Get(var_, index));
72 }
73 
74 bool VarArray::Set(uint32_t index, const Var& value) {
75  if (!has_interface<PPB_VarArray_1_0>())
76  return false;
77 
78  return PP_ToBool(get_interface<PPB_VarArray_1_0>()->Set(var_, index,
79  value.pp_var()));
80 }
81 
82 uint32_t VarArray::GetLength() const {
83  if (!has_interface<PPB_VarArray_1_0>())
84  return 0;
85 
86  return get_interface<PPB_VarArray_1_0>()->GetLength(var_);
87 }
88 
89 bool VarArray::SetLength(uint32_t length) {
90  if (!has_interface<PPB_VarArray_1_0>())
91  return false;
92 
93  return PP_ToBool(get_interface<PPB_VarArray_1_0>()->SetLength(var_, length));
94 }
95 
96 } // namespace pp
virtual Var & operator=(const Var &other)
Definition: var.cc:176
VarArray & operator=(const VarArray &other)
Assignment operator.
Definition: var_array.cc:52
uint32_t GetLength() const
Definition: var_array.cc:82
bool Set(uint32_t index, const Var &value)
Definition: var_array.cc:74
VarArray()
Constructs a new array var.
Definition: var_array.cc:21
bool SetLength(uint32_t length)
Definition: var_array.cc:89
#define PP_NOTREACHED()
Definition: logging.h:32
Special value passed to constructor to make NULL.
Definition: var.h:24
bool is_array() const
Definition: var.h:133
const PP_Var & pp_var() const
Definition: var.h:226
Var()
Definition: var.cc:94
virtual ~VarArray()
Definition: var_array.cc:49
A generic type used for passing data types between the module and the page.
Definition: var.h:21
Var Get(uint32_t index) const
Definition: var_array.cc:67
PP_Var var_
Definition: var.h:308