Pepper_31_C++_interfaces
to_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_TO_VAR_CONVERTOR_H_
6 #define PPAPI_CPP_EXTENSIONS_TO_VAR_CONVERTOR_H_
7 
8 #include <string>
9 
10 #include "ppapi/c/pp_var.h"
11 #include "ppapi/cpp/extensions/optional.h"
12 #include "ppapi/cpp/var.h"
13 #include "ppapi/cpp/var_array.h"
14 #include "ppapi/cpp/var_array_buffer.h"
15 #include "ppapi/cpp/var_dictionary.h"
16 
17 namespace pp {
18 namespace ext {
19 namespace internal {
20 
22  public:
23  PP_Var pp_var() const {
24  return var_.pp_var();
25  }
26 
27  const Var& var() const {
28  return var_;
29  }
30 
31  protected:
33  }
34 
35  explicit ToVarConverterBase(const PP_Var& var) : var_(var) {
36  }
37 
38  explicit ToVarConverterBase(const Var& var): var_(var) {
39  }
40 
42  }
43 
45 };
46 
47 template <class T>
49  public:
50  explicit ToVarConverter(const T& object)
51  : ToVarConverterBase(object.CreateVar()) {
52  }
53 
55  }
56 };
57 
58 template <class T>
60  public:
61  explicit ToVarConverter(const Optional<T>& object)
63  object.IsSet() ? ToVarConverter<T>(*object).pp_var() :
64  PP_MakeUndefined()) {
65  }
66 
68  }
69 };
70 
71 template <>
73  public:
74  explicit ToVarConverter(bool object) : ToVarConverterBase(Var(object)) {
75  }
76 
78  }
79 };
80 
81 template <>
83  public:
84  explicit ToVarConverter(int32_t object) : ToVarConverterBase(Var(object)) {
85  }
86 
88  }
89 };
90 
91 template <>
93  public:
94  explicit ToVarConverter(double object) : ToVarConverterBase(Var(object)) {
95  }
96 
98  }
99 };
100 
101 template <>
102 class ToVarConverter<std::string> : public ToVarConverterBase {
103  public:
104  explicit ToVarConverter(const std::string& object)
105  : ToVarConverterBase(Var(object)) {
106  }
107 
109  }
110 };
111 
112 template <>
114  public:
115  explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) {
116  }
117 
119  }
120 };
121 
122 template <>
124  public:
125  explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) {
126  }
127 
129  }
130 };
131 
132 template <>
134  public:
135  explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) {
136  }
137 
139  }
140 };
141 
142 template <>
144  public:
145  explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) {
146  }
147 
149  }
150 };
151 
152 } // namespace internal
153 } // namespace ext
154 } // namespace pp
155 
156 #endif // PPAPI_CPP_EXTENSIONS_TO_VAR_CONVERTOR_H_
const PP_Var & pp_var() const
Definition: var.h:213
A generic type used for passing data types between the module and the page.
Definition: var.h:20