-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathnode.h
More file actions
60 lines (46 loc) · 1.46 KB
/
node.h
File metadata and controls
60 lines (46 loc) · 1.46 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (C) 2017-2018 Egor Pugin <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <memory>
#include <type_traits>
namespace sw
{
/// provides castable interface (as() methods)
struct SW_BUILDER_API ICastable
{
virtual ~ICastable() = 0;
template <class T, typename = std::enable_if_t<std::is_pointer_v<T>>>
std::decay_t<std::remove_pointer_t<T>> *as()
{
return dynamic_cast<std::decay_t<std::remove_pointer_t<T>> *>(this);
}
template <class T, typename = std::enable_if_t<std::is_pointer_v<T>>>
const std::decay_t<std::remove_pointer_t<T>> *as() const
{
return dynamic_cast<const std::decay_t<std::remove_pointer_t<T>> *>(this);
}
template <class T, typename = std::enable_if_t<!std::is_pointer_v<T>>>
std::decay_t<T> &as()
{
return dynamic_cast<std::decay_t<T> &>(*this);
}
template <class T, typename = std::enable_if_t<!std::is_pointer_v<T>>>
const std::decay_t<T> &as() const
{
return dynamic_cast<const std::decay_t<T> &>(*this);
}
};
namespace builder { struct Command; }
namespace detail
{
struct SW_BUILDER_API Executable
{
virtual ~Executable() = default;
virtual std::shared_ptr<builder::Command> getCommand() const = 0;
virtual void execute() const;
};
}
}