forked from microsoft/cppgraphqlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeroData.cpp
51 lines (42 loc) · 1.3 KB
/
HeroData.cpp
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "HeroData.h"
#include "DroidData.h"
#include "HumanData.h"
#include "CharacterObject.h"
namespace graphql::learn {
std::shared_ptr<object::Character> make_hero(const SharedHero& hero) noexcept
{
return std::visit(
[](const auto& hero) noexcept {
using hero_t = std::decay_t<decltype(hero)>;
if constexpr (std::is_same_v<std::shared_ptr<Human>, hero_t>)
{
return std::make_shared<object::Character>(std::make_shared<object::Human>(hero));
}
else if constexpr (std::is_same_v<std::shared_ptr<Droid>, hero_t>)
{
return std::make_shared<object::Character>(std::make_shared<object::Droid>(hero));
}
},
hero);
}
std::shared_ptr<object::Character> make_hero(const WeakHero& hero) noexcept
{
return std::visit(
[](const auto& hero) noexcept {
using hero_t = std::decay_t<decltype(hero)>;
if constexpr (std::is_same_v<std::weak_ptr<Human>, hero_t>)
{
return std::make_shared<object::Character>(
std::make_shared<object::Human>(hero.lock()));
}
else if constexpr (std::is_same_v<std::weak_ptr<Droid>, hero_t>)
{
return std::make_shared<object::Character>(
std::make_shared<object::Droid>(hero.lock()));
}
},
hero);
}
} // namespace graphql::learn