28 #include "baseprinter.h"
31 #include "templates.h"
32 #include "generatoroptions.h"
33 #include "generatorcommon.h"
35 namespace QtProtobuf {
38 using PropertyMap = std::map<std::string, std::string>;
47 class DescriptorPrinterBase :
public BasePrinter
50 DescriptorPrinterBase(
const T* descriptor,
const std::shared_ptr<::google::protobuf::io::Printer> &printer) : BasePrinter(printer)
51 , mDescriptor(descriptor)
52 , mName(utils::upperCaseName(descriptor->name()))
54 virtual ~DescriptorPrinterBase() =
default;
57 mPrinter->Print(Templates::SemicolonBlockEnclosureTemplate);
58 mPrinter->Print(
"\n");
61 void printNamespaces() {
62 auto namespaces = common::getNamespaces(mDescriptor);
63 if (!GeneratorOptions::instance().extraNamespace().empty()) {
64 namespaces.insert(namespaces.begin(), GeneratorOptions::instance().extraNamespace());
66 mPrinter->Print(
"\n");
67 for (
auto ns : namespaces) {
68 mPrinter->Print({{
"namespace", ns}}, Templates::NamespaceTemplate);
72 void encloseNamespaces() {
73 auto namespacesSize = common::getNamespaces(mDescriptor).size();
74 if (!GeneratorOptions::instance().extraNamespace().empty()) {
77 mPrinter->Print(
"\n");
78 for (
size_t i = 0; i < namespacesSize; ++i) {
79 mPrinter->Print(Templates::SimpleBlockEnclosureTemplate);
81 mPrinter->Print(
"\n");