34 #include "templates.h"
36 #include <google/protobuf/descriptor.h>
38 namespace QtProtobuf {
41 using TypeMap = std::map<std::string, std::string>;
42 using PropertyMap = std::map<std::string, std::string>;
43 using MethodMap = std::map<std::string, std::string>;
53 static std::vector<std::string> getNamespaces(
const T *type) {
54 if (type ==
nullptr) {
58 std::vector<std::string> namespacesList = utils::split(type->full_name(),
'.');
59 if (!namespacesList.empty()) {
60 namespacesList.pop_back();
62 return namespacesList;
65 static std::vector<std::string> getNestedNamespaces(const ::google::protobuf::Descriptor *type) {
66 auto namespaces = getNamespaces(type);
67 auto package = utils::split(type->file()->package(), '.');
68 for (
size_t i = package.size(); i < namespaces.size(); i++) {
69 namespaces[i] += Templates::QtProtobufNestedNamespace;
75 static std::string getNamespacesString(
const std::vector<std::string> &namespacesList,
const std::string &separator);
76 static std::string getScopeNamespacesString(std::string original,
const std::string &scope);
77 static TypeMap produceQtTypeMap(const ::google::protobuf::Descriptor *type, const ::google::protobuf::Descriptor *scope);
78 static TypeMap produceMessageTypeMap(const ::google::protobuf::Descriptor *type, const ::google::protobuf::Descriptor *scope);
79 static TypeMap produceEnumTypeMap(const ::google::protobuf::EnumDescriptor *type, const ::google::protobuf::Descriptor *scope);
80 static TypeMap produceSimpleTypeMap(::google::protobuf::FieldDescriptor::Type type);
81 static TypeMap produceTypeMap(const ::google::protobuf::FieldDescriptor *field, const ::google::protobuf::Descriptor *scope);
82 static PropertyMap producePropertyMap(const ::google::protobuf::FieldDescriptor *field, const ::google::protobuf::Descriptor *scope);
83 static std::string qualifiedName(
const std::string &name);
84 static bool isLocalEnum(const ::google::protobuf::EnumDescriptor *type,
const google::protobuf::Descriptor *scope);
85 static EnumVisibility enumVisibility(const ::google::protobuf::EnumDescriptor *type, const ::google::protobuf::Descriptor *scope);
86 static bool hasQmlAlias(const ::google::protobuf::FieldDescriptor *field);
87 static bool isQtType(const ::google::protobuf::FieldDescriptor *field);
88 static bool isPureMessage(const ::google::protobuf::FieldDescriptor *field);
90 using InterateMessageLogic = std::function<void(const ::google::protobuf::FieldDescriptor *, PropertyMap &)>;
91 static void iterateMessageFields(const ::google::protobuf::Descriptor *message, InterateMessageLogic callback) {
92 for (
int i = 0; i < message->field_count(); i++) {
93 const ::google::protobuf::FieldDescriptor *field = message->field(i);
94 auto propertyMap = common::producePropertyMap(field, message);
95 callback(field, propertyMap);
99 static MethodMap produceMethodMap(const ::google::protobuf::MethodDescriptor *method,
const std::string &scope);
101 static void iterateMessages(const ::google::protobuf::FileDescriptor *file, std::function<
void(const ::google::protobuf::Descriptor *)> callback);
102 static void iterateNestedMessages(const ::google::protobuf::Descriptor *message, std::function<
void(const ::google::protobuf::Descriptor *)> callback);
104 static bool hasNestedMessages(const ::google::protobuf::Descriptor *message);
106 static bool isNested(const ::google::protobuf::Descriptor *message);
107 static bool isNestedOf(const ::google::protobuf::Descriptor *message, const ::google::protobuf::Descriptor *containing) {
108 return containing == message->containing_type();
110 static const ::google::protobuf::Descriptor *findHighestMessage(const ::google::protobuf::Descriptor *message);
Definition: generatorcommon.h:45