File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,24 @@ class IBackendObject
23
23
bool isCompatibleDevicewise (const IBackendObject* other) const ;
24
24
25
25
bool wasCreatedBy (const ILogicalDevice* device) const ;
26
+
27
+ template <typename derived_t_ptr, typename base_t_ptr>
28
+ static inline derived_t_ptr cast (base_t_ptr base, const ILogicalDevice* device)
29
+ {
30
+ using base_t = std::remove_pointer_t <base_t_ptr>;
31
+ using derived_t = std::remove_pointer_t <derived_t_ptr>;
32
+ static_assert (std::is_base_of_v<IBackendObject, base_t >," base_t should be derived from IBackendObject" );
33
+ static_assert (std::is_base_of_v<base_t ,derived_t >," derived_t should be derived from base_t" );
34
+ if (!base->wasCreatedBy (device))
35
+ return nullptr ;
36
+ return static_cast <derived_t_ptr>(base);
37
+ }
38
+
39
+ template <typename derived_t_ptr, typename base_t_ptr, typename other_t_ptr>
40
+ static inline derived_t_ptr cast (base_t_ptr base, const other_t_ptr& compatibleWith)
41
+ {
42
+ return cast<derived_t_ptr,base_t_ptr>(base,compatibleWith->getOriginDevice ());
43
+ }
26
44
27
45
const ILogicalDevice* getOriginDevice () const ;
28
46
You can’t perform that action at this time.
0 commit comments