summaryrefslogtreecommitdiffstats
path: root/o3d/gpu/np_utils/np_dispatcher_specializations.h
blob: 62fb8c49c37eea0685f185e90304e7228049f110 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// There is deliberately no header guard here. This file is included multiple
// times, once for each dispatcher specialiation arity. Do not include this
// file directly. Include np_dispatcher.h instead.

template <typename NPObjectType PARAM_TYPENAMES>
class NPDispatcher<NPObjectType, void(PARAM_TYPES)>
    : public BaseNPDispatcher {
  typedef void (NPObjectType::*FunctionType)(PARAM_TYPES);
 public:
  NPDispatcher(BaseNPDispatcher* next,
               const NPUTF8* name,
               FunctionType function)
      : BaseNPDispatcher(next, name),
        function_(function) {
  }

  virtual bool Invoke(NPObject* object,
                      const NPVariant* args,
                      uint32_t num_args,
                      NPVariant* result) {
    VOID_TO_NPVARIANT(*result);

    if (num_args != NUM_PARAMS)
      return false;

    PARAM_TO_NVPARIANT_CONVERSIONS

    (static_cast<NPObjectType*>(object)->*function_)(PARAM_NAMES);
    return true;
  }

  virtual int num_args() const {
    return NUM_PARAMS;
  }

 private:
  FunctionType function_;
};

template <typename NPObjectType, typename R PARAM_TYPENAMES>
class NPDispatcher<NPObjectType, R(PARAM_TYPES)>
    : public BaseNPDispatcher {
  typedef R (NPObjectType::*FunctionType)(PARAM_TYPES);
 public:
  NPDispatcher(BaseNPDispatcher* next,
               const NPUTF8* name,
               FunctionType function)
      : BaseNPDispatcher(next, name),
        function_(function) {
  }

  virtual bool Invoke(NPObject* object,
                      const NPVariant* args,
                      uint32_t num_args,
                      NPVariant* result) {
    VOID_TO_NPVARIANT(*result);

    if (num_args != NUM_PARAMS)
      return false;

    PARAM_TO_NVPARIANT_CONVERSIONS

    ValueToNPVariant(
        (static_cast<NPObjectType*>(object)->*function_)(PARAM_NAMES), result);
    return true;
  }

  virtual int num_args() const {
    return NUM_PARAMS;
  }

 private:
  FunctionType function_;
};

#undef NUM_PARAMS
#undef PARAM_TYPENAMES
#undef PARAM_TYPES
#undef PARAM_NAMES
#undef PARAM_DECLS
#undef PARAM_TO_NVPARIANT_CONVERSIONS