Move namespace helpers into the public part of names.h

PiperOrigin-RevId: 485978369
pull/10903/head
Matt Kulukundis 2 years ago committed by Joshua Haberman
parent f4c07f297d
commit 1019b94795
  1. 4
      src/google/protobuf/compiler/cpp/helpers.cc
  2. 4
      src/google/protobuf/compiler/cpp/helpers.h
  3. 13
      src/google/protobuf/compiler/cpp/names.h

@ -403,6 +403,7 @@ std::string Namespace(const std::string& package) {
return "::" + DotsToColons(package); return "::" + DotsToColons(package);
} }
std::string Namespace(const FileDescriptor* d) { return Namespace(d, {}); }
std::string Namespace(const FileDescriptor* d, const Options& options) { std::string Namespace(const FileDescriptor* d, const Options& options) {
std::string ns = Namespace(d->package()); std::string ns = Namespace(d->package());
if (IsWellKnownMessage(d) && options.opensource_runtime) { if (IsWellKnownMessage(d) && options.opensource_runtime) {
@ -418,14 +419,17 @@ std::string Namespace(const FileDescriptor* d, const Options& options) {
return ns; return ns;
} }
std::string Namespace(const Descriptor* d) { return Namespace(d, {}); }
std::string Namespace(const Descriptor* d, const Options& options) { std::string Namespace(const Descriptor* d, const Options& options) {
return Namespace(d->file(), options); return Namespace(d->file(), options);
} }
std::string Namespace(const FieldDescriptor* d) { return Namespace(d, {}); }
std::string Namespace(const FieldDescriptor* d, const Options& options) { std::string Namespace(const FieldDescriptor* d, const Options& options) {
return Namespace(d->file(), options); return Namespace(d->file(), options);
} }
std::string Namespace(const EnumDescriptor* d) { return Namespace(d, {}); }
std::string Namespace(const EnumDescriptor* d, const Options& options) { std::string Namespace(const EnumDescriptor* d, const Options& options) {
return Namespace(d->file(), options); return Namespace(d->file(), options);
} }

@ -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 Descriptor* d, const Options& options);
std::string Namespace(const FieldDescriptor* 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 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. // Returns true if it's safe to reset "field" to zero.
bool CanInitializeByZeroing(const FieldDescriptor* field); bool CanInitializeByZeroing(const FieldDescriptor* field);

@ -43,10 +43,23 @@ class Descriptor;
class EnumDescriptor; class EnumDescriptor;
class EnumValueDescriptor; class EnumValueDescriptor;
class FieldDescriptor; class FieldDescriptor;
class FileDescriptor;
namespace compiler { namespace compiler {
namespace cpp { 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. // Returns the unqualified C++ name.
// //
// For example, if you had: // For example, if you had:

Loading…
Cancel
Save