[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 5 | #ifndef PPAPI_CPP_VAR_DICTIONARY_H_ |
6 | #define PPAPI_CPP_VAR_DICTIONARY_H_ | ||||
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 7 | |
8 | #include "ppapi/c/pp_bool.h" | ||||
9 | #include "ppapi/cpp/var.h" | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 10 | #include "ppapi/cpp/var_array.h" |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 11 | |
12 | /// @file | ||||
13 | /// This file defines the API for interacting with dictionary vars. | ||||
14 | |||||
15 | namespace pp { | ||||
16 | |||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 17 | class VarDictionary : public Var { |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 18 | public: |
19 | /// Constructs a new dictionary var. | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 20 | VarDictionary(); |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 21 | |
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 22 | /// Constructs a <code>VarDictionary</code> given a var for which |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 23 | /// is_dictionary() is true. This will refer to the same dictionary var, but |
24 | /// allow you to access methods specific to dictionary. | ||||
25 | /// | ||||
26 | /// @param[in] var A dictionary var. | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 27 | explicit VarDictionary(const Var& var); |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 28 | |
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 29 | /// Constructs a <code>VarDictionary</code> given a <code>PP_Var</code> |
[email protected] | da55ed9 | 2013-03-20 17:42:29 | [diff] [blame] | 30 | /// of type PP_VARTYPE_DICTIONARY. |
31 | /// | ||||
32 | /// @param[in] var A <code>PP_Var</code> of type PP_VARTYPE_DICTIONARY. | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 33 | explicit VarDictionary(const PP_Var& var); |
[email protected] | da55ed9 | 2013-03-20 17:42:29 | [diff] [blame] | 34 | |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 35 | /// Copy constructor. |
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 36 | VarDictionary(const VarDictionary& other); |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 37 | |
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 38 | virtual ~VarDictionary(); |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 39 | |
40 | /// Assignment operator. | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 41 | VarDictionary& operator=(const VarDictionary& other); |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 42 | |
43 | /// The <code>Var</code> assignment operator is overridden here so that we can | ||||
44 | /// check for assigning a non-dictionary var to a | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 45 | /// <code>VarDictionary</code>. |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 46 | /// |
47 | /// @param[in] other The dictionary var to be assigned. | ||||
48 | /// | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 49 | /// @return The resulting <code>VarDictionary</code> (as a |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 50 | /// <code>Var</code>&). |
51 | virtual Var& operator=(const Var& other); | ||||
52 | |||||
53 | /// Gets the value associated with the specified key. | ||||
54 | /// | ||||
55 | /// @param[in] key A string var. | ||||
56 | /// | ||||
57 | /// @return The value that is associated with <code>key</code>. If | ||||
58 | /// <code>key</code> is not a string var, or it doesn't exist in the | ||||
59 | /// dictionary, an undefined var is returned. | ||||
60 | Var Get(const Var& key) const; | ||||
61 | |||||
62 | /// Sets the value associated with the specified key. | ||||
63 | /// | ||||
64 | /// @param[in] key A string var. If this key hasn't existed in the dictionary, | ||||
65 | /// it is added and associated with <code>value</code>; otherwise, the | ||||
66 | /// previous value is replaced with <code>value</code>. | ||||
67 | /// @param[in] value The value to set. | ||||
68 | /// | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 69 | /// @return A <code>bool</code> indicating whether the operation succeeds. |
70 | bool Set(const Var& key, const Var& value); | ||||
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 71 | |
72 | /// Deletes the specified key and its associated value, if the key exists. | ||||
73 | /// | ||||
74 | /// @param[in] key A string var. | ||||
75 | void Delete(const Var& key); | ||||
76 | |||||
77 | /// Checks whether a key exists. | ||||
78 | /// | ||||
79 | /// @param[in] key A string var. | ||||
80 | /// | ||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 81 | /// @return A <code>bool</code> indicating whether the key exists. |
82 | bool HasKey(const Var& key) const; | ||||
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 83 | |
84 | /// Gets all the keys in the dictionary. | ||||
85 | /// | ||||
86 | /// @return An array var which contains all the keys of the dictionary. | ||||
[email protected] | da55ed9 | 2013-03-20 17:42:29 | [diff] [blame] | 87 | /// The elements are string vars. Returns an empty array var if failed. |
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 88 | VarArray GetKeys() const; |
[email protected] | d9e5f412 | 2013-03-18 20:42:50 | [diff] [blame] | 89 | }; |
90 | |||||
91 | } // namespace pp | ||||
92 | |||||
[email protected] | 034fbf8 | 2013-06-20 09:08:15 | [diff] [blame] | 93 | #endif // PPAPI_CPP_VAR_DICTIONARY_H_ |