// 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&& name, std::vector&& appearsIn,
std::optional&& homePlanet) noexcept
: id_ { std::move(id) }
, name_ { std::move(name) }
, appearsIn_ { std::move(appearsIn) }
, homePlanet_ { std::move(homePlanet) }
{
}
void Human::addFriends(std::vector friends) noexcept
{
friends_.resize(friends.size());
std::transform(friends.begin(),
friends.end(),
friends_.begin(),
[](const auto& spFriend) noexcept {
return std::visit(
[](const auto& hero) noexcept {
return WeakHero {
std::weak_ptr { hero }
};
},
spFriend);
});
}
const response::IdType& Human::getId() const noexcept
{
return id_;
}
const std::optional& Human::getName() const noexcept
{
return name_;
}
std::optional Human::getFriends() const noexcept
{
std::vector result(friends_.size());
std::transform(friends_.begin(),
friends_.end(),
result.begin(),
[](const auto& wpFriend) noexcept {
return make_hero(wpFriend);
});
result.erase(std::remove(result.begin(), result.end(), std::shared_ptr {}),
result.end());
return result.empty() ? std::nullopt : std::make_optional(std::move(result));
}
std::optional Human::getAppearsIn() const noexcept
{
std::vector result(appearsIn_.size());
std::transform(appearsIn_.begin(),
appearsIn_.end(),
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& Human::getHomePlanet() const noexcept
{
return homePlanet_;
}
} // namespace graphql::learn