blob: 2c79410a98aa9d1d75c7f8c952af25006afde6f2 (
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
|
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
namespace Timeline {
template<class Base>
class SafeCastable
{
public:
template<class Derived>
bool is() const
{
return static_cast<const Base *>(this)->classId() == Derived::staticClassId;
}
template<class Derived>
Derived &asRef()
{
Q_ASSERT(is<Derived>());
return static_cast<Derived &>(*this);
}
template<class Derived>
const Derived &asConstRef() const
{
Q_ASSERT(is<Derived>());
return static_cast<const Derived &>(*this);
}
template<class Derived>
Derived &&asRvalueRef()
{
Q_ASSERT(is<Derived>());
return static_cast<Derived &&>(*this);
}
};
} // namespace Timeline
|