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_TO_VAR_CONVERTOR_H_
6 #define PPAPI_CPP_EXTENSIONS_TO_VAR_CONVERTOR_H_
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"
21 class ToVarConverterBase
{
23 PP_Var
pp_var() const {
27 const Var
& var() const {
32 ToVarConverterBase() {
35 explicit ToVarConverterBase(const PP_Var
& var
) : var_(var
) {
38 explicit ToVarConverterBase(const Var
& var
): var_(var
) {
41 ~ToVarConverterBase() {
48 class ToVarConverter
: public ToVarConverterBase
{
50 explicit ToVarConverter(const T
& object
)
51 : ToVarConverterBase(object
.CreateVar()) {
59 class ToVarConverter
<Optional
<T
> > : public ToVarConverterBase
{
61 explicit ToVarConverter(const Optional
<T
>& object
)
63 object
.IsSet() ? ToVarConverter
<T
>(*object
).pp_var() :
72 class ToVarConverter
<bool> : public ToVarConverterBase
{
74 explicit ToVarConverter(bool object
) : ToVarConverterBase(Var(object
)) {
82 class ToVarConverter
<int32_t> : public ToVarConverterBase
{
84 explicit ToVarConverter(int32_t object
) : ToVarConverterBase(Var(object
)) {
92 class ToVarConverter
<double> : public ToVarConverterBase
{
94 explicit ToVarConverter(double object
) : ToVarConverterBase(Var(object
)) {
102 class ToVarConverter
<std::string
> : public ToVarConverterBase
{
104 explicit ToVarConverter(const std::string
& object
)
105 : ToVarConverterBase(Var(object
)) {
113 class ToVarConverter
<Var
> : public ToVarConverterBase
{
115 explicit ToVarConverter(const Var
& object
) : ToVarConverterBase(object
) {
123 class ToVarConverter
<VarArray
> : public ToVarConverterBase
{
125 explicit ToVarConverter(const Var
& object
) : ToVarConverterBase(object
) {
133 class ToVarConverter
<VarDictionary
> : public ToVarConverterBase
{
135 explicit ToVarConverter(const Var
& object
) : ToVarConverterBase(object
) {
143 class ToVarConverter
<VarArrayBuffer
> : public ToVarConverterBase
{
145 explicit ToVarConverter(const Var
& object
) : ToVarConverterBase(object
) {
152 } // namespace internal
156 #endif // PPAPI_CPP_EXTENSIONS_TO_VAR_CONVERTOR_H_