/* * MIT License * * Copyright (c) 2019 Alexey Edelev , Tatyana Borisova * * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be included in all copies * or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "templates.h" using namespace qtprotobuf::generator; const char *Templates::DefaultProtobufIncludesTemplate = "#include \n" "#include \n" "#include \n" "#include \n\n"; const char *Templates::GlobalEnumClassNameTemplate = "GlobalEnums"; const char *Templates::PreambleTemplate = "/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */\n\n" "#pragma once\n\n" "#include \n"; const char *Templates::InternalIncludeTemplate = "#include \"$include$.h\"\n"; const char *Templates::ExternalIncludeTemplate = "#include <$include$>\n"; const char *Templates::GlobalEnumIncludeTemplate = "#include \n"; const char *Templates::UsingQtProtobufNamespaceTemplate = "\nusing namespace qtprotobuf;\n"; const char *Templates::ComplexTypeRegistrationMethodTemplate = "static void registerTypes();\n"; const char *Templates::ComplexTypeRegistrationTemplate = "void $classname$::registerTypes()\n{\n" " static bool registationDone = false;\n" " if (!registationDone) {\n\n" " int metaTypeId = qRegisterMetaType<$classname$>(\"$classname$\");\n" " int listMetaTypeId = qRegisterMetaType<$classname$List>(\"$classname$List\");\n" " qRegisterMetaType<$namespaces$::$classname$>(\"$namespaces$::$classname$\");\n" " qRegisterMetaType<$namespaces$::$classname$List>(\"$namespaces$::$classname$List\");\n" " registerSerializers(metaTypeId, listMetaTypeId);\n"; const char *Templates::ComplexListTypeUsingTemplate = "using $classname$List = QList<$classname$>;\n"; const char *Templates::MapTypeUsingTemplate = "using $classname$ = QMap<$key$, $value$>;\n"; const char *Templates::EnumTypeUsingTemplate = "using $enum$List = QList<$enum$>;\n"; const char *Templates::NamespaceTemplate = "\nnamespace $namespace$ {\n"; const char *Templates::UsingNamespaceTemplate = "using namespace $namespace$;\n"; const char *Templates::NonProtoClassDefinitionTemplate = "\nclass $classname$ : public QObject\n" "{\n" " Q_OBJECT\n"; const char *Templates::ProtoClassDefinitionTemplate = "\nclass $classname$ final : public qtprotobuf::ProtobufObject<$classname$>\n" "{\n" " Q_OBJECT\n"; const char *Templates::PropertyTemplate = "Q_PROPERTY($type$ $property_name$ READ $property_name$ WRITE set$property_name_cap$ NOTIFY $property_name$Changed)\n"; const char *Templates::MessagePropertyTemplate = "Q_PROPERTY($type$ $property_name$ READ $property_name$ WRITE set$property_name_cap$ NOTIFY $property_name$Changed)\n"; const char *Templates::MemberTemplate = "$type$ m_$property_name$;\n"; const char *Templates::EnumMemberTemplate = "::$type$ m_$property_name$;\n"; const char *Templates::PublicBlockTemplate = "\npublic:\n"; const char *Templates::PrivateBlockTemplate = "\nprivate:\n"; const char *Templates::EnumDefinitionTemplate = "enum $enum$ {\n"; const char *Templates::EnumFieldTemplate = "$enumvalue$ = $value$,\n"; const char *Templates::ProtoConstructorTemplate = "$classname$(QObject *parent = nullptr) : ProtobufObject(parent)\n"; const char *Templates::ConstructorTemplate = "$classname$();\n"; const char *Templates::CopyConstructorTemplate = "$classname$(const $classname$ &other) : ProtobufObject() {\n"; const char *Templates::MoveConstructorTemplate = "$classname$($classname$ &&other) : ProtobufObject() {\n"; const char *Templates::CopyFieldTemplate = "m_$property_name$ = other.m_$property_name$;\n"; const char *Templates::MoveComplexFieldTemplate = "m_$property_name$ = std::move(other.m_$property_name$);\n"; const char *Templates::MoveFieldTemplate = "m_$property_name$ = std::exchange(other.m_$property_name$, 0);\n"; const char *Templates::EnumMoveFieldTemplate = "m_$property_name$ = other.m_$property_name$;\n"; const char *Templates::AssignmentOperatorTemplate = "$classname$ &operator =(const $classname$ &other) {\n"; const char *Templates::AssignmentOperatorReturnTemplate = "return *this;\n"; const char *Templates::MoveAssignmentOperatorTemplate = "$classname$ &operator =($classname$ &&other) {\n"; const char *Templates::EqualOperatorTemplate = "bool operator ==(const $type$ &other) const {\n" " return "; const char *Templates::EqualOperatorPropertyTemplate = "m_$property_name$ == other.m_$property_name$"; const char *Templates::NotEqualOperatorTemplate = "bool operator !=(const $type$ &other) const {\n" " return !this->operator ==(other);\n" "}\n\n"; const char *Templates::GetterTemplate = "$type$ $property_name$() const {\n" " return m_$property_name$;\n" "}\n\n"; const char *Templates::SetterTemplateSimpleType = "void set$property_name_cap$($type$ $property_name$) {\n" " if (m_$property_name$ != $property_name$) {\n" " m_$property_name$ = $property_name$;\n" " $property_name$Changed();\n" " }\n" "}\n\n"; const char *Templates::SetterTemplateComplexType = "void set$property_name_cap$(const $type$ &$property_name$) {\n" " if (m_$property_name$ != $property_name$) {\n" " m_$property_name$ = $property_name$;\n" " $property_name$Changed();\n" " }\n" "}\n\n"; const char *Templates::SignalsBlockTemplate = "\nsignals:\n"; const char *Templates::SignalTemplate = "void $property_name$Changed();\n"; const char *Templates::FieldsOrderingDefinitionContainerTemplate = "static const std::unordered_map propertyOrdering;\n"; const char *Templates::FieldsOrderingContainerTemplate = "const std::unordered_map $type$::propertyOrdering = {"; const char *Templates::FieldOrderTemplate = "{$field_number$,$property_number$}"; const char *Templates::EnumTemplate = "$type$"; const char *Templates::SimpleBlockEnclosureTemplate = "}\n\n"; const char *Templates::SemicolonBlockEnclosureTemplate = "};\n"; const char *Templates::EmptyBlockTemplate = "{}\n\n"; const char *Templates::ConstructorContentTemplate = "{\n registerTypes();\n}\n"; const char *Templates::DeclareMetaTypeTemplate = "Q_DECLARE_METATYPE($namespaces$::$classname$)\n"; const char *Templates::DeclareComplexListTypeTemplate = "Q_DECLARE_METATYPE($namespaces$::$classname$List)\n"; const char *Templates::RegisterMetaTypeTemplate = " qRegisterMetaType<$namespaces$::$classname$>(\"$namespaces$::$classname$\");\n"; const char *Templates::QEnumTemplate = "Q_ENUM($type$)\n"; const char *Templates::ClassDefinitionTemplate = "\nclass $classname$ : public $parent_class$\n" "{\n"; const char *Templates::ClientMethodDeclarationSyncTemplate = "Q_INVOKABLE bool $method_name$(const $param_type$ &$param_name$, $return_type$ &$return_name$);\n"; const char *Templates::ClientMethodDeclarationAsyncTemplate = "Q_INVOKABLE bool $method_name$(const $param_type$ &$param_name$, const qtprotobuf::AsyncReply<$return_type$> &reply);\n"; const char *Templates::ServerMethodDeclarationTemplate = "Q_INVOKABLE virtual $return_type$ $method_name$(const $param_type$ &$param_name$) = 0;\n"; const char *Templates::ConstructorDefinitionSyncTemplate = "\n$classname$::$classname$() : $parent_class$(\"$service_name$\")\n" "{\n" "}\n"; const char *Templates::ClientMethodDefinitionSyncTemplate = "\nbool $classname$::$method_name$(const $param_type$ &$param_name$, $return_type$ &$return_name$)\n" "{\n" " return call(\"$method_name$\", $param_name$, $return_name$);\n" "}\n"; const char *Templates::ClientMethodDefinitionAsyncTemplate = "\nbool $classname$::$method_name$(const $param_type$ &$param_name$, const qtprotobuf::AsyncReply<$return_type$> &reply)\n" "{\n" " //TODO: call transport method to serialize this method\n" " return false;\n" "}\n"; const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::string> Templates::TypeReflection = { {::google::protobuf::FieldDescriptor::TYPE_DOUBLE, "double"}, {::google::protobuf::FieldDescriptor::TYPE_FLOAT, "float"}, {::google::protobuf::FieldDescriptor::TYPE_INT64, "int64"}, //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html {::google::protobuf::FieldDescriptor::TYPE_UINT64,"uint64"}, //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html {::google::protobuf::FieldDescriptor::TYPE_INT32, "int32"}, {::google::protobuf::FieldDescriptor::TYPE_FIXED64, "fint64"}, //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html {::google::protobuf::FieldDescriptor::TYPE_FIXED32, "fint32"}, {::google::protobuf::FieldDescriptor::TYPE_BOOL, "bool"}, {::google::protobuf::FieldDescriptor::TYPE_STRING, "QString"}, {::google::protobuf::FieldDescriptor::TYPE_BYTES, "QByteArray"}, {::google::protobuf::FieldDescriptor::TYPE_UINT32, "uint32"}, //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html {::google::protobuf::FieldDescriptor::TYPE_SFIXED32, "sfint32"}, {::google::protobuf::FieldDescriptor::TYPE_SFIXED64, "sfint64"}, //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html {::google::protobuf::FieldDescriptor::TYPE_SINT32, "sint32"}, {::google::protobuf::FieldDescriptor::TYPE_SINT64, "sint64"} //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html };