rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
operation_cast.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include <rexlib/core/operation/operation.hpp>
6#include <rexlib/core/operation/operation_descriptor.hpp>
7#include <rexlib/core/operation/operation_id.hpp>
8
10#include <rexlib/core/platform/dynamic_shared_object.h>
11
12#include <typeinfo>
13
14namespace rexlib
15{
16
24REXLIB_NORETURN REXLIB_API
26 const operation &got,
28);
29
40 const operation &got,
41 const char *expected
42);
43
44namespace detail
45{
46
47template <typename Op, typename = void>
49{
50 static const char* get() noexcept
51 {
52 return typeid(Op).name();
53 }
54};
55
56template <typename Op>
58 Op,
59 decltype(void(Op::get_static_descriptor()))
60>
61{
62 static const operation_descriptor& get() noexcept
63 {
64 return Op::get_static_descriptor();
65 }
66};
67
68} // namespace detail
69
84template <typename Op>
86{
87 if (op.get_id() != operation_id::of<Op>())
88 {
90 op,
92 );
93 }
94
95 return static_cast<const Op&>(op);
96}
97
98} // namespace rexlib
Macro definitions for supported attributes.
#define REXLIB_NORETURN
Indicates that the function does not return.
Definition attributes.hpp:32
Container for multidimensional numeric data.
Definition array.hpp:31
Immutable static description of an operation type.
Definition operation_descriptor.hpp:30
Abstract class that describes an operation.
Definition operation.hpp:23
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
const Op & operation_cast(const operation &op)
Downcast an operation after checking its identity.
Definition operation_cast.hpp:85
REXLIB_NORETURN void throw_unexpected_operation(const operation &got, const operation_descriptor &expected)
Report an operation that is not of the expected type.
Definition operation_cast.hpp:49