Pepper_47_C++_interfaces
from_var_converter.h
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #ifndef PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_
6 #define PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_
7 
8 #include <string>
9 
10 #include "ppapi/c/pp_var.h"
12 #include "ppapi/cpp/logging.h"
13 #include "ppapi/cpp/var.h"
14 #include "ppapi/cpp/var_array.h"
17 
18 namespace pp {
19 namespace ext {
20 namespace internal {
21 
22 template <class T>
24  public:
25  T& value() { return value_; }
26 
27  protected:
29  }
30 
31  explicit FromVarConverterBase(const T& value) : value_(value) {
32  }
33 
35  }
36 
38 };
39 
40 template <class T>
42  public:
44  }
45 
46  explicit FromVarConverter(const PP_Var& var) {
47  Set(var);
48  }
49 
51  }
52 
53  void Set(const PP_Var& var) {
54  bool succeeded = FromVarConverterBase<T>::value_.Populate(var);
55  // Suppress unused variable warnings.
56  static_cast<void>(succeeded);
57  PP_DCHECK(succeeded);
58  }
59 };
60 
61 template <class T>
63  : public FromVarConverterBase<Optional<T> > {
64  public:
66  }
67 
68  explicit FromVarConverter(const PP_Var& var) {
69  Set(var);
70  }
71 
73  }
74 
75  void Set(const PP_Var& var) {
76  if (var.type == PP_VARTYPE_UNDEFINED) {
78  } else {
79  FromVarConverter<T> converter(var);
81  }
82  }
83 };
84 
85 template <>
87  public:
89  }
90 
91  explicit FromVarConverter(const PP_Var& var) {
92  Set(var);
93  }
94 
96  }
97 
98  void Set(const PP_Var& var) {
100  }
101 };
102 
103 template <>
105  public:
107  }
108 
109  explicit FromVarConverter(const PP_Var& var) {
110  Set(var);
111  }
112 
114  }
115 
116  void Set(const PP_Var& var) {
118  }
119 };
120 
121 template <>
123  public:
125  }
126 
127  explicit FromVarConverter(const PP_Var& var) {
128  Set(var);
129  }
130 
132  }
133 
134  void Set(const PP_Var& var) {
136  }
137 };
138 
139 template <>
140 class FromVarConverter<std::string> : public FromVarConverterBase<std::string> {
141  public:
143  }
144 
145  explicit FromVarConverter(const PP_Var& var) {
146  Set(var);
147  }
148 
150  }
151 
152  void Set(const PP_Var& var) {
154  }
155 };
156 
157 template <>
159  public:
161  }
162 
163  explicit FromVarConverter(const PP_Var& var) {
164  Set(var);
165  }
166 
168  }
169 
170  void Set(const PP_Var& var) {
172  }
173 };
174 
175 template <>
177  : public FromVarConverterBase<VarArray> {
178  public:
180  }
181 
182  explicit FromVarConverter(const PP_Var& var) {
183  Set(var);
184  }
185 
187  }
188 
189  void Set(const PP_Var& var) {
191  }
192 };
193 
194 template <>
196  : public FromVarConverterBase<VarDictionary> {
197  public:
199  }
200 
201  explicit FromVarConverter(const PP_Var& var) {
202  Set(var);
203  }
204 
206  }
207 
208  void Set(const PP_Var& var) {
210  }
211 };
212 
213 template <>
215  : public FromVarConverterBase<VarArrayBuffer> {
216  public:
218  }
219 
220  explicit FromVarConverter(const PP_Var& var) {
221  Set(var);
222  }
223 
225  }
226 
227  void Set(const PP_Var& var) {
229  }
230 };
231 
232 } // namespace internal
233 } // namespace ext
234 } // namespace pp
235 
236 #endif // PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_
std::string AsString() const
Definition: var.cc:250
#define PP_DCHECK(a)
Definition: logging.h:16
double AsDouble() const
Definition: var.cc:241
bool AsBool() const
Definition: var.cc:224
int32_t AsInt() const
Definition: var.cc:232
A generic type used for passing data types between the module and the page.
Definition: var.h:21