Debian Codegraph @

libs/gltfio/src/upcast.h

raw
1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef TNT_FILAMENT_UPCAST_H
18 #define TNT_FILAMENT_UPCAST_H
19
20 /*
21 * Generates functions to safely upcast a pointer Bar* to FBar*
22 * FILAMENT_UPCAST() should be included in the header file
23 * declaring FBar, e.g.:
24 *
25 * #include <Bar.h>
26 *
27 * class FBar : public Bar {
28 * };
29 *
30 * FILAMENT_UPCAST(Bar)
31 *
32 */
33
34 #define FILAMENT_UPCAST(CLASS) \
35 inline F##CLASS& upcast(CLASS& that) noexcept { \
36 return static_cast<F##CLASS &>(that); \
37 } \
38 inline const F##CLASS& upcast(const CLASS& that) noexcept { \
39 return static_cast<const F##CLASS &>(that); \
40 } \
41 inline F##CLASS* upcast(CLASS* that) noexcept { \
42 return static_cast<F##CLASS *>(that); \
43 } \
44 inline F##CLASS const* upcast(CLASS const* that) noexcept { \
45 return static_cast<F##CLASS const *>(that); \
46 }
47
48 #endif // TNT_FILAMENT_UPCAST_H