[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/wravery/cppgraphqlgen/main/samples/learn/DroidData.cpp [Back]  [Original]

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "DroidData.h"

#include "HumanData.h"

namespace graphql::learn {

Droid::Droid(std::string&& id, std::optional&& name, std::vector&& appearsIn,
	std::optional&& primaryFunction) noexcept
	: id_ { std::move(id) }
	, name_ { std::move(name) }
	, appearsIn_ { std::move(appearsIn) }
	, primaryFunction_ { std::move(primaryFunction) }
{
}

void Droid::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& Droid::getId() const noexcept
{
	return id_;
}

const std::optional& Droid::getName() const noexcept
{
	return name_;
}

std::optional Droid::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 Droid::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& Droid::getPrimaryFunction() const noexcept
{
	return primaryFunction_;
}

} // namespace graphql::learn

Web Proxy Viewer  |  New URL  |  Original Page