[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/gitmodimo/cppgraphqlgen/main/src/SchemaGenerator.cpp [Back]  [Original]

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

#include "SchemaGenerator.h"
#include "GeneratorUtil.h"

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 26495)
#pragma warning(disable : 26812)
#endif // _MSC_VER

#include 

#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std::literals;

namespace graphql::generator::schema {

Generator::Generator(SchemaOptions&& schemaOptions, GeneratorOptions&& options)
	: _loader(std::move(schemaOptions))
	, _options(std::move(options))
	, _headerDir(getHeaderDir())
	, _sourceDir(getSourceDir())
	, _headerPath(getHeaderPath())
	, _sourcePath(getSourcePath())
{
}

std::string Generator::getHeaderDir() const noexcept
{
	if (!_options.paths.headerPath.empty())
	{
		return std::filesystem::path { _options.paths.headerPath }.string();
	}
	else
	{
		return {};
	}
}

std::string Generator::getSourceDir() const noexcept
{
	if (!_options.paths.sourcePath.empty())
	{
		return std::filesystem::path(_options.paths.sourcePath).string();
	}
	else
	{
		return {};
	}
}

std::string Generator::getHeaderPath() const noexcept
{
	std::filesystem::path fullPath { _headerDir };

	fullPath /= (std::string { _loader.getFilenamePrefix() } + "Schema.h");
	return fullPath.string();
}

std::string Generator::getSourcePath() const noexcept
{
	std::filesystem::path fullPath { _sourceDir };

	fullPath /= (std::string { _loader.getFilenamePrefix() } + "Schema.cpp");
	return fullPath.string();
}

std::vector Generator::Build() const noexcept
{
	std::vector builtFiles;

	if (outputHeader() && _options.verbose)
	{
		builtFiles.push_back(_headerPath);
	}

	if (outputSource())
	{
		builtFiles.push_back(_sourcePath);
	}

	auto separateFiles = outputSeparateFiles();

	for (auto& file : separateFiles)
	{
		builtFiles.push_back(std::move(file));
	}

	return builtFiles;
}

bool Generator::outputHeader() const noexcept
{
	std::ofstream headerFile(_headerPath, std::ios_base::trunc);
	IncludeGuardScope includeGuard { headerFile,
		std::filesystem::path(_headerPath).filename().string() };

	headerFile 

Web Proxy Viewer  |  New URL  |  Original Page