') { return ''; } return 'std::vector<'.$this->getTypeName(substr($type, 7, -1)).'> &&'; } if (preg_match('/[^A-Za-z0-9.]/', $type)) { return ''; } return 'object_ptr<'.$this->getClassName($type).'> &&'; } } protected function escapeDocumentation($doc) { $doc = htmlspecialchars($doc); $doc = str_replace('*/', '*/', $doc); $doc = str_replace('#', '\#', $doc); return $doc; } protected function getFieldName($name) { if (substr($name, 0, 6) === 'param_') { $name = substr($name, 6); } return $name.'_'; } protected function getClassName($type) { return implode(explode('.', trim($type, "\n ;"))); } protected function getTypeName($type) { switch ($type) { case 'Bool': return 'bool'; case 'int32': return 'std::int32_t'; case 'int53': case 'int64': return 'std::int64_t'; case 'double': return 'double'; case 'string': case 'bytes': return 'std::string'; case 'bool': case 'int': case 'long': case 'Int': case 'Long': case 'Int32': case 'Int53': case 'Int64': case 'Double': case 'String': case 'Bytes': $this->printError("Wrong type $type"); return ''; default: if (substr($type, 0, 6) === 'vector') { if ($type[6] !== '<' || $type[strlen($type) - 1] !== '>') { $this->printError("Wrong vector subtype in $type"); return ''; } return 'std::vector<'.$this->getTypeName(substr($type, 7, -1)).'>'; } if (preg_match('/[^A-Za-z0-9.]/', $type)) { $this->printError("Wrong type $type"); return ''; } return 'object_ptr<'.$this->getClassName($type).'>'; } } protected function getBaseClassName($is_function) { return $is_function ? 'Function' : 'Object'; } protected function needRemoveLine($line) { $line = trim($line); return strpos($line, '/**') === 0 || strpos($line, '*') === 0 || strpos($line, '///') === 0; } protected function needSkipLine($line) { $tline = trim($line); return empty($tline) || $tline[0] == '}' || $tline == 'public:' || strpos($line, '#pragma ') === 0 || strpos($line, '#include <') === 0 || strpos($tline, 'return ') === 0 || strpos($tline, 'namespace') === 0 || preg_match('/class [A-Za-z0-9_]*;/', $line) || $tline === 'if (value == nullptr) {'; } protected function isHeaderLine($line) { return strpos($line, 'template <') === 0; } protected function extractClassName($line) { if (strpos($line, 'class ') === 0) { return explode(' ', trim($line))[1]; } return ''; } protected function fixLine($line) { if (strpos($line, 'ID = ') > 0 || strpos($line, 'ReturnType = ') > 0) { return substr($line, 0, strpos($line, '=')); } return $line; } protected function addGlobalDocumentation() { $this->addDocumentation('#include "td/tl/TlObject.h"', <<addDocumentation('using BaseObject = ::td::TlObject;', <<addDocumentation('using object_ptr = ::td::tl_object_ptr;', <<addDocumentation('object_ptr make_object(Args &&... args) {', <<(); * auto send_message_request = td::td_api::make_object(chat_id, 0, false, false, nullptr, * td::td_api::make_object("Hello, world!!!", false, true, {}, nullptr)); * \\endcode * * \\tparam Type Type of an object to construct. * \\param[in] args Arguments to pass to the object constructor. * \\return Wrapped pointer to the created object. */ EOT ); $this->addDocumentation('object_ptr move_object_as(FromType &&from) {', << call_state = ...; * switch (call_state->get_id()) { * case td::td_api::callStatePending::ID: { * auto state = td::move_tl_object_as(call_state); * // use state * break; * } * case td::td_api::callStateExchangingKeys::ID: { * // no additional fields, no casting is needed * break; * } * case td::td_api::callStateReady::ID: { * auto state = td::move_tl_object_as(call_state); * // use state * break; * } * case td::td_api::callStateHangingUp::ID: { * // no additional fields, no casting is needed * break; * } * case td::td_api::callStateDiscarded::ID: { * auto state = td::move_tl_object_as(call_state); * // use state * break; * } * case td::td_api::callStateError::ID: { * auto state = td::move_tl_object_as(call_state); * // use state * break; * } * default: * assert(false); * } * \\endcode * * \\tparam ToType Type of a TDLib API object to move to. * \\tparam FromType Type of a TDLib API object to move from, this is auto-deduced. * \\param[in] from Wrapped in td::td_api::object_ptr pointer to a TDLib API object. */ EOT ); $this->addDocumentation('std::string to_string(const BaseObject &value);', <<addDocumentation('std::string to_string(const object_ptr &value) {', <<addDocumentation(' void store(TlStorerToString &s, const char *field_name) const final;', <<addDocumentation('class Object: public TlObject {', <<addDocumentation('class Function: public TlObject {', <<addDocumentation(' static const std::int32_t ID', <<addDocumentation(' std::int32_t get_id() const final {', <<ID. */ EOT ); $this->addDocumentation(' using ReturnType', <<addDocumentation("class $class_name: public Object {", <<addDocumentation("class $class_name final : public $base_class_name {", <<addDocumentation($class_name." $type_name $field_name;", <<addDocumentation(" $class_name();", << $type) { $full_constructor .= $colon.$this->getParameterTypeName($type).$this->getFieldName($name); $colon = ', '; } $full_constructor .= ');'; $full_doc = << $type) { $full_doc .= ' * \\param[in] '.$this->getFieldName($name).' '.$info[$name]."\n"; } $full_doc .= ' */'; $this->addDocumentation($full_constructor, $full_doc); } } $generator = new DoxygenTlDocumentationGenerator(); $generator->generate($argv[1], $argv[2]);