/Users/deen/code/yugabyte-db/src/yb/yql/pggate/type_mapping.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | // Provides mappings for argument and return types between YB C API and its C++ implementation. |
15 | | |
16 | | #ifndef YB_YQL_PGGATE_TYPE_MAPPING_H |
17 | | #define YB_YQL_PGGATE_TYPE_MAPPING_H |
18 | | |
19 | | #include "yb/common/ybc-internal.h" |
20 | | #include "yb/common/ybc_util.h" |
21 | | |
22 | | #include "yb/util/status_fwd.h" |
23 | | |
24 | | #include "yb/yql/pggate/ybc_pg_typedefs.h" |
25 | | |
26 | | namespace yb { |
27 | | namespace pggate { |
28 | | namespace impl { |
29 | | |
30 | | // ------------------------------------------------------------------------------------------------ |
31 | | // Mapping from C API return types to return types of actual C++ member function implementations. |
32 | | |
33 | | // The type mapping is an identity mapping by default. |
34 | | template<typename c_type> struct ReturnTypeMapper { |
35 | | typedef c_type cxx_ret_type; |
36 | | |
37 | | static c_type ToC(cxx_ret_type cxx_value) { |
38 | | return cxx_value; |
39 | | } |
40 | | }; |
41 | | |
42 | | template<> struct ReturnTypeMapper<YBCStatus> { |
43 | | typedef Status cxx_ret_type; |
44 | | |
45 | 0 | static YBCStatus ToC(cxx_ret_type cxx_value) { |
46 | 0 | return ::yb::ToYBCStatus(cxx_value); |
47 | 0 | } |
48 | | }; |
49 | | |
50 | | // ------------------------------------------------------------------------------------------------ |
51 | | // Mapping from C API function argument types to argument types of actual C++ member functions. |
52 | | |
53 | | // The type mapping is an identity mapping by default. |
54 | | template<typename c_type> struct ArgTypeMapper { |
55 | | typedef c_type cxx_type; |
56 | | |
57 | | static cxx_type ToCxx(c_type c_value) { |
58 | | return c_value; |
59 | | } |
60 | | }; |
61 | | |
62 | | // This template is specialized by C++ class generation macros to map an opaque struct pointer to |
63 | | // a pointer to the implementation's C++ class. |
64 | | |
65 | | } // namespace impl |
66 | | |
67 | | } // namespace pggate |
68 | | } // namespace yb |
69 | | |
70 | | #endif // YB_YQL_PGGATE_TYPE_MAPPING_H |