cpp_generator.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
  19. #define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
  20. // cpp_generator.h/.cc do not directly depend on GRPC/ProtoBuf, such that they
  21. // can be used to generate code for other serialization systems, such as
  22. // FlatBuffers.
  23. #include <memory>
  24. #include <string>
  25. #include <vector>
  26. #include "src/compiler/config.h"
  27. #include "src/compiler/schema_interface.h"
  28. #ifdef GRPC_CUSTOM_STRING
  29. #warning GRPC_CUSTOM_STRING is no longer supported. Please use std::string.
  30. #endif
  31. namespace grpc {
  32. // Using grpc::string and grpc::to_string is discouraged in favor of
  33. // std::string and std::to_string. This is only for legacy code using
  34. // them explictly.
  35. using std::string; // deprecated
  36. using std::to_string; // deprecated
  37. } // namespace grpc
  38. namespace grpc_cpp_generator {
  39. // Contains all the parameters that are parsed from the command line.
  40. struct Parameters {
  41. // Puts the service into a namespace
  42. std::string services_namespace;
  43. // Use system includes (<>) or local includes ("")
  44. bool use_system_headers;
  45. // Prefix to any grpc include
  46. std::string grpc_search_path;
  47. // Generate Google Mock code to facilitate unit testing.
  48. bool generate_mock_code;
  49. // Google Mock search path, when non-empty, local includes will be used.
  50. std::string gmock_search_path;
  51. // *EXPERIMENTAL* Additional include files in grpc.pb.h
  52. std::vector<std::string> additional_header_includes;
  53. // By default, use "pb.h"
  54. std::string message_header_extension;
  55. // Whether to include headers corresponding to imports in source file.
  56. bool include_import_headers;
  57. };
  58. // Return the prologue of the generated header file.
  59. std::string GetHeaderPrologue(grpc_generator::File* file,
  60. const Parameters& params);
  61. // Return the includes needed for generated header file.
  62. std::string GetHeaderIncludes(grpc_generator::File* file,
  63. const Parameters& params);
  64. // Return the includes needed for generated source file.
  65. std::string GetSourceIncludes(grpc_generator::File* file,
  66. const Parameters& params);
  67. // Return the epilogue of the generated header file.
  68. std::string GetHeaderEpilogue(grpc_generator::File* file,
  69. const Parameters& params);
  70. // Return the prologue of the generated source file.
  71. std::string GetSourcePrologue(grpc_generator::File* file,
  72. const Parameters& params);
  73. // Return the services for generated header file.
  74. std::string GetHeaderServices(grpc_generator::File* file,
  75. const Parameters& params);
  76. // Return the services for generated source file.
  77. std::string GetSourceServices(grpc_generator::File* file,
  78. const Parameters& params);
  79. // Return the epilogue of the generated source file.
  80. std::string GetSourceEpilogue(grpc_generator::File* file,
  81. const Parameters& params);
  82. // Return the prologue of the generated mock file.
  83. std::string GetMockPrologue(grpc_generator::File* file,
  84. const Parameters& params);
  85. // Return the includes needed for generated mock file.
  86. std::string GetMockIncludes(grpc_generator::File* file,
  87. const Parameters& params);
  88. // Return the services for generated mock file.
  89. std::string GetMockServices(grpc_generator::File* file,
  90. const Parameters& params);
  91. // Return the epilogue of generated mock file.
  92. std::string GetMockEpilogue(grpc_generator::File* file,
  93. const Parameters& params);
  94. // Return the prologue of the generated mock file.
  95. std::string GetMockPrologue(grpc_generator::File* file,
  96. const Parameters& params);
  97. // Return the includes needed for generated mock file.
  98. std::string GetMockIncludes(grpc_generator::File* file,
  99. const Parameters& params);
  100. // Return the services for generated mock file.
  101. std::string GetMockServices(grpc_generator::File* file,
  102. const Parameters& params);
  103. // Return the epilogue of generated mock file.
  104. std::string GetMockEpilogue(grpc_generator::File* file,
  105. const Parameters& params);
  106. } // namespace grpc_cpp_generator
  107. #endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H