mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-30 14:07:11 +02:00
Add D++ library.
This commit is contained in:
131
vendor/DPP/buildtools/classes/Generator/CoroGenerator.php
vendored
Normal file
131
vendor/DPP/buildtools/classes/Generator/CoroGenerator.php
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Dpp\Generator;
|
||||
|
||||
use Dpp\StructGeneratorInterface;
|
||||
|
||||
/**
|
||||
* Generate header and .cpp file for coroutine calls (starting with 'co_')
|
||||
*/
|
||||
class CoroGenerator implements StructGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHeaderStart(): string
|
||||
{
|
||||
return <<<EOT
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2022 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
/* Auto @generated by buildtools/make_coro_struct.php.
|
||||
*
|
||||
* DO NOT EDIT BY HAND!
|
||||
*
|
||||
* To re-generate this header file re-run the script!
|
||||
*/
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateCppStart(): string
|
||||
{
|
||||
return $this->generateHeaderStart() . <<<EOT
|
||||
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/coro.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function checkForChanges(): bool
|
||||
{
|
||||
/* Check if we need to re-generate by comparing modification times */
|
||||
$us = file_exists('include/dpp/cluster_coro_calls.h') ? filemtime('include/dpp/cluster_coro_calls.h') : 0;
|
||||
$them = filemtime('include/dpp/cluster.h');
|
||||
if ($them <= $us) {
|
||||
echo "-- No change required.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "-- Autogenerating include/dpp/cluster_coro_calls.h\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
|
||||
{
|
||||
$parameterNames = preg_replace('/^, /', '', $parameterNames);
|
||||
if (!empty($parameterNames)) {
|
||||
$parameterNames .= ', ';
|
||||
}
|
||||
return "auto inline co_{$currentFunction}($noDefaults) {\n\treturn dpp::awaitable(this, [&] (auto cc) { this->$currentFunction({$parameterNames}cc); }); \n}\n\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCommentArray(): array
|
||||
{
|
||||
return [" * \memberof dpp::cluster"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function saveHeader(string $content): void
|
||||
{
|
||||
$content .= "auto inline co_request(const std::string &url, http_method method, const std::string &postdata = \"\", const std::string &mimetype = \"text/plain\", const std::multimap<std::string, std::string> &headers = {}) {\n\treturn dpp::awaitable(this, [&] (auto cc) { this->request(url, method, cc, mimetype, headers); }); \n}\n\n";
|
||||
file_put_contents('include/dpp/cluster_coro_calls.h', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function saveCpp(string $cppcontent): void
|
||||
{
|
||||
/* No cpp file to save, code is all inline */
|
||||
}
|
||||
|
||||
}
|
130
vendor/DPP/buildtools/classes/Generator/SyncGenerator.php
vendored
Normal file
130
vendor/DPP/buildtools/classes/Generator/SyncGenerator.php
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Dpp\Generator;
|
||||
|
||||
use Dpp\StructGeneratorInterface;
|
||||
|
||||
/**
|
||||
* Generate header and .cpp file for synchronous calls (ending in '_sync')
|
||||
*/
|
||||
class SyncGenerator implements StructGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHeaderStart(): string
|
||||
{
|
||||
return <<<EOT
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2022 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
/* Auto @generated by buildtools/make_sync_struct.php.
|
||||
*
|
||||
* DO NOT EDIT BY HAND!
|
||||
*
|
||||
* To re-generate this header file re-run the script!
|
||||
*/
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateCppStart(): string
|
||||
{
|
||||
return $this->generateHeaderStart() . <<<EOT
|
||||
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <dpp/cluster.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function checkForChanges(): bool
|
||||
{
|
||||
/* Check if we need to re-generate by comparing modification times */
|
||||
$us = file_exists('include/dpp/cluster_sync_calls.h') ? filemtime('include/dpp/cluster_sync_calls.h') : 0;
|
||||
$them = filemtime('include/dpp/cluster.h');
|
||||
if ($them <= $us) {
|
||||
echo "-- No change required.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "-- Autogenerating include/dpp/cluster_sync_calls.h\n";
|
||||
echo "-- Autogenerating src/dpp/cluster_sync_calls.cpp\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
|
||||
{
|
||||
return "$returnType {$currentFunction}_sync($parameters);\n\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterNames): string
|
||||
{
|
||||
return "$returnType cluster::{$currentFunction}_sync($noDefaults) {\n\treturn dpp::sync<$returnType>(this, &cluster::$currentFunction$parameterNames);\n}\n\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCommentArray(): array
|
||||
{
|
||||
return [
|
||||
" * \memberof dpp::cluster",
|
||||
" * @throw dpp::rest_exception upon failure to execute REST function",
|
||||
" * @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.",
|
||||
" * Avoid direct use of this function inside an event handler.",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function saveHeader(string $content): void
|
||||
{
|
||||
file_put_contents('include/dpp/cluster_sync_calls.h', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function saveCpp(string $cppcontent): void
|
||||
{
|
||||
file_put_contents('src/dpp/cluster_sync_calls.cpp', $cppcontent);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user