cpp_names.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__
  31. #define GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__
  32. #include <string>
  33. #include <google/protobuf/port_def.inc>
  34. namespace google {
  35. namespace protobuf {
  36. class Descriptor;
  37. class EnumDescriptor;
  38. class EnumValueDescriptor;
  39. class FieldDescriptor;
  40. namespace compiler {
  41. namespace cpp {
  42. // Returns the unqualified C++ name.
  43. //
  44. // For example, if you had:
  45. // package foo.bar;
  46. // message Baz { message Qux {} }
  47. // Then the non-qualified version would be:
  48. // Baz_Qux
  49. std::string ClassName(const Descriptor* descriptor);
  50. std::string ClassName(const EnumDescriptor* enum_descriptor);
  51. // Returns the fully qualified C++ name.
  52. //
  53. // For example, if you had:
  54. // package foo.bar;
  55. // message Baz { message Qux {} }
  56. // Then the qualified ClassName for Qux would be:
  57. // ::foo::bar::Baz_Qux
  58. std::string QualifiedClassName(const Descriptor* d);
  59. std::string QualifiedClassName(const EnumDescriptor* d);
  60. std::string QualifiedExtensionName(const FieldDescriptor* d);
  61. // Get the (unqualified) name that should be used for this field in C++ code.
  62. // The name is coerced to lower-case to emulate proto1 behavior. People
  63. // should be using lowercase-with-underscores style for proto field names
  64. // anyway, so normally this just returns field->name().
  65. std::string FieldName(const FieldDescriptor* field);
  66. // Requires that this field is in a oneof. Returns the (unqualified) case
  67. // constant for this field.
  68. std::string OneofCaseConstantName(const FieldDescriptor* field);
  69. // Returns the quafilied case constant for this field.
  70. std::string QualifiedOneofCaseConstantName(const FieldDescriptor* field);
  71. // Get the (unqualified) name that should be used for this enum value in C++
  72. // code.
  73. std::string EnumValueName(const EnumValueDescriptor* enum_value);
  74. // Strips ".proto" or ".protodevel" from the end of a filename.
  75. PROTOC_EXPORT std::string StripProto(const std::string& filename);
  76. } // namespace cpp
  77. } // namespace compiler
  78. } // namespace protobuf
  79. } // namespace google
  80. #include <google/protobuf/port_undef.inc>
  81. #endif // GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__