diff --git a/src/google/protobuf/compiler/cpp/helpers.cc b/src/google/protobuf/compiler/cpp/helpers.cc index 569bc1dc31..89df52b593 100644 --- a/src/google/protobuf/compiler/cpp/helpers.cc +++ b/src/google/protobuf/compiler/cpp/helpers.cc @@ -403,6 +403,7 @@ std::string Namespace(const std::string& package) { return "::" + DotsToColons(package); } +std::string Namespace(const FileDescriptor* d) { return Namespace(d, {}); } std::string Namespace(const FileDescriptor* d, const Options& options) { std::string ns = Namespace(d->package()); if (IsWellKnownMessage(d) && options.opensource_runtime) { @@ -418,14 +419,17 @@ std::string Namespace(const FileDescriptor* d, const Options& options) { return ns; } +std::string Namespace(const Descriptor* d) { return Namespace(d, {}); } std::string Namespace(const Descriptor* d, const Options& options) { return Namespace(d->file(), options); } +std::string Namespace(const FieldDescriptor* d) { return Namespace(d, {}); } std::string Namespace(const FieldDescriptor* d, const Options& options) { return Namespace(d->file(), options); } +std::string Namespace(const EnumDescriptor* d) { return Namespace(d, {}); } std::string Namespace(const EnumDescriptor* d, const Options& options) { return Namespace(d->file(), options); } diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index 87b7221cc8..8e537f22aa 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -116,6 +116,10 @@ std::string Namespace(const FileDescriptor* d, const Options& options); std::string Namespace(const Descriptor* d, const Options& options); std::string Namespace(const FieldDescriptor* d, const Options& options); std::string Namespace(const EnumDescriptor* d, const Options& options); +std::string Namespace(const FileDescriptor* d); +std::string Namespace(const Descriptor* d); +std::string Namespace(const FieldDescriptor* d); +std::string Namespace(const EnumDescriptor* d); // Returns true if it's safe to reset "field" to zero. bool CanInitializeByZeroing(const FieldDescriptor* field); diff --git a/src/google/protobuf/compiler/cpp/names.h b/src/google/protobuf/compiler/cpp/names.h index d83cabbac0..f4dac4c644 100644 --- a/src/google/protobuf/compiler/cpp/names.h +++ b/src/google/protobuf/compiler/cpp/names.h @@ -43,10 +43,23 @@ class Descriptor; class EnumDescriptor; class EnumValueDescriptor; class FieldDescriptor; +class FileDescriptor; namespace compiler { namespace cpp { +// Returns the fully qualified C++ namespace. +// +// For example, if you had: +// package foo.bar; +// message Baz { message Moo {} } +// Then the qualified namespace for Moo would be: +// ::foo::bar +std::string Namespace(const FileDescriptor* d); +std::string Namespace(const Descriptor* d); +std::string Namespace(const FieldDescriptor* d); +std::string Namespace(const EnumDescriptor* d); + // Returns the unqualified C++ name. // // For example, if you had: