|
@@ -1,7 +1,7 @@
|
|
/*
|
|
/*
|
|
* MIT License
|
|
* MIT License
|
|
*
|
|
*
|
|
- * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Tatyana Borisova <tanusshhka@mail.ru>
|
|
|
|
|
|
+ * Copyright (c) 2020 Alexey Edelev <semlanik@gmail.com>, Tatyana Borisova <tanusshhka@mail.ru>
|
|
*
|
|
*
|
|
* This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
|
|
* This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
|
|
*
|
|
*
|
|
@@ -23,14 +23,13 @@
|
|
* DEALINGS IN THE SOFTWARE.
|
|
* DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
*/
|
|
|
|
|
|
-#include "protobufclassgenerator.h"
|
|
|
|
|
|
+#include "messagedeclarationprinter.h"
|
|
#include "utils.h"
|
|
#include "utils.h"
|
|
#include "generatoroptions.h"
|
|
#include "generatoroptions.h"
|
|
#include "generatorcommon.h"
|
|
#include "generatorcommon.h"
|
|
|
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
#include <google/protobuf/descriptor.h>
|
|
#include <google/protobuf/descriptor.h>
|
|
-#include <google/protobuf/io/zero_copy_stream.h>
|
|
|
|
#include <google/protobuf/descriptor.pb.h>
|
|
#include <google/protobuf/descriptor.pb.h>
|
|
|
|
|
|
using namespace ::QtProtobuf::generator;
|
|
using namespace ::QtProtobuf::generator;
|
|
@@ -38,77 +37,53 @@ using namespace ::google::protobuf;
|
|
using namespace ::google::protobuf::io;
|
|
using namespace ::google::protobuf::io;
|
|
using namespace ::google::protobuf::compiler;
|
|
using namespace ::google::protobuf::compiler;
|
|
|
|
|
|
-ProtobufClassGenerator::ProtobufClassGenerator(const Descriptor *message, const std::shared_ptr<::google::protobuf::io::ZeroCopyOutputStream> &out)
|
|
|
|
- : ClassGeneratorBase(message->full_name(), out)
|
|
|
|
- , mMessage(message)
|
|
|
|
- , mTypeMap(common::produceMessageTypeMap(message, nullptr))
|
|
|
|
|
|
+MessageDeclarationPrinter::MessageDeclarationPrinter(const Descriptor *message, const std::shared_ptr<::google::protobuf::io::Printer> &printer)
|
|
|
|
+ : DescriptorPrinterBase<google::protobuf::Descriptor>(message, printer)
|
|
{
|
|
{
|
|
|
|
+ mTypeMap = common::produceMessageTypeMap(message, nullptr);
|
|
}
|
|
}
|
|
|
|
|
|
-ProtobufClassGenerator::ProtobufClassGenerator(const ::google::protobuf::Descriptor *message, const std::shared_ptr<::google::protobuf::io::Printer> &printer)
|
|
|
|
- : ClassGeneratorBase(message->full_name(), printer)
|
|
|
|
- , mMessage(message)
|
|
|
|
- , mTypeMap(common::produceMessageTypeMap(message, nullptr))
|
|
|
|
|
|
+void MessageDeclarationPrinter::printCopyFunctionality()
|
|
{
|
|
{
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void ProtobufClassGenerator::printCopyFunctionality()
|
|
|
|
-{
|
|
|
|
- assert(mMessage != nullptr);
|
|
|
|
- mPrinter->Print({{"classname", mClassName}},
|
|
|
|
|
|
+ assert(mDescriptor != nullptr);
|
|
|
|
+ mPrinter->Print({{"classname", mName}},
|
|
Templates::CopyConstructorDeclarationTemplate);
|
|
Templates::CopyConstructorDeclarationTemplate);
|
|
|
|
|
|
- mPrinter->Print({{"classname", mClassName}},
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}},
|
|
Templates::AssignmentOperatorDeclarationTemplate);
|
|
Templates::AssignmentOperatorDeclarationTemplate);
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printMoveSemantic()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printMoveSemantic()
|
|
{
|
|
{
|
|
- assert(mMessage != nullptr);
|
|
|
|
- mPrinter->Print({{"classname", mClassName}},
|
|
|
|
|
|
+ assert(mDescriptor != nullptr);
|
|
|
|
+ mPrinter->Print({{"classname", mName}},
|
|
Templates::MoveConstructorDeclarationTemplate);
|
|
Templates::MoveConstructorDeclarationTemplate);
|
|
|
|
|
|
- mPrinter->Print({{"classname", mClassName}},
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}},
|
|
Templates::MoveAssignmentOperatorDeclarationTemplate);
|
|
Templates::MoveAssignmentOperatorDeclarationTemplate);
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printComparisonOperators()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printComparisonOperators()
|
|
{
|
|
{
|
|
- assert(mMessage != nullptr);
|
|
|
|
- mPrinter->Print({{"classname", mClassName}}, Templates::EqualOperatorDeclarationTemplate);
|
|
|
|
|
|
+ assert(mDescriptor != nullptr);
|
|
|
|
+ mPrinter->Print({{"classname", mName}}, Templates::EqualOperatorDeclarationTemplate);
|
|
|
|
|
|
- mPrinter->Print({{"classname", mClassName}}, Templates::NotEqualOperatorDeclarationTemplate);
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}}, Templates::NotEqualOperatorDeclarationTemplate);
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printIncludes()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printConstructors()
|
|
{
|
|
{
|
|
- assert(mMessage != nullptr);
|
|
|
|
-
|
|
|
|
- mPrinter->Print(Templates::DefaultProtobufIncludesTemplate);
|
|
|
|
- if (GeneratorOptions::instance().hasQml()) {
|
|
|
|
- mPrinter->Print(Templates::QmlProtobufIncludesTemplate);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- std::set<std::string> existingIncludes;
|
|
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- printInclude(mMessage, mMessage->field(i), existingIncludes);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void ProtobufClassGenerator::printConstructors()
|
|
|
|
-{
|
|
|
|
- for (int i = 0; i <= mMessage->field_count(); i++) {
|
|
|
|
|
|
+ for (int i = 0; i <= mDescriptor->field_count(); i++) {
|
|
printConstructor(i);
|
|
printConstructor(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printConstructor(int fieldCount)
|
|
|
|
|
|
+void MessageDeclarationPrinter::printConstructor(int fieldCount)
|
|
{
|
|
{
|
|
std::vector<std::string> parameterList;
|
|
std::vector<std::string> parameterList;
|
|
- mPrinter->Print({{"classname", mClassName}}, Templates::ProtoConstructorBeginTemplate);
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}}, Templates::ProtoConstructorBeginTemplate);
|
|
for (int i = 0; i < fieldCount; i++) {
|
|
for (int i = 0; i < fieldCount; i++) {
|
|
- const FieldDescriptor *field = mMessage->field(i);
|
|
|
|
|
|
+ const FieldDescriptor *field = mDescriptor->field(i);
|
|
const char *parameterTemplate = Templates::ConstructorParameterTemplate;
|
|
const char *parameterTemplate = Templates::ConstructorParameterTemplate;
|
|
FieldDescriptor::Type fieldType = field->type();
|
|
FieldDescriptor::Type fieldType = field->type();
|
|
if (field->is_repeated() && !field->is_map()) {
|
|
if (field->is_repeated() && !field->is_map()) {
|
|
@@ -119,28 +94,27 @@ void ProtobufClassGenerator::printConstructor(int fieldCount)
|
|
|| field->is_map()) {
|
|
|| field->is_map()) {
|
|
parameterTemplate = Templates::ConstructorMessageParameterTemplate;
|
|
parameterTemplate = Templates::ConstructorMessageParameterTemplate;
|
|
}
|
|
}
|
|
- mPrinter->Print(common::producePropertyMap(field, mMessage), parameterTemplate);
|
|
|
|
|
|
+ mPrinter->Print(common::producePropertyMap(field, mDescriptor), parameterTemplate);
|
|
}
|
|
}
|
|
|
|
|
|
- mPrinter->Print({{"classname", mClassName}}, Templates::ProtoConstructorEndTemplate);
|
|
|
|
- mPrinter->Print("\n");
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}}, Templates::ProtoConstructorEndTemplate);
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printMaps()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printMaps()
|
|
{
|
|
{
|
|
Indent();
|
|
Indent();
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- const FieldDescriptor *field = mMessage->field(i);
|
|
|
|
|
|
+ for (int i = 0; i < mDescriptor->field_count(); i++) {
|
|
|
|
+ const FieldDescriptor *field = mDescriptor->field(i);
|
|
if (field->is_map()) {
|
|
if (field->is_map()) {
|
|
const Descriptor *type = field->message_type();
|
|
const Descriptor *type = field->message_type();
|
|
const char *mapTemplate = type->field(1)->type() == FieldDescriptor::TYPE_MESSAGE ? Templates::MessageMapTypeUsingTemplate : Templates::MapTypeUsingTemplate;
|
|
const char *mapTemplate = type->field(1)->type() == FieldDescriptor::TYPE_MESSAGE ? Templates::MessageMapTypeUsingTemplate : Templates::MapTypeUsingTemplate;
|
|
- mPrinter->Print(common::producePropertyMap(field, mMessage), mapTemplate);
|
|
|
|
|
|
+ mPrinter->Print(common::producePropertyMap(field, mDescriptor), mapTemplate);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Outdent();
|
|
Outdent();
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printMetaTypesDeclaration()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printMetaTypesDeclaration()
|
|
{
|
|
{
|
|
mPrinter->Print(mTypeMap,
|
|
mPrinter->Print(mTypeMap,
|
|
Templates::DeclareMetaTypeTemplate);
|
|
Templates::DeclareMetaTypeTemplate);
|
|
@@ -151,33 +125,31 @@ void ProtobufClassGenerator::printMetaTypesDeclaration()
|
|
mPrinter->Print(mTypeMap,
|
|
mPrinter->Print(mTypeMap,
|
|
Templates::DeclareComplexQmlListTypeTemplate);
|
|
Templates::DeclareComplexQmlListTypeTemplate);
|
|
}
|
|
}
|
|
-
|
|
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- const FieldDescriptor *field = mMessage->field(i);
|
|
|
|
- auto fieldMap = common::producePropertyMap(field, nullptr);
|
|
|
|
|
|
+ common::iterateMessageFields(mDescriptor, [&](const FieldDescriptor *field, PropertyMap &propertyMap) {
|
|
if (field->type() == FieldDescriptor::TYPE_ENUM
|
|
if (field->type() == FieldDescriptor::TYPE_ENUM
|
|
- && common::isLocalEnum(field->enum_type(), mMessage)) {
|
|
|
|
- mPrinter->Print(fieldMap, Templates::DeclareMetaTypeTemplate);
|
|
|
|
|
|
+ && common::isLocalEnum(field->enum_type(), mDescriptor)) {
|
|
|
|
+ mPrinter->Print(propertyMap, Templates::DeclareMetaTypeTemplate);
|
|
|
|
+ mPrinter->Print(propertyMap, Templates::DeclareMetaTypeListTemplate);
|
|
} else if (field->is_map()) {
|
|
} else if (field->is_map()) {
|
|
- fieldMap["key_type_underscore"] = fieldMap["key_type"];
|
|
|
|
- utils::replace(fieldMap["key_type_underscore"], "::", "_");
|
|
|
|
|
|
+ propertyMap["key_type_underscore"] = propertyMap["key_type"];
|
|
|
|
+ utils::replace(propertyMap["key_type_underscore"], "::", "_");
|
|
|
|
|
|
- fieldMap["value_type_underscore"] = fieldMap["key_type"];
|
|
|
|
- utils::replace(fieldMap["value_type_underscore"], "::", "_");
|
|
|
|
|
|
+ propertyMap["value_type_underscore"] = propertyMap["key_type"];
|
|
|
|
+ utils::replace(propertyMap["value_type_underscore"], "::", "_");
|
|
|
|
|
|
- mPrinter->Print(fieldMap, Templates::DeclareMetaTypeMapTemplate);
|
|
|
|
|
|
+ mPrinter->Print(propertyMap, Templates::DeclareMetaTypeMapTemplate);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printProperties()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printProperties()
|
|
{
|
|
{
|
|
- assert(mMessage != nullptr);
|
|
|
|
|
|
+ assert(mDescriptor != nullptr);
|
|
//private section
|
|
//private section
|
|
Indent();
|
|
Indent();
|
|
|
|
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- const FieldDescriptor *field = mMessage->field(i);
|
|
|
|
|
|
+ for (int i = 0; i < mDescriptor->field_count(); i++) {
|
|
|
|
+ const FieldDescriptor *field = mDescriptor->field(i);
|
|
const char *propertyTemplate = Templates::PropertyTemplate;
|
|
const char *propertyTemplate = Templates::PropertyTemplate;
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() && !field->is_repeated()) {
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() && !field->is_repeated()) {
|
|
propertyTemplate = Templates::MessagePropertyTemplate;
|
|
propertyTemplate = Templates::MessagePropertyTemplate;
|
|
@@ -186,32 +158,30 @@ void ProtobufClassGenerator::printProperties()
|
|
} else if (field->is_repeated() && !field->is_map()) {
|
|
} else if (field->is_repeated() && !field->is_map()) {
|
|
propertyTemplate = Templates::RepeatedPropertyTemplate;
|
|
propertyTemplate = Templates::RepeatedPropertyTemplate;
|
|
}
|
|
}
|
|
- mPrinter->Print(common::producePropertyMap(field, mMessage), propertyTemplate);
|
|
|
|
|
|
+ mPrinter->Print(common::producePropertyMap(field, mDescriptor), propertyTemplate);
|
|
}
|
|
}
|
|
|
|
|
|
//Generate extra QmlListProperty that is mapped to list
|
|
//Generate extra QmlListProperty that is mapped to list
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- const FieldDescriptor *field = mMessage->field(i);
|
|
|
|
|
|
+ for (int i = 0; i < mDescriptor->field_count(); i++) {
|
|
|
|
+ const FieldDescriptor *field = mDescriptor->field(i);
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && field->is_repeated() && !field->is_map()
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && field->is_repeated() && !field->is_map()
|
|
&& GeneratorOptions::instance().hasQml()) {
|
|
&& GeneratorOptions::instance().hasQml()) {
|
|
- mPrinter->Print(common::producePropertyMap(field, mMessage), Templates::QmlListPropertyTemplate);
|
|
|
|
|
|
+ mPrinter->Print(common::producePropertyMap(field, mDescriptor), Templates::QmlListPropertyTemplate);
|
|
} else if (common::hasQmlAlias(field)) {
|
|
} else if (common::hasQmlAlias(field)) {
|
|
- mPrinter->Print(common::producePropertyMap(field, mMessage), Templates::NonScriptableAliasPropertyTemplate);
|
|
|
|
|
|
+ mPrinter->Print(common::producePropertyMap(field, mDescriptor), Templates::NonScriptableAliasPropertyTemplate);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Outdent();
|
|
Outdent();
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printGetters()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printGetters()
|
|
{
|
|
{
|
|
Indent();
|
|
Indent();
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- const FieldDescriptor *field = mMessage->field(i);
|
|
|
|
|
|
+
|
|
|
|
+ common::iterateMessageFields(mDescriptor, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) {
|
|
printComments(field);
|
|
printComments(field);
|
|
mPrinter->Print("\n");
|
|
mPrinter->Print("\n");
|
|
-
|
|
|
|
- PropertyMap propertyMap = common::producePropertyMap(field, mMessage);
|
|
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() && !field->is_repeated()) {
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() && !field->is_repeated()) {
|
|
mPrinter->Print(propertyMap, Templates::GetterPrivateMessageDeclarationTemplate);
|
|
mPrinter->Print(propertyMap, Templates::GetterPrivateMessageDeclarationTemplate);
|
|
mPrinter->Print(propertyMap, Templates::GetterMessageDeclarationTemplate);
|
|
mPrinter->Print(propertyMap, Templates::GetterMessageDeclarationTemplate);
|
|
@@ -226,16 +196,14 @@ void ProtobufClassGenerator::printGetters()
|
|
mPrinter->Print(propertyMap, Templates::GetterQmlListDeclarationTemplate);
|
|
mPrinter->Print(propertyMap, Templates::GetterQmlListDeclarationTemplate);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
Outdent();
|
|
Outdent();
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printSetters()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printSetters()
|
|
{
|
|
{
|
|
Indent();
|
|
Indent();
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- auto field = mMessage->field(i);
|
|
|
|
- PropertyMap propertyMap = common::producePropertyMap(field, mMessage);
|
|
|
|
|
|
+ common::iterateMessageFields(mDescriptor, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) {
|
|
switch (field->type()) {
|
|
switch (field->type()) {
|
|
case FieldDescriptor::TYPE_MESSAGE:
|
|
case FieldDescriptor::TYPE_MESSAGE:
|
|
if (!field->is_map() && !field->is_repeated()) {
|
|
if (!field->is_map() && !field->is_repeated()) {
|
|
@@ -253,38 +221,68 @@ void ProtobufClassGenerator::printSetters()
|
|
mPrinter->Print(propertyMap, Templates::SetterTemplate);
|
|
mPrinter->Print(propertyMap, Templates::SetterTemplate);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
Outdent();
|
|
Outdent();
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printSignals()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printSignals()
|
|
{
|
|
{
|
|
Indent();
|
|
Indent();
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- mPrinter->Print(common::producePropertyMap(mMessage->field(i), mMessage), Templates::SignalTemplate);
|
|
|
|
|
|
+ for (int i = 0; i < mDescriptor->field_count(); i++) {
|
|
|
|
+ mPrinter->Print(common::producePropertyMap(mDescriptor->field(i), mDescriptor), Templates::SignalTemplate);
|
|
}
|
|
}
|
|
Outdent();
|
|
Outdent();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void ProtobufClassGenerator::printPrivateMethods()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printPrivateMethods()
|
|
{
|
|
{
|
|
Indent();
|
|
Indent();
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- auto field = mMessage->field(i);
|
|
|
|
- auto propertyMap = common::producePropertyMap(field, mMessage);
|
|
|
|
|
|
+ common::iterateMessageFields(mDescriptor, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) {
|
|
if (common::hasQmlAlias(field)) {
|
|
if (common::hasQmlAlias(field)) {
|
|
mPrinter->Print(propertyMap, Templates::NonScriptableGetterTemplate);
|
|
mPrinter->Print(propertyMap, Templates::NonScriptableGetterTemplate);
|
|
mPrinter->Print(propertyMap, Templates::NonScriptableSetterTemplate);
|
|
mPrinter->Print(propertyMap, Templates::NonScriptableSetterTemplate);
|
|
}
|
|
}
|
|
|
|
+ });
|
|
|
|
+ Outdent();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MessageDeclarationPrinter::printQEnums() {
|
|
|
|
+ if (mDescriptor->enum_type_count() <= 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ printPublicBlock();
|
|
|
|
+
|
|
|
|
+ Indent();
|
|
|
|
+ for (int i = 0; i < mDescriptor->enum_type_count(); i++) {
|
|
|
|
+ const auto enumDescr = mDescriptor->enum_type(i);
|
|
|
|
+ auto typeMap = common::produceEnumTypeMap(enumDescr, mDescriptor);
|
|
|
|
+ mPrinter->Print(typeMap, Templates::EnumDefinitionTemplate);
|
|
|
|
+
|
|
|
|
+ Indent();
|
|
|
|
+ for (int j = 0; j < enumDescr->value_count(); j++) {
|
|
|
|
+ const auto valueDescr = enumDescr->value(j);
|
|
|
|
+ mPrinter->Print({{"enumvalue", utils::upperCaseName(valueDescr->name())},
|
|
|
|
+ {"value", std::to_string(valueDescr->number())}}, Templates::EnumFieldTemplate);
|
|
|
|
+ }
|
|
|
|
+ Outdent();
|
|
|
|
+ mPrinter->Print(Templates::SemicolonBlockEnclosureTemplate);
|
|
|
|
+ mPrinter->Print(typeMap, Templates::QEnumTemplate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < mDescriptor->enum_type_count(); i++) {
|
|
|
|
+ const auto enumDescr = mDescriptor->enum_type(i);
|
|
|
|
+ auto typeMap = common::produceEnumTypeMap(enumDescr, mDescriptor);
|
|
|
|
+ mPrinter->Print(typeMap, Templates::EnumTypeRepeatedTemplate);
|
|
}
|
|
}
|
|
Outdent();
|
|
Outdent();
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printClassBody()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printClassBody()
|
|
{
|
|
{
|
|
printProperties();
|
|
printProperties();
|
|
- printQEnums(mMessage);
|
|
|
|
|
|
+ printQEnums();
|
|
|
|
|
|
printPublicBlock();
|
|
printPublicBlock();
|
|
printMaps();
|
|
printMaps();
|
|
@@ -303,7 +301,7 @@ void ProtobufClassGenerator::printClassBody()
|
|
printSetters();
|
|
printSetters();
|
|
|
|
|
|
Indent();
|
|
Indent();
|
|
- mPrinter->Print({{"classname", mClassName}}, Templates::ManualRegistrationDeclaration);
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}}, Templates::ManualRegistrationDeclaration);
|
|
Outdent();
|
|
Outdent();
|
|
|
|
|
|
printSignalsBlock();
|
|
printSignalsBlock();
|
|
@@ -316,17 +314,15 @@ void ProtobufClassGenerator::printClassBody()
|
|
printClassMembers();
|
|
printClassMembers();
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printListType()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printListType()
|
|
{
|
|
{
|
|
- mPrinter->Print({{"classname", mClassName}}, Templates::ComplexListTypeUsingTemplate);
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}}, Templates::ComplexListTypeUsingTemplate);
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::printClassMembers()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printClassMembers()
|
|
{
|
|
{
|
|
Indent();
|
|
Indent();
|
|
- for (int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- auto field = mMessage->field(i);
|
|
|
|
- auto propertyMap = common::producePropertyMap(field, mMessage);
|
|
|
|
|
|
+ common::iterateMessageFields(mDescriptor, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) {
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() && !field->is_repeated()) {
|
|
if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() && !field->is_repeated()) {
|
|
mPrinter->Print(propertyMap, Templates::ComplexMemberTemplate);
|
|
mPrinter->Print(propertyMap, Templates::ComplexMemberTemplate);
|
|
} else if(field->is_repeated() && !field->is_map()){
|
|
} else if(field->is_repeated() && !field->is_map()){
|
|
@@ -334,38 +330,11 @@ void ProtobufClassGenerator::printClassMembers()
|
|
} else {
|
|
} else {
|
|
mPrinter->Print(propertyMap, Templates::MemberTemplate);
|
|
mPrinter->Print(propertyMap, Templates::MemberTemplate);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
Outdent();
|
|
Outdent();
|
|
}
|
|
}
|
|
|
|
|
|
-void ProtobufClassGenerator::run()
|
|
|
|
|
|
+void MessageDeclarationPrinter::printDestructor()
|
|
{
|
|
{
|
|
- printDisclaimer();
|
|
|
|
- printPreamble();
|
|
|
|
- printIncludes();
|
|
|
|
- printNamespaces();
|
|
|
|
- printFieldClassDeclaration();
|
|
|
|
- printComments(mMessage);
|
|
|
|
- printClassDeclaration();
|
|
|
|
- printClassBody();
|
|
|
|
- encloseClass();
|
|
|
|
- printListType();
|
|
|
|
- encloseNamespaces();
|
|
|
|
- printMetaTypesDeclaration();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void ProtobufClassGenerator::printDestructor()
|
|
|
|
-{
|
|
|
|
- mPrinter->Print({{"classname", mClassName}}, "virtual ~$classname$();\n");
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void ProtobufClassGenerator::printFieldClassDeclaration()
|
|
|
|
-{
|
|
|
|
- for(int i = 0; i < mMessage->field_count(); i++) {
|
|
|
|
- auto field = mMessage->field(i);
|
|
|
|
- if (field->type() == FieldDescriptor::TYPE_MESSAGE
|
|
|
|
- && !field->is_map() && !field->is_repeated()) {
|
|
|
|
- mPrinter->Print({{"classname", utils::upperCaseName(field->message_type()->name())}}, Templates::ProtoClassDeclarationTemplate);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ mPrinter->Print({{"classname", mName}}, "virtual ~$classname$();\n");
|
|
}
|
|
}
|