cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / cpp / extensions / from_var_converter.h
blob06ae0df2501ff968196dd652db11e92a1ae6bc6b
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.
5 #ifndef PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_
6 #define PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_
8 #include <string>
10 #include "ppapi/c/pp_var.h"
11 #include "ppapi/cpp/extensions/optional.h"
12 #include "ppapi/cpp/logging.h"
13 #include "ppapi/cpp/var.h"
14 #include "ppapi/cpp/var_array.h"
15 #include "ppapi/cpp/var_array_buffer.h"
16 #include "ppapi/cpp/var_dictionary.h"
18 namespace pp {
19 namespace ext {
20 namespace internal {
22 template <class T>
23 class FromVarConverterBase {
24 public:
25 T& value() { return value_; }
27 protected:
28 FromVarConverterBase() : value_() {
31 explicit FromVarConverterBase(const T& value) : value_(value) {
34 ~FromVarConverterBase() {
37 T value_;
40 template <class T>
41 class FromVarConverter : public FromVarConverterBase<T> {
42 public:
43 FromVarConverter() {
46 explicit FromVarConverter(const PP_Var& var) {
47 Set(var);
50 ~FromVarConverter() {
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);
61 template <class T>
62 class FromVarConverter<Optional<T> >
63 : public FromVarConverterBase<Optional<T> > {
64 public:
65 FromVarConverter() {
68 explicit FromVarConverter(const PP_Var& var) {
69 Set(var);
72 ~FromVarConverter() {
75 void Set(const PP_Var& var) {
76 if (var.type == PP_VARTYPE_UNDEFINED) {
77 FromVarConverterBase<Optional<T> >::value_.Reset();
78 } else {
79 FromVarConverter<T> converter(var);
80 FromVarConverterBase<Optional<T> >::value_ = converter.value();
85 template <>
86 class FromVarConverter<bool> : public FromVarConverterBase<bool> {
87 public:
88 FromVarConverter() {
91 explicit FromVarConverter(const PP_Var& var) {
92 Set(var);
95 ~FromVarConverter() {
98 void Set(const PP_Var& var) {
99 FromVarConverterBase<bool>::value_ = Var(var).AsBool();
103 template <>
104 class FromVarConverter<int32_t> : public FromVarConverterBase<int32_t> {
105 public:
106 FromVarConverter() {
109 explicit FromVarConverter(const PP_Var& var) {
110 Set(var);
113 ~FromVarConverter() {
116 void Set(const PP_Var& var) {
117 FromVarConverterBase<int32_t>::value_ = Var(var).AsInt();
121 template <>
122 class FromVarConverter<double> : public FromVarConverterBase<double> {
123 public:
124 FromVarConverter() {
127 explicit FromVarConverter(const PP_Var& var) {
128 Set(var);
131 ~FromVarConverter() {
134 void Set(const PP_Var& var) {
135 FromVarConverterBase<double>::value_ = Var(var).AsDouble();
139 template <>
140 class FromVarConverter<std::string> : public FromVarConverterBase<std::string> {
141 public:
142 FromVarConverter() {
145 explicit FromVarConverter(const PP_Var& var) {
146 Set(var);
149 ~FromVarConverter() {
152 void Set(const PP_Var& var) {
153 FromVarConverterBase<std::string>::value_ = Var(var).AsString();
157 template <>
158 class FromVarConverter<Var> : public FromVarConverterBase<Var> {
159 public:
160 FromVarConverter() {
163 explicit FromVarConverter(const PP_Var& var) {
164 Set(var);
167 ~FromVarConverter() {
170 void Set(const PP_Var& var) {
171 FromVarConverterBase<Var>::value_ = Var(var);
175 template <>
176 class FromVarConverter<VarArray>
177 : public FromVarConverterBase<VarArray> {
178 public:
179 FromVarConverter() {
182 explicit FromVarConverter(const PP_Var& var) {
183 Set(var);
186 ~FromVarConverter() {
189 void Set(const PP_Var& var) {
190 FromVarConverterBase<VarArray>::value_ = Var(var);
194 template <>
195 class FromVarConverter<VarDictionary>
196 : public FromVarConverterBase<VarDictionary> {
197 public:
198 FromVarConverter() {
201 explicit FromVarConverter(const PP_Var& var) {
202 Set(var);
205 ~FromVarConverter() {
208 void Set(const PP_Var& var) {
209 FromVarConverterBase<VarDictionary>::value_ = Var(var);
213 template <>
214 class FromVarConverter<VarArrayBuffer>
215 : public FromVarConverterBase<VarArrayBuffer> {
216 public:
217 FromVarConverter() {
220 explicit FromVarConverter(const PP_Var& var) {
221 Set(var);
224 ~FromVarConverter() {
227 void Set(const PP_Var& var) {
228 FromVarConverterBase<VarArrayBuffer>::value_ = Var(var);
232 } // namespace internal
233 } // namespace ext
234 } // namespace pp
236 #endif // PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_