1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ 9 #define GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ 10 11 #include <string> 12 13 #include "absl/strings/string_view.h" 14 15 // Must be included last. 16 #include "google/protobuf/port_def.inc" 17 18 namespace google { 19 namespace protobuf { 20 21 class Descriptor; 22 class EnumDescriptor; 23 class EnumValueDescriptor; 24 class FieldDescriptor; 25 class FileDescriptor; 26 27 namespace compiler { 28 namespace cpp { 29 30 // Returns the fully qualified C++ namespace. 31 // 32 // For example, if you had: 33 // package foo.bar; 34 // message Baz { message Moo {} } 35 // Then the qualified namespace for Moo would be: 36 // ::foo::bar 37 PROTOC_EXPORT std::string Namespace(const FileDescriptor* d); 38 PROTOC_EXPORT std::string Namespace(const Descriptor* d); 39 PROTOC_EXPORT std::string Namespace(const FieldDescriptor* d); 40 PROTOC_EXPORT std::string Namespace(const EnumDescriptor* d); 41 42 // Returns the unqualified C++ name. 43 // 44 // For example, if you had: 45 // package foo.bar; 46 // message Baz { message Moo {} } 47 // Then the non-qualified version would be: 48 // Baz_Moo 49 PROTOC_EXPORT std::string ClassName(const Descriptor* descriptor); 50 PROTOC_EXPORT std::string ClassName(const EnumDescriptor* enum_descriptor); 51 52 // Returns the fully qualified C++ name. 53 // 54 // For example, if you had: 55 // package foo.bar; 56 // message Baz { message Moo {} } 57 // Then the qualified ClassName for Moo would be: 58 // ::foo::bar::Baz_Moo 59 PROTOC_EXPORT std::string QualifiedClassName(const Descriptor* d); 60 PROTOC_EXPORT std::string QualifiedClassName(const EnumDescriptor* d); 61 PROTOC_EXPORT std::string QualifiedExtensionName(const FieldDescriptor* d); 62 63 // Get the (unqualified) name that should be used for this field in C++ code. 64 // The name is coerced to lower-case to emulate proto1 behavior. People 65 // should be using lowercase-with-underscores style for proto field names 66 // anyway, so normally this just returns field->name(). 67 PROTOC_EXPORT std::string FieldName(const FieldDescriptor* field); 68 69 // Requires that this field is in a oneof. Returns the (unqualified) case 70 // constant for this field. 71 PROTOC_EXPORT std::string OneofCaseConstantName(const FieldDescriptor* field); 72 // Returns the quafilied case constant for this field. 73 PROTOC_EXPORT std::string QualifiedOneofCaseConstantName( 74 const FieldDescriptor* field); 75 76 // Get the (unqualified) name that should be used for this enum value in C++ 77 // code. 78 PROTOC_EXPORT std::string EnumValueName(const EnumValueDescriptor* enum_value); 79 80 // Strips ".proto" or ".protodevel" from the end of a filename. 81 PROTOC_EXPORT std::string StripProto(absl::string_view filename); 82 83 } // namespace cpp 84 } // namespace compiler 85 } // namespace protobuf 86 } // namespace google 87 88 #include "google/protobuf/port_undef.inc" 89 90 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ 91