1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // https://developers.google.com/protocol-buffers/ 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions are 7 // met: 8 // 9 // * Redistributions of source code must retain the above copyright 10 // notice, this list of conditions and the following disclaimer. 11 // * Redistributions in binary form must reproduce the above 12 // copyright notice, this list of conditions and the following disclaimer 13 // in the documentation and/or other materials provided with the 14 // distribution. 15 // * Neither the name of Google Inc. nor the names of its 16 // contributors may be used to endorse or promote products derived from 17 // this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ 32 #define GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ 33 34 #include <string> 35 36 // Must be included last. 37 #include <google/protobuf/port_def.inc> 38 39 namespace google { 40 namespace protobuf { 41 42 class Descriptor; 43 class EnumDescriptor; 44 class EnumValueDescriptor; 45 class FieldDescriptor; 46 47 namespace compiler { 48 namespace cpp { 49 50 // Returns the unqualified C++ name. 51 // 52 // For example, if you had: 53 // package foo.bar; 54 // message Baz { message Moo {} } 55 // Then the non-qualified version would be: 56 // Baz_Moo 57 std::string ClassName(const Descriptor* descriptor); 58 std::string ClassName(const EnumDescriptor* enum_descriptor); 59 60 // Returns the fully qualified C++ name. 61 // 62 // For example, if you had: 63 // package foo.bar; 64 // message Baz { message Moo {} } 65 // Then the qualified ClassName for Moo would be: 66 // ::foo::bar::Baz_Moo 67 std::string QualifiedClassName(const Descriptor* d); 68 std::string QualifiedClassName(const EnumDescriptor* d); 69 std::string QualifiedExtensionName(const FieldDescriptor* d); 70 71 // Get the (unqualified) name that should be used for this field in C++ code. 72 // The name is coerced to lower-case to emulate proto1 behavior. People 73 // should be using lowercase-with-underscores style for proto field names 74 // anyway, so normally this just returns field->name(). 75 std::string FieldName(const FieldDescriptor* field); 76 77 // Requires that this field is in a oneof. Returns the (unqualified) case 78 // constant for this field. 79 std::string OneofCaseConstantName(const FieldDescriptor* field); 80 // Returns the quafilied case constant for this field. 81 std::string QualifiedOneofCaseConstantName(const FieldDescriptor* field); 82 83 // Get the (unqualified) name that should be used for this enum value in C++ 84 // code. 85 std::string EnumValueName(const EnumValueDescriptor* enum_value); 86 87 // Strips ".proto" or ".protodevel" from the end of a filename. 88 PROTOC_EXPORT std::string StripProto(const std::string& filename); 89 90 } // namespace cpp 91 } // namespace compiler 92 } // namespace protobuf 93 } // namespace google 94 95 #include <google/protobuf/port_undef.inc> 96 97 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ 98