forked from microsoft/cppgraphqlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryData.cpp
56 lines (42 loc) · 1.38 KB
/
QueryData.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
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "CharacterObject.h"
#include "QueryData.h"
namespace graphql::learn {
Query::Query(std::map<Episode, SharedHero>&& heroes,
std::map<response::IdType, std::shared_ptr<Human>>&& humans,
std::map<response::IdType, std::shared_ptr<Droid>>&& droids) noexcept
: heroes_ { std::move(heroes) }
, humans_ { std::move(humans) }
, droids_ { std::move(droids) }
{
}
std::shared_ptr<object::Character> Query::getHero(std::optional<Episode> episodeArg) const noexcept
{
std::shared_ptr<object::Character> result;
const auto episode = episodeArg ? *episodeArg : Episode::NEW_HOPE;
if (const auto itr = heroes_.find(episode); itr != heroes_.end())
{
result = make_hero(itr->second);
}
return result;
}
std::shared_ptr<object::Human> Query::getHuman(const response::IdType& idArg) const noexcept
{
std::shared_ptr<object::Human> result;
if (const auto itr = humans_.find(idArg); itr != humans_.end())
{
result = std::make_shared<object::Human>(itr->second);
}
return result;
}
std::shared_ptr<object::Droid> Query::getDroid(const response::IdType& idArg) const noexcept
{
std::shared_ptr<object::Droid> result;
if (const auto itr = droids_.find(idArg); itr != droids_.end())
{
result = std::make_shared<object::Droid>(itr->second);
}
return result;
}
} // namespace graphql::learn