FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppgraphqlgen/samples/learn/HumanData.cpp at issues-334 · gitmodimo/cppgraphqlgen · GitHub
gitmodimo
/
cppgraphqlgen
Public
forked from
microsoft/cppgraphqlgen
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppgraphqlgen
/
samples
/
learn
/
HumanData.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (57 loc) · 1.94 KB
Breadcrumbs
cppgraphqlgen
/
samples
/
learn
/
HumanData.cpp
Copy path
File metadata and controls
73 lines (57 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
61
62
63
64
65
66
67
68
69
70
71
72
73
//
Copyright (c) Microsoft Corporation. All rights reserved.
//
Licensed under the MIT License.
#
include
"
HumanData.h
"
#
include
"
DroidData.h
"
namespace
graphql
::learn {
Human::Human
(std::string&& id, std::optional<std::string>&& name, std::vector<Episode>&& appearsIn,
std::optional<std::string>&& homePlanet)
noexcept
: id_ {
std::move
(id) }
, name_ {
std::move
(name) }
, appearsIn_ {
std::move
(appearsIn) }
, homePlanet_ {
std::move
(homePlanet) }
{
}
void
Human::addFriends
(std::vector<SharedHero> friends)
noexcept
{
friends_.
resize
(friends.
size
());
std::ranges::transform
(friends, friends_.
begin
(), [](
const
auto
& spFriend)
noexcept
{
return
std::visit
(
[](
const
auto
& hero)
noexcept
{
return
WeakHero {
std::weak_ptr<
typename
std::
decay_t
<
decltype
(hero)>::element_type> { hero }
};
},
spFriend);
});
}
const
response::IdType&
Human::getId
()
const
noexcept
{
return
id_;
}
const
std::optional<std::string>&
Human::getName
()
const
noexcept
{
return
name_;
}
std::optional<std::vector<std::shared_ptr<object::Character>>>
Human::getFriends
()
const
noexcept
{
std::vector<std::shared_ptr<object::Character>>
result
(friends_.
size
());
std::ranges::transform
(friends_, result.
begin
(), [](
const
auto
& wpFriend)
noexcept
{
return
make_hero
(wpFriend);
});
result.
erase
(
std::remove
(result.
begin
(), result.
end
(), std::shared_ptr<object::Character> {}),
result.
end
());
return
result.
empty
() ? std::
nullopt
:
std::make_optional
(
std::move
(result));
}
std::optional<std::vector<std::optional<Episode>>>
Human::getAppearsIn
()
const
noexcept
{
std::vector<std::optional<Episode>>
result
(appearsIn_.
size
());
std::ranges::transform
(appearsIn_, result.
begin
(), [](
const
auto
& entry)
noexcept
{
return
std::make_optional
(entry);
});
return
result.
empty
() ? std::
nullopt
:
std::make_optional
(
std::move
(result));
}
const
std::optional<std::string>&
Human::getHomePlanet
()
const
noexcept
{
return
homePlanet_;
}
}
//
namespace graphql::learn
Back
|
FazBrowse Home
|
New Git URL