123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /*
- * MIT License
- *
- * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Tatyana Borisova <tanusshhka@mail.ru>
- *
- * 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 <QMetaType>\n"
- "#include <QList>\n"
- "#include <protobufobject.h>\n"
- "#include <unordered_map>\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 <QObject>\n";
- const char *Templates::InternalIncludeTemplate = "#include \"$include$.h\"\n";
- const char *Templates::ExternalIncludeTemplate = "#include <$include$>\n";
- const char *Templates::GlobalEnumIncludeTemplate = "#include <globalenums.h>\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"
- " qRegisterMetaType<$classname$>(\"$classname$\");\n"
- " qRegisterMetaType<$classname$List>(\"$classname$List\");\n"
- " qRegisterMetaType<$classname$>(\"$namespaces$::$classname$\");\n"
- " qRegisterMetaType<$classname$List>(\"$namespaces$::$classname$List\");\n"
- " registerSerializers();\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$($parameter_list$QObject *parent = nullptr) : ProtobufObject(parent)";
- 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<int/*field number*/, int/*property number*/> propertyOrdering;\n";
- const char *Templates::FieldsOrderingContainerTemplate = "const std::unordered_map<int, int> $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::PropertyInitializerTemplate = "\n ,m_$property_name$($property_name$)";
- const char *Templates::ConstructorContentTemplate = "\n{\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::RegisterMetaTypeDefaultTemplate = "qRegisterMetaType<$namespaces$::$type$>();\n";
- const char *Templates::RegisterMetaTypeTemplateNoNamespace = "qRegisterMetaType<$namespaces$::$type$>(\"$type$\");\n";
- const char *Templates::RegisterMetaTypeTemplate = "qRegisterMetaType<$namespaces$::$type$>(\"$namespaces$::$type$\");\n";
- const char *Templates::QEnumTemplate = "Q_ENUM($type$)\n";
- const char *Templates::MapSerializationRegisterTemplate = "qtprotobuf::ProtobufObjectPrivate::wrapSerializer<$classname$::$type$>(\n"
- "qtprotobuf::ProtobufObjectPrivate::serializeMap<$classname$::$type$::key_type, $classname$::$type$::mapped_type>,\n"
- "qtprotobuf::ProtobufObjectPrivate::deserializeMap<$classname$::$type$::key_type, $classname$::$type$::mapped_type>\n"
- ", qtprotobuf::LengthDelimited);\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
- };
|