Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(710)

Side by Side Diff: ppapi/cpp/extensions/dict_field.h

Issue 17005006: Move PPB_VarArray and PPB_VarDictionary out of dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/extensions/dev/socket_dev.cc ('k') | ppapi/cpp/extensions/ext_output_traits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_ 5 #ifndef PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_
6 #define PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_ 6 #define PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "ppapi/c/pp_bool.h" 10 #include "ppapi/c/pp_bool.h"
11 #include "ppapi/cpp/dev/var_dictionary_dev.h"
12 #include "ppapi/cpp/extensions/from_var_converter.h" 11 #include "ppapi/cpp/extensions/from_var_converter.h"
13 #include "ppapi/cpp/extensions/optional.h" 12 #include "ppapi/cpp/extensions/optional.h"
14 #include "ppapi/cpp/extensions/to_var_converter.h" 13 #include "ppapi/cpp/extensions/to_var_converter.h"
15 #include "ppapi/cpp/var.h" 14 #include "ppapi/cpp/var.h"
15 #include "ppapi/cpp/var_dictionary.h"
16 16
17 namespace pp { 17 namespace pp {
18 namespace ext { 18 namespace ext {
19 19
20 template <class T> 20 template <class T>
21 class DictField { 21 class DictField {
22 public: 22 public:
23 explicit DictField(const std::string& key) : key_(key), value_() { 23 explicit DictField(const std::string& key) : key_(key), value_() {
24 } 24 }
25 25
26 ~DictField() { 26 ~DictField() {
27 } 27 }
28 28
29 const std::string& key() const { return key_; } 29 const std::string& key() const { return key_; }
30 30
31 // Returns the value. 31 // Returns the value.
32 T& operator()() { return value_; } 32 T& operator()() { return value_; }
33 const T& operator()() const { return value_; } 33 const T& operator()() const { return value_; }
34 34
35 // Adds this field to the dictionary var. 35 // Adds this field to the dictionary var.
36 bool AddTo(VarDictionary_Dev* dict) const { 36 bool AddTo(VarDictionary* dict) const {
37 if (!dict) 37 if (!dict)
38 return false; 38 return false;
39 39
40 internal::ToVarConverter<T> converter(value_); 40 internal::ToVarConverter<T> converter(value_);
41 return PP_ToBool(dict->Set(Var(key_), converter.var())); 41 return dict->Set(Var(key_), converter.var());
42 } 42 }
43 43
44 bool Populate(const VarDictionary_Dev& dict) { 44 bool Populate(const VarDictionary& dict) {
45 Var value_var = dict.Get(Var(key_)); 45 Var value_var = dict.Get(Var(key_));
46 if (value_var.is_undefined()) 46 if (value_var.is_undefined())
47 return false; 47 return false;
48 48
49 internal::FromVarConverter<T> converter(value_var.pp_var()); 49 internal::FromVarConverter<T> converter(value_var.pp_var());
50 value_ = converter.value(); 50 value_ = converter.value();
51 return true; 51 return true;
52 } 52 }
53 53
54 private: 54 private:
(...skipping 10 matching lines...) Expand all
65 ~OptionalDictField() { 65 ~OptionalDictField() {
66 } 66 }
67 67
68 const std::string& key() const { return key_; } 68 const std::string& key() const { return key_; }
69 69
70 // Returns the value. 70 // Returns the value.
71 Optional<T>& operator()() { return value_; } 71 Optional<T>& operator()() { return value_; }
72 const Optional<T>& operator()() const { return value_; } 72 const Optional<T>& operator()() const { return value_; }
73 73
74 // Adds this field to the dictionary var, if |value| has been set. 74 // Adds this field to the dictionary var, if |value| has been set.
75 bool MayAddTo(VarDictionary_Dev* dict) const { 75 bool MayAddTo(VarDictionary* dict) const {
76 if (!dict) 76 if (!dict)
77 return false; 77 return false;
78 if (!value_.IsSet()) 78 if (!value_.IsSet())
79 return true; 79 return true;
80 80
81 internal::ToVarConverter<T> converter(*value_); 81 internal::ToVarConverter<T> converter(*value_);
82 return PP_ToBool(dict->Set(Var(key_), converter.var())); 82 return dict->Set(Var(key_), converter.var());
83 } 83 }
84 84
85 bool Populate(const VarDictionary_Dev& dict) { 85 bool Populate(const VarDictionary& dict) {
86 Var value_var = dict.Get(Var(key_)); 86 Var value_var = dict.Get(Var(key_));
87 internal::FromVarConverter<Optional<T> > converter(value_var.pp_var()); 87 internal::FromVarConverter<Optional<T> > converter(value_var.pp_var());
88 value_.Swap(&converter.value()); 88 value_.Swap(&converter.value());
89 return true; 89 return true;
90 } 90 }
91 91
92 private: 92 private:
93 std::string key_; 93 std::string key_;
94 Optional<T> value_; 94 Optional<T> value_;
95 }; 95 };
96 96
97 } // namespace ext 97 } // namespace ext
98 } // namespace pp 98 } // namespace pp
99 99
100 #endif // PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_ 100 #endif // PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/extensions/dev/socket_dev.cc ('k') | ppapi/cpp/extensions/ext_output_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698