[NaClDocs] Fill in the landing page for the SDK section of the docs.
[chromium-blink-merge.git] / ppapi / cpp / var_array.h
blob49373ff260b37d319480eff62f994095cd29eebf
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 #ifndef PPAPI_CPP_VAR_ARRAY_H_
6 #define PPAPI_CPP_VAR_ARRAY_H_
8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_stdint.h"
10 #include "ppapi/cpp/var.h"
12 /// @file
13 /// This file defines the API for interacting with array vars.
15 namespace pp {
17 class VarArray : public Var {
18 public:
19 /// Constructs a new array var.
20 VarArray();
22 /// Constructs a <code>VarArray</code> given a var for which is_array() is
23 /// true. This will refer to the same array var, but allow you to access
24 /// methods specific to arrays.
25 ///
26 /// @param[in] var An array var.
27 explicit VarArray(const Var& var);
29 /// Constructs a <code>VarArray</code> given a <code>PP_Var</code> of type
30 /// PP_VARTYPE_ARRAY.
31 ///
32 /// @param[in] var A <code>PP_Var</code> of type PP_VARTYPE_ARRAY.
33 explicit VarArray(const PP_Var& var);
35 /// Copy constructor.
36 VarArray(const VarArray& other);
38 virtual ~VarArray();
40 /// Assignment operator.
41 VarArray& operator=(const VarArray& other);
43 /// The <code>Var</code> assignment operator is overridden here so that we can
44 /// check for assigning a non-array var to a <code>VarArray</code>.
45 ///
46 /// @param[in] other The array var to be assigned.
47 ///
48 /// @return The resulting <code>VarArray</code> (as a <code>Var</code>&).
49 virtual Var& operator=(const Var& other);
51 /// Gets an element from the array.
52 ///
53 /// @param[in] index An index indicating which element to return.
54 ///
55 /// @return The element at the specified position. If <code>index</code> is
56 /// larger than or equal to the array length, an undefined var is returned.
57 Var Get(uint32_t index) const;
59 /// Sets the value of an element in the array.
60 ///
61 /// @param[in] index An index indicating which element to modify. If
62 /// <code>index</code> is larger than or equal to the array length, the length
63 /// is updated to be <code>index</code> + 1. Any position in the array that
64 /// hasn't been set before is set to undefined, i.e., <code>PP_Var</code> of
65 /// type <code>PP_VARTYPE_UNDEFINED</code>.
66 /// @param[in] value The value to set.
67 ///
68 /// @return A <code>bool</code> indicating whether the operation succeeds.
69 bool Set(uint32_t index, const Var& value);
71 /// Gets the array length.
72 ///
73 /// @return The array length.
74 uint32_t GetLength() const;
76 /// Sets the array length.
77 ///
78 /// @param[in] length The new array length. If <code>length</code> is smaller
79 /// than its current value, the array is truncated to the new length; any
80 /// elements that no longer fit are removed. If <code>length</code> is larger
81 /// than its current value, undefined vars are appended to increase the array
82 /// to the specified length.
83 ///
84 /// @return A <code>bool</code> indicating whether the operation succeeds.
85 bool SetLength(uint32_t length);
88 } // namespace pp
90 #endif // PPAPI_CPP_VAR_ARRAY_H_