generateHeaderStart() . << #include #include #include 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"; echo "-- Autogenerating src/dpp/cluster_coro_calls.cpp\n"; return true; } /** * @inheritDoc */ public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string { return "[[nodiscard]] async co_{$currentFunction}($parameters);\n\n"; } /** * @inheritDoc */ public function generateCppDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string { /* if (substr($parameterNames, 0, 2) === ", ") $parameterNames = substr($parameterNames, 2); */ return "async cluster::co_${currentFunction}($noDefaults) {\n\treturn async{ this, static_cast(&cluster::$currentFunction)$parameterNames };\n}\n\n"; } /** * @inheritDoc */ public function getCommentArray(): array { return [" * \memberof dpp::cluster"]; } /** * @inheritDoc */ public function saveHeader(string $content): void { $content .= "[[nodiscard]] async co_request(const std::string &url, http_method method, const std::string &postdata = \"\", const std::string &mimetype = \"text/plain\", const std::multimap &headers = {}, const std::string &protocol = \"1.1\");\n\n"; file_put_contents('include/dpp/cluster_coro_calls.h', $content); } /** * @inheritDoc */ public function saveCpp(string $cppcontent): void { $cppcontent .= "dpp::async dpp::cluster::co_request(const std::string &url, http_method method, const std::string &postdata, const std::string &mimetype, const std::multimap &headers, const std::string &protocol) {\n\treturn async{ [&, this] (C &&cc) { return this->request(url, method, std::forward(cc), postdata, mimetype, headers, protocol); }};\n} #endif "; file_put_contents('src/dpp/cluster_coro_calls.cpp', $cppcontent); } }