summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eo_cxx/eo_private.hh
blob: abd67e522341c7d2dee1f62442bc3c29d599046f (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Copyright 2019 by its authors. See AUTHORS.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///
/// @file eo_private.hh
///

#ifndef EFL_CXX_EO_PRIVATE_HH
#define EFL_CXX_EO_PRIVATE_HH

#include "eo_ops.hh"

namespace eo { 
struct Base;
}

namespace efl { namespace eo { namespace detail {

/// @addtogroup Efl_Cxx_Detail
/// @{

/// @internal
///
/// @brief Provides a getter for an heterogeous sequence of arguments.
///
/// @param T An <em>EO C++ Class</em>
/// @param Seq An heterogenous sequence of arguments.
///
template <typename T, typename Tuple>
struct args_class
{
   typedef T class_type;

   /// @internal
   ///
   /// @brief Class constructor.
   ///
   /// @param tuple An heterogenous sequence of arguments.
   ///
   args_class(Tuple tuple) : _tuple(tuple) {}

   /// @internal
   ///
   /// @brief Get the Nth element of the sequence.
   ///
   /// @param N The index of the argument to be retrieved.
   ///
   template <int N>
   typename std::remove_reference
   <
     typename std::tuple_element<N, Tuple>::type
   >::type get() const
   {
      return std::get<N>(_tuple);
   }

   ///
   /// TODO document.
   ///
   constexpr std::size_t size() const
   {
      return std::tuple_size<Tuple>::value;
   }

   Tuple _tuple; ///< The sequence of arguments.
};

/// @internal
///
/// @brief A simple generic tag to help keeping track of a type.
///
/// @details
/// Used to mimic what would be a "template specialization" of a
/// function through the overload of an argument of type @ref
/// efl::eo::detail::tag --- because @c C++0x does not implement
/// template specialization of functions.
///
template <typename T> struct tag {};

/// @internal
///
/// @brief Invokes the different implementations of @ref
/// efl::eo::detail::eo_class_new for the parent and all extensions.
///
/// @see efl::eo::detail::eo_class_new
///
template <typename ... E>
Eo_Class const* do_eo_class_new(Eo_Class_Description& class_desc)
{
   return eo_class_new(&class_desc, get_eo_class(tag<E>())..., (void*)NULL);
}

template <typename T> struct operation_description_class_size;
template <> struct operation_description_class_size< ::eo::Base> : std::integral_constant<std::size_t, 0u> {};

/// @internal
///
/// @brief Provides the operator to convert @p T to @p D.
///
/// @param D The target (derived) class
/// @param T An <em>EO C++ Class</em>
///
template <typename D, typename T>
struct conversion_operator
{
   operator T() const
   {
      detail::ref(static_cast<D const*>(this)->_eo_ptr());
      return T(static_cast<D const*>(this)->_eo_ptr());
   }
};

/// @}

} // namespace detail {

template <typename T, typename... A>
detail::args_class<T, std::tuple< A... > >
args(A... arg)
{
   return detail::args_class<T, std::tuple<A...> >(std::tuple<A...>(arg...));
}

namespace detail {

/// @addtogroup Efl_Cxx_Detail
/// @{

/// @internal
///
/// @brief Provides all operations of type @p T.
///
/// @param T An <em>EO C++ Class</em>
///
/// There must be an unique specialization of this class for each
/// declared <em>EO C++ Class</em>.
///
template <typename T> struct operations;

template <>
struct operations< ::eo::Base> { template <typename T> struct type {}; };
  
/// @internal
///
/// @brief Provides the operations of an extension as well as its
/// conversion operator.
///
/// @param T The <em>EO C++ Extension</em>
///
/// There must be an unique specialization of @ref
/// efl::eo::detail::extension_inheritance for each known <em>EO C++
/// Extension</em> -- i.e., @em Interfaces and @em Mixins.
///
template <typename T>
struct extension_inheritance {};

/// @internal
///
/// @brief efl::eo::inherit's private data.
///
struct Inherit_Private_Data
{
   void* this_;
};

} } } // namespace efl { namespace eo { namespace detail {

namespace efl { namespace eo { namespace detail {
template <typename T>
int initialize_operation_description(efl::eo::detail::tag< ::eo::Base>
                                 , Eo_Op_Description* ops)
{
   (void)ops;
   return 0;
}

/// @}

} } } // namespace efl { namespace eo { namespace detail {

#endif