/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 159 lines · 55 code · 29 blank · 75 comment · 6 complexity · 79b930db95861d7dee6d334435c6a33f MD5 · raw file

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  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. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
  34. #define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
  35. #include <string>
  36. #include <google/protobuf/descriptor.h>
  37. #include <google/protobuf/descriptor.pb.h>
  38. namespace google {
  39. namespace protobuf {
  40. namespace compiler {
  41. namespace cpp {
  42. // Commonly-used separator comments. Thick is a line of '=', thin is a line
  43. // of '-'.
  44. extern const char kThickSeparator[];
  45. extern const char kThinSeparator[];
  46. // Returns the non-nested type name for the given type. If "qualified" is
  47. // true, prefix the type with the full namespace. For example, if you had:
  48. // package foo.bar;
  49. // message Baz { message Qux {} }
  50. // Then the qualified ClassName for Qux would be:
  51. // ::foo::bar::Baz_Qux
  52. // While the non-qualified version would be:
  53. // Baz_Qux
  54. string ClassName(const Descriptor* descriptor, bool qualified);
  55. string ClassName(const EnumDescriptor* enum_descriptor, bool qualified);
  56. string SuperClassName(const Descriptor* descriptor);
  57. // Get the (unqualified) name that should be used for this field in C++ code.
  58. // The name is coerced to lower-case to emulate proto1 behavior. People
  59. // should be using lowercase-with-underscores style for proto field names
  60. // anyway, so normally this just returns field->name().
  61. string FieldName(const FieldDescriptor* field);
  62. // Get the unqualified name that should be used for a field's field
  63. // number constant.
  64. string FieldConstantName(const FieldDescriptor *field);
  65. // Returns the scope where the field was defined (for extensions, this is
  66. // different from the message type to which the field applies).
  67. inline const Descriptor* FieldScope(const FieldDescriptor* field) {
  68. return field->is_extension() ?
  69. field->extension_scope() : field->containing_type();
  70. }
  71. // Returns the fully-qualified type name field->message_type(). Usually this
  72. // is just ClassName(field->message_type(), true);
  73. string FieldMessageTypeName(const FieldDescriptor* field);
  74. // Strips ".proto" or ".protodevel" from the end of a filename.
  75. string StripProto(const string& filename);
  76. // Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.).
  77. // Note: non-built-in type names will be qualified, meaning they will start
  78. // with a ::. If you are using the type as a template parameter, you will
  79. // need to insure there is a space between the < and the ::, because the
  80. // ridiculous C++ standard defines "<:" to be a synonym for "[".
  81. const char* PrimitiveTypeName(FieldDescriptor::CppType type);
  82. // Get the declared type name in CamelCase format, as is used e.g. for the
  83. // methods of WireFormat. For example, TYPE_INT32 becomes "Int32".
  84. const char* DeclaredTypeMethodName(FieldDescriptor::Type type);
  85. // Get code that evaluates to the field's default value.
  86. string DefaultValue(const FieldDescriptor* field);
  87. // Convert a file name into a valid identifier.
  88. string FilenameIdentifier(const string& filename);
  89. // Return the name of the AddDescriptors() function for a given file.
  90. string GlobalAddDescriptorsName(const string& filename);
  91. // Return the name of the AssignDescriptors() function for a given file.
  92. string GlobalAssignDescriptorsName(const string& filename);
  93. // Return the name of the ShutdownFile() function for a given file.
  94. string GlobalShutdownFileName(const string& filename);
  95. // Escape C++ trigraphs by escaping question marks to \?
  96. string EscapeTrigraphs(const string& to_escape);
  97. // Do message classes in this file keep track of unknown fields?
  98. inline bool HasUnknownFields(const FileDescriptor *file) {
  99. return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
  100. }
  101. // Does this file have generated parsing, serialization, and other
  102. // standard methods for which reflection-based fallback implementations exist?
  103. inline bool HasGeneratedMethods(const FileDescriptor *file) {
  104. return file->options().optimize_for() != FileOptions::CODE_SIZE;
  105. }
  106. // Do message classes in this file have descriptor and refelction methods?
  107. inline bool HasDescriptorMethods(const FileDescriptor *file) {
  108. return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
  109. }
  110. // Should we generate generic services for this file?
  111. inline bool HasGenericServices(const FileDescriptor *file) {
  112. return file->service_count() > 0 &&
  113. file->options().optimize_for() != FileOptions::LITE_RUNTIME &&
  114. file->options().cc_generic_services();
  115. }
  116. // Should string fields in this file verify that their contents are UTF-8?
  117. inline bool HasUtf8Verification(const FileDescriptor* file) {
  118. return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
  119. }
  120. // Should we generate a separate, super-optimized code path for serializing to
  121. // flat arrays? We don't do this in Lite mode because we'd rather reduce code
  122. // size.
  123. inline bool HasFastArraySerialization(const FileDescriptor* file) {
  124. return file->options().optimize_for() == FileOptions::SPEED;
  125. }
  126. } // namespace cpp
  127. } // namespace compiler
  128. } // namespace protobuf
  129. } // namespace google
  130. #endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__